security(backend): guard clone symlinks and require auth on /metrics (#182, #183) - #212
Merged
parthrohit22 merged 1 commit intoJul 27, 2026
Conversation
- github/client.py _directory_size no longer descends into symlinked directories (os.walk followlinks=False + prune symlink dirs), closing the clone-path symlink-escape disclosure/DoS gap (issue Second-Origin#182). - /metrics now requires authentication (Depends(get_current_user)); was world-readable runtime metrics (issue Second-Origin#183). - Updated OpenAPI contract + system tests to reflect /metrics as bearer-protected (401), matching existing contract-authority discipline. Note on Second-Origin#184: its 'arbitrary paths' claim is invalid — RepositoryContextBuilder validates the selected file against the sealed snapshot and only sends snapshot-derived paths. The omitted-review-findings half is a real but feature-sized gap (no review query path exists); tracked separately, not folded into this security PR.
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.
Summary
Two backend security fixes that protect the §28 "Trusted output" / custody posture: (1) the clone path no longer follows symlinks when measuring repository size (closes the symlink-escape disclosure/DoS gap), and (2) the
/metricsendpoint now requires authentication instead of being world-readable.Issue #184 was assessed during this work and is scoped out: its "sends arbitrary paths" claim is invalid (the AI context builder validates the selected file against the sealed snapshot and only ever sends snapshot-derived paths), while the omitted-review-findings half is a real but feature-sized gap with no existing review query path — tracked separately, not folded into this security PR.
Linked issue
Related to #182 (clone symlink escape) and #183 (/metrics unauthenticated). Closes #182 and #183. Note on #184 in the testing/summary above.
Roadmap alignment
GET /metricsreturned 401 after the change (TestClient smoke); full backend suite 701 passed / 4 env-skipped; OpenAPI contract test updated to assert/metricsis bearer-protected.What changed
apps/backend/app/github/client.py:_directory_sizeusesos.walk(..., followlinks=False)and prunes symlinked directories, so a crafted symlink (e.g. to/or a parent) cannot cause disclosure or a measurement loop during clone-size budget enforcement.apps/backend/app/main.py:/metricsroute gainsdependencies=[Depends(get_current_user)]and documents401in its OpenAPI responses.tests/test_openapi_contract.py:/metricsremoved fromPUBLIC_OPERATIONS, expected statuses now{200, 401, 500}.tests/test_system.py: metrics test usesauth_clientand asserts 200.Acceptance criteria completed
/metricsrequires a bearer token (returns 401 unauthenticated).Testing performed
Plus a TestClient smoke confirming
GET /metrics-> 401 without auth.Screenshots
Not applicable (backend/auth change).
Security and data considerations
/metricsnow requires authentication — closes an information-disclosure surface (runtime request counters were world-readable).Dependencies and blocked work
None.
Scope changes or remaining work
#184 ("AI context sends arbitrary paths") is out of scope here: its security premise was found invalid on inspection (the AI context builder validates against the sealed snapshot). The omitted-review-findings aspect is a separate, larger feature (needs a review query path) and should get its own issue rather than be silently bundled.
Contributor checklist
devupstream/devCloses) is used only because the issue is fully resolved