fix(tree): keep file reads inside the repository - #11
Merged
Conversation
/api/tree/file/ and /api/tree/raw/ decodeURIComponent the path and joined it onto the repository root with no containment check. WHATWG URL parsing collapses a literal ../ before the handler sees it, but percent-encoded separators survive - and the UI itself sends encodeURIComponent(filePath), so %2F-encoded paths are the normal code path. Any file the user could read was readable. resolveInRepo resolves and then asserts containment, and both readers plus /api/open-in-editor go through it. Raw responses are also served inertly: only image types keep their content type, anything else is application/octet-stream with Content-Disposition: attachment, and every raw response carries nosniff and default-src 'none'; sandbox - a repository's own .html or .svg can no longer execute in this origin. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018PkYQzbsnMihHesafWvXKs
This was referenced Aug 21, 2026
fiddur
marked this pull request as ready for review
August 21, 2026 13:34
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.
Audit finding P1-4.
/api/tree/file/and/api/tree/raw/decodeURIComponentthe path and joinedit onto the repository root with no containment check:
WHATWG URL parsing collapses a literal
../before the handler sees it, but percent-encodedseparators survive —
/api/tree/raw/..%2f..%2f..%2fetc%2fpasswddecodes to../../../etc/passwd.This is not an exotic encoding: the UI sends
encodeURIComponent(filePath), so%2F-encoded pathsare the normal code path. Any file the user could read was readable —
~/.ssh/id_rsa,~/.config/gh/hosts.yml, other repositories' source.resolveInReporesolves the path and then asserts containment, rejecting.., absolute paths, and the sibling-directory-sharing-a-prefix case/api/open-in-editor(audit P2-3) go through itapplication/octet-streamwithContent-Disposition: attachment, and every raw response carriesnosniffplusdefault-src 'none'; sandbox, so a repository's own.htmlor.svgcan no longer execute in this origin and hand an attacker same-origin access to the APIStacked on #10.
🤖 Generated with Claude Code
https://claude.ai/code/session_018PkYQzbsnMihHesafWvXKs