Validate session and task ids to close a path traversal - #24
Open
dgruhin-hrizn wants to merge 1 commit into
Open
Validate session and task ids to close a path traversal#24dgruhin-hrizn wants to merge 1 commit into
dgruhin-hrizn wants to merge 1 commit into
Conversation
Express URL-decodes route params, so %2f inside :sessionId becomes a real
path separator after decoding and path.join() walks straight out of
TASKS_DIR. No route validated either param.
Demonstrated against a throwaway CLAUDE_DIR, with a canary file placed at
<CLAUDE_DIR>/projects/victim/secret.json:
DELETE /api/tasks/..%2fprojects%2fvictim/secret
-> HTTP 200, canary deleted
The route appends '.json', so the primitive is limited to files with that
extension -- which still covers package.json, tsconfig.json and any
*.json holding credentials.
Two things make this worse than a local-only bug:
- app.listen(port) with no host binds 0.0.0.0, not loopback, so the API
is reachable from anything on the same network. That is a real
configuration in practice -- the viewer is genuinely useful from a
phone on the same wifi.
- There is no auth, no CORS config and no origin check, so a LAN client
needs nothing but curl.
A drive-by from a random web page is mostly blocked, since a cross-origin
DELETE is not a CORS-simple request and Express answers no preflight. The
realistic vectors are direct LAN access and chaining from same-origin
script execution.
Adds SAFE_ID (/^[A-Za-z0-9._-]{1,128}$/, with '.' and '..' rejected
explicitly) and guards the three routes that take these params, returning
400. Also skips task objects whose on-disk id fails the same check, so
malformed files never reach the client.
Purely additive; no existing line moves. Verified the patched server
returns 400 for the payload above with the canary intact, and that
ordinary requests still return 200.
This was referenced Aug 19, 2026
Open
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.
Security: path traversal on an unauthenticated API
Express URL-decodes route params, so
%2finside:sessionIdbecomes a real path separator after decoding andpath.join(TASKS_DIR, sessionId, …)walks straight out of the tasks tree. No route validates either param.Demonstrated against a throwaway
CLAUDE_DIR, with a canary at<CLAUDE_DIR>/projects/victim/secret.json:The route appends
.json, so the primitive is limited to files with that extension — which still coverspackage.json,tsconfig.json, and any*.jsonholding credentials.Why this is more than a local-only bug
app.listen(port)binds0.0.0.0, not loopback, so the API is reachable from anything on the same network. That's a real configuration in practice — the viewer is genuinely useful from a phone on the same wifi.curl.Being precise about the threat model, since it affects how urgent this is: a drive-by from a random web page is mostly blocked, because a cross-origin
DELETEisn't a CORS-simple request and Express answers no preflight. The realistic vectors are direct LAN access, and chaining from same-origin script execution (see #27, and PR #25).The fix
Adds
SAFE_ID(/^[A-Za-z0-9._-]{1,128}$/, with.and..rejected explicitly) and guards the three routes that take these params, returning 400. Also skips task objects whose on-diskidfails the same check, so malformed files never reach the client.Purely additive — no existing line moves. 36 insertions, 0 deletions.
Verification
DELETE ..%2fprojects%2fvictim/secretGET /api/sessions/..%2f..%2fprojectsGET /api/sessions/<real-id>One thing worth considering separately: binding to
127.0.0.1by default with an opt-in--hostflag would defend this in depth. I've deliberately not done that here, because it would break the phone-on-LAN use case that I suspect a number of people rely on — it deserves its own PR and its own discussion rather than being smuggled into a security fix.