fix: restrict the local API to the diff under review and same-origin callers - #40
Open
jessebond2 wants to merge 2 commits into
Open
fix: restrict the local API to the diff under review and same-origin callers#40jessebond2 wants to merge 2 commits into
jessebond2 wants to merge 2 commits into
Conversation
Containment was checked lexically, so a symlink stored inside the repository served the contents of whatever it pointed at outside the repository.
…lers /api/file-content served any file inside the repository, so a gitignored .env was readable by anything that could reach the port. It now serves only paths in the diff being reviewed, asked of git by name rather than parsed back out of the patch: the `diff --git` header is ambiguous for paths containing ` b/`, and binary files carry no `+++` header to read instead. The API also answered any caller: a page the user has open could post comments (which the agent skills then apply as code changes) or write settings, and a rebound DNS name could read the diff. Requests are now checked for a loopback Host and a same-origin Origin. A missing Origin still passes so the CLI and agent skills keep working, and binding to a non-loopback host stays an explicit opt-in to LAN access. Settings writes are validated against known keys and values, since `browser` names the application launched on the next run.
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 freeto 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.
The local server answers any caller that can reach the port, and
/api/file-contentserves any file inside the repository. Two commits, one concern each.Symlink containment
isSafePathcompares lexically, so a symlink stored inside the repo served the contents of whatever it pointed at outside the repo.resolveWithinDir(realpath-based) for the worktree read. Thegit showpath is untouched — it returns a link's target text rather than following it.API scope
/api/file-contentnow serves only paths in the diff under review. Previously any repository file was readable, including gitignored ones such as.env.git diff --name-only -zrather than parsing the patch: thediff --githeader is ambiguous for paths containingb/(as the/api/file-versionscomment already notes), and binary files carry no+++header to read instead. Side effect: images whose path contains a space now display, where they previously 404'd./api/*requires a loopbackHost, and a same-originOriginwhen one is present. This stops a page the user happens to have open from posting comments (which the agent skills then apply as code changes) or writing settings, and stops a rebound DNS name from reading the diff.PUT /api/settingsvalidates keys and values instead of spreading the request body, sincebrowsernames the application launched on the next run. It is limited to the values the Toolbar offers.Kept working on purpose
Originstill pass, so the CLI and thediffx-*skills are unaffected — only browsers attach that header.--host 0.0.0.0still serves LAN reviewers. TheHostcheck is skipped there, since a non-loopback bind is an explicit opt-in and LAN addresses can't be allowlisted ahead of time; theOrigincheck still applies.getUntrackedFilePathsgained-z. Without it, git quotes paths containing non-ASCII or newline characters, and the new membership check would have regressed those files.softWrapis now declared in the server'sSettings. The client already sends it and it was persisting only via the unvalidated spread, so validation would otherwise have dropped it.