Fix stored XSS via uploaded filename#10
Open
thistehneisen wants to merge 1 commit into
Open
Conversation
`header.Filename` from /upload flows into the front-end via WebSocket
("uploaded" / "upload-processed" / "upload-lists" messages) and is
rendered with `innerHTML` in `assets/js/notifications.js` and
`assets/js/user-actions.js`. A filename like
<img src=x onerror=alert(1)>.txt
is persisted to MongoDB and executes JavaScript in every user that
receives it (including admins, since the broadcast / notifications
path includes them).
This patch applies `filepath.Base()` and validates the basename
against `^[A-Za-z0-9 ._-]{1,200}$`. Uploads with unsafe characters are
rejected with HTTP 200 + an explanatory message at the same response
surface as the existing error paths.
This also incidentally hardens against path-traversal (defence in
depth — Go ≥1.17 `mime/multipart` already applies filepath.Base, but
relying on stdlib for security-critical input is fragile) and
NUL-byte / control-character injection.
Verified:
* unsafe name (<img ...>) → rejected with the new message; nothing
written to upload/queue/ or persisted in MongoDB users.uploads.in
* safe name (normal-name.txt) → "ok", processed end-to-end, downloads
link appears in the profile UI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix stored XSS via uploaded filename
Reported by: OffSeq — Nils Putniņš
<npu@offseq.com>Affected version: v2.6.1 (
a2a794ef6916d16da3fcc2f9f8d86225482e7263)What this PR fixes
The original filename submitted to
/upload(multipartContent-Dispositionfilename=) flows verbatim through MongoDB and back to every viewer overWebSocket (
"uploaded","upload-processed","upload-lists"messages,plus the notification text built server-side at
upload.go:527).The Web GUI renders these via
innerHTMLinassets/js/notifications.js:73,159andassets/js/user-actions.js:175,211,which executes any HTML/JS embedded in the filename.
A filename like
is persisted to MongoDB (
users.uploads.in) and executes in every userthat opens their profile / receives the notification (including admins).
The fix
path/filepath.Base(header.Filename)strips any path components fromthe user-supplied basename.
(
^[A-Za-z0-9 ._-]{1,200}$). Anything else is rejected up front withHTTP 200 + a descriptive error body, exactly like the other failure
paths in
uploadHandler.This kills the XSS vector at the source — no front-end change is
needed because nothing dangerous reaches the rendered string anymore.
It also incidentally hardens against path traversal (defence-in-depth
on top of
mime/multipartsince Go 1.17) and NUL / control-characterinjection.
Single file changed, +29 lines.
Repro (pre-patch behaviour)
On the Web GUI, opening the profile page renders the payload in the
download list via
innerHTML→alert(1)fires.Post-patch behaviour
Same request returns HTTP 200 with body:
…and nothing is written to
upload/queue/, MongoDB, or any other state.Verified locally; standard filenames (
indicators.txt,IOCs - 2026-05.csv)still upload normally end-to-end.
Trade-off note
The 200-char /
[A-Za-z0-9 ._-]allow-list is intentionally strict. Ifoperators need to permit additional characters (parentheses, commas,
unicode), the regex is a single line to relax. We chose the conservative
default because the audit found multiple
.innerHTML/.html()sinksacross the front-end; a strict source-side filter is the most defensible
position until those sinks are individually audited.
Out of scope (separate work)
innerHTML/.html()withtextContent/.text()(orDOM construction) everywhere user-controllable strings are rendered
— defence-in-depth on top of this PR.
messages that mix HTML + user data (
upload.go:527, etc.).Nils Putniņš / npu[at]offseq[dot]com / OffSeq
https://offseq.com / https://radar.offseq.com