Skip to content

Harden local HTTP API: add CSRF token + restrict CORS #5

@lextpf

Description

@lextpf

Problem

mo2-server listens on 127.0.0.1:5000 and exposes endpoints that mutate
the user's machine: archive uploads, batch-script spawns
(deploy.bat, purge.bat), test-runner spawns, config writes, FOMOD JSON
deletes. The HTTP layer currently has no authentication and the CORS rule
is origin("*") (src/main.cpp around the crow::App<crow::CORSHandler>
block).

The loopback bind does not protect against a malicious webpage the user
happens to be browsing in the same session. Any tab can issue
fetch('http://127.0.0.1:5000/api/...'). CORS only governs whether JS can
read the response; the request is already executed by the server, so the
side effect (file write, process spawn, config change) happens regardless.
For "simple" requests like multipart/form-data uploads there is no CORS
preflight at all, so even the read-side block does not fire.

Concretely vulnerable today:

  • POST /api/installation/upload (multipart, no preflight)
  • POST /api/installation/install
  • POST /api/plugin/deploy / purge (spawns batch scripts)
  • POST /api/test/run (spawns Python)
  • POST /api/mo2/fomods/scan
  • POST /api/logs/clear / clear/test
  • PUT /api/config
  • DELETE /api/mo2/fomods/<name>

The MO2 Python plugin does not use HTTP (it loads mo2-salma.dll via
ctypes), so the only legitimate HTTP client is the local dashboard.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions