Repository navigation
fix(http): wire rate limiter, harden CORS and fix Swagger authorize - #22
Merged
Merged
Conversation
- Register app.state.limiter and the RateLimitExceeded handler so over-limit requests return 429 instead of an unhandled 500 - Remove the invalid "*" origin combined with allow_credentials=True and pin CORS to the demo frontend origin (http://localhost:5173, no trailing slash) - Add tests covering the CORS preflight and the 429 rate-limit response
The OAuth2PasswordBearer tokenUrl was "token", but no /token route exists; Swagger's Authorize button failed with 404. Point it at /login.
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.
Context
B6 of the portfolio fixes — three HTTP integration defects where documented behavior did not match reality: rate limiting was declared but not wired, CORS used an invalid origin/credentials combination, and Swagger's Authorize button pointed at a route that does not exist.
Changes
Rate limiting (over-limit returned 500, documented as 429)
core/limiter.pydefines aLimiter, and 38@limiter.limit(...)decorators are active across 7 routers — butapp.state.limiterand theRateLimitExceededhandler were both commented out inmain.py. Over-limit requests therefore surfaced as unhandled 500s.app.state.limiter = limiterandapp.add_exception_handler(RateLimitExceeded, _rate_limit_exceeded_handler).CORS (invalid
"*"+allow_credentials=True)allow_originsmixed the"*"wildcard withallow_credentials=True, which browsers reject."*"and pinned origins to the demo frontend,http://localhost:5173.http://localhost:5173/), which made the preflight fail with 400 — theOriginheader never carries a trailing slash. The new CORS test caught it before merge.Swagger Authorize (404)
OAuth2PasswordBearer(tokenUrl="token")pointed at a non-existent/tokenroute, so the Authorize button could never authenticate.tokenUrlat the real/loginroute.Tests
test/test_routers/test_cors.py— preflight allowed for the demo origin, rejected for unknown origins, and no wildcard inallow_origins.test/test_routers/test_rate_limit.py— over-limit returns 429 (never 500) and the body reportsRate limit exceeded; limiter state is reset per test to avoid cross-test bleed.Verification
pytest -q-> 177 passed (baseline 155).