Repository navigation
fix(auth): protect GET /api/stats with read-only API key router - #8
Merged
Merged
Conversation
Register /api/stats on protected_api so project metadata is not enumerable when CODE_SEARCH_API_KEY is configured. Add regression tests for open-when-unset and 401/200 auth behavior. Fixes #7 Co-authored-by: Solomon Neas <solomonneas@users.noreply.github.com>
|
Important Review skippedAuto reviews are limited based on label configuration. 🏷️ Required labels (at least one) (1)
Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository: escoffier-labs/coderabbit/.coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Fixes #7
Summary
/api/statswas registered directly on the FastAPI app, bypassingrequire_api_keywhenCODE_SEARCH_API_KEYwas configured. The route now usesprotected_api, matching/api/projectsand/api/summary-stats.Regression coverage checks all three project-metadata endpoints when the key is unset and when requests provide no key, a wrong key, a valid
X-API-Key, or a valid bearer token. The repository verification script now installs pytest in its throwaway environment and runs the full Python suite.Scope
src/code_search_api/server.py: register/api/statson the read-only protected routertests/test_auth.py: cover metadata endpoint authenticationREADME.md: mark/api/statsas authenticatedscripts/verify: run the Python suite in the throwaway environmentAGENTS.md: describe the Python test gateImpact analysis
GraphTrail attributed
tests/test_auth.py, includingtest_metadata_routes_open_when_key_unsetandtest_metadata_routes_require_valid_key_when_configured. It also found the existingstats -> get_conncall and the MCP client pathCodeSearchClient.stats -> CodeSearchClient.request.Verification
Exact updated head:
ea3247b3b614da4d01d1409ee20d8e851c3ba5f6GitHub Actions run 31432855009:
The smoke tests used OS-assigned loopback ports and throwaway databases.
git diff --check origin/main...HEADandgit status --shortproduced no output.Risk notes
Operators who configure
CODE_SEARCH_API_KEYmust now authenticate/api/stats; behavior remains open when the key is unset. No client code or dependencies changed. The MCP client already uses the shared request helper that attaches the configured API key.