Unauthenticated arbitrary file write via unvalidated destination in scanner.exportReport
Description
The Scanner module's exportReport handler writes a report to an attacker-controlled filesystem path with zero validation. destination flows unauthenticated from two HTTP entry points straight into fs.writeFileSync(), giving arbitrary file write (overwrite any path the process can write). The shipped Dockerfile runs as root, so an attacker can overwrite any file in the container.
Root Cause
ScannerService.exportReport(scanId, options) passes options.destination directly into writeFileSync():
mcp_modules/scanner/src/service.js:458—writeFileSync(destination, report)(HTML)mcp_modules/scanner/src/service.js:460—writeFileSync(destination, JSON.stringify(report, null, 2))(JSON)
destination is fully attacker-controlled from two unauthenticated entry points:
GET /scanner/reports/:id/export?destination=…—controller.js:183readsc.req.query('destination')→:185callsexportReport(id, {format, destination})(route registeredindex.js:42).POST /tools/scanner {"action":"export",...,"destination":…}—index.js:130-138passesparams.destination(route registeredindex.js:85).
There is NO path validation anywhere in the call chain: grep -rn "path.resolve|startsWith|normalize|realpath" mcp_modules/scanner/src/ returns 0 path-validation matches. The join(this.dataDir, ...) at service.js:447 only executes in the if (!destination) branch; when destination is supplied it is used verbatim. Absolute paths and ../ traversal both reach the sink unmodified. No auth middleware is registered on any scanner route (only request-logging, CORS with ACAO: *, and an optional in-memory rate-limiter).
Impact
Unauthenticated arbitrary file write. The target path is fully attacker-controlled; content is partially constrained (fixed HTML string, or a JSON envelope carrying attacker-influenced scan.target/scan.error). An attacker can overwrite any file the Node process can write — configuration, application source, static assets — causing integrity loss and denial of service. The shipped Dockerfile (node:20-alpine, no USER) runs as root.
Proof of Concept
SCAN=$(curl -s -X POST http://TARGET:3000/scanner/scan \
-H 'Content-Type: application/json' -d '{"target":"http://example.com"}' | jq -r '.scanId')
# GET entry point:
curl -s "http://TARGET:3000/scanner/reports/$SCAN/export?format=html&destination=/tmp/pwned.html"
# MCP tool entry point (with traversal):
curl -s -X POST http://TARGET:3000/tools/scanner -H 'Content-Type: application/json' \
-d "{\"action\":\"export\",\"scanId\":\"$SCAN\",\"format\":\"json\",\"destination\":\"../../../../tmp/pwned.json\"}"Attack Chain
- Entry:
POST /scanner/scan {"target":"http://example.com"}. Guard:validateTarget()(scanner/src/utils.js) requires a parseable http/https URL. Bypass proof:http://example.comparses as valid. Even if thenucleibinary is absent,scannerScanTarget's catch returns{id, status:'failed'}(service.js:69-91), stored viastoreScanResult()(service.js:291); the handler echoesscanId(controller.js:129). A valid stored scanId is always produced. - Entry (write):
GET /scanner/reports/<scanId>/export?format=html&destination=/etc/cron.d/x(or the POST tool form). Guard: none (no auth middleware on scanner routes). Bypass proof: the onlyapp.use('*')registrations in the repo are logging/CORS/rate-limit (src/core/middleware.js:16,33,71); grep forauthenticat|bearer|jwt|authoriz|apikeyon scanner routes = 0 hits. - Processing:
exportReportcallsgetScanById(scanId)(service.js:442) which throws only on unknown id (satisfied by step 1), thengenerateReport→scannerGenerateReportwhich never throws. - Sink:
writeFileSync(destination, report)(service.js:458/460) —destinationused verbatim. - Impact: overwrite any writable file at an attacker-chosen path.
Bypass Evidence
- No guard exists:
grep -rn "path.resolve|startsWith|normalize|realpath" mcp_modules/scanner/src/→ 0 matches.destinationis never transformed betweencontroller.js:183andservice.js:458/460. - No auth: only logging/CORS/rate-limit middleware; no auth token/header checked on any
/scanner*or/tools/scannerroute. - scanId always obtainable:
storeScanResultis called on both the failed-scan path (service.js:291) and the no-nuclei path. - State-changing GET: the export route is a
GETthat writes a file, and default CORS isACAO: *, so even a loopback-bound instance is reachable via cross-origin browser requests (CSRF-style; the write is the side effect).
Affected Versions
npm @profullstack/mcp-server <= 1.4.12 (latest published). Code present on HEAD 72aa20d at service.js:458/460, controller.js:183, index.js:130-138; no fix commit.
Suggested Fix
Confine destination to the reports directory: resolve the path, reject absolute paths and .. traversal, and verify the resolved path is a descendant of the intended output directory. Additionally, require authentication on scanner routes that perform side effects.
--- Reported by zx (Jace) — GitHub: @manus-use