Skip to main content
Menu
Advisories

Unauthenticated arbitrary file write via unvalidated destination in scanner.exportReport

GHSA-PPP9-2HC2-HFG5Published Updated GitHub

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:183 reads c.req.query('destination') → :185 calls exportReport(id, {format, destination}) (route registered index.js:42).
  • POST /tools/scanner {"action":"export",...,"destination":…} — index.js:130-138 passes params.destination (route registered index.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

  1. Entry: POST /scanner/scan {"target":"http://example.com"}. Guard: validateTarget() (scanner/src/utils.js) requires a parseable http/https URL. Bypass proof: http://example.com parses as valid. Even if the nuclei binary is absent, scannerScanTarget's catch returns {id, status:'failed'} (service.js:69-91), stored via storeScanResult() (service.js:291); the handler echoes scanId (controller.js:129). A valid stored scanId is always produced.
  2. 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 only app.use('*') registrations in the repo are logging/CORS/rate-limit (src/core/middleware.js:16,33,71); grep for authenticat|bearer|jwt|authoriz|apikey on scanner routes = 0 hits.
  3. Processing: exportReport calls getScanById(scanId) (service.js:442) which throws only on unknown id (satisfied by step 1), then generateReport → scannerGenerateReport which never throws.
  4. Sink: writeFileSync(destination, report) (service.js:458/460) — destination used verbatim.
  5. 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. destination is never transformed between controller.js:183 and service.js:458/460.
  • No auth: only logging/CORS/rate-limit middleware; no auth token/header checked on any /scanner* or /tools/scanner route.
  • scanId always obtainable: storeScanResult is called on both the failed-scan path (service.js:291) and the no-nuclei path.
  • State-changing GET: the export route is a GET that writes a file, and default CORS is ACAO: *, 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

Affected versions

References

GitHub · profullstack/mcp-server