fix: add rate limiting to webhooks and auth endpoints, and add caching to user session#2591
Merged
Conversation
Member
Author
This stack of pull requests is managed by Graphite. Learn more about stacking. |
Contributor
|
Container images for this PR have been built successfully!
Built from commit c199f8a |
bb1bd66 to
88f5b3a
Compare
…g to user session
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.

Checklist
mainbranchWhat This PR Implements
Fixes:
Changes Made
Testing Done
./scripts/development/dev.sh startjust lint all)just test backendAI Tool Used (if applicable)
AI Tool:
Assistance Level:
What AI helped with:
I reviewed and edited all AI-generated output:
I ran all required tests and manually verified changes:
Additional Context
Disclaimer Greptiles Reviews use AI, make sure to check over its work.
To better help train Greptile on our codebase, if the comment is useful and valid Like the comment, if its not helpful or invalid Dislike
To have Greptile Re-Review the changes, mention
greptileai.Greptile Summary
This PR adds per-IP rate limiting to auth and webhook endpoints, introduces a 15-second in-process token-verification cache to reduce DB load, and adds
TRUSTED_PROXIESconfiguration to correctly identify client IPs behind reverse proxies.PerIPRateLimitForPathscreates one independent token bucket per path, so a login burst does not consume the token-refresh or webhook budget. Auth endpoints are capped at 5 req/min (burst 5); the webhook trigger at 60 req/min (burst 10).VerifyTokennow caches validated(User, SessionID)tuples for 15 s, keyed by SHA-256 of the raw JWT. Cache entries are eagerly purged inRevokeSession,ChangePassword, and the newInvalidateUserTokenCache, which is also called fromUpdateUserandDeleteUserto address stale roles/deletion.opportunisticBearerAuthInternal, which populates user/session context without rejecting the request, enabling logout to revoke the correct session even though the route has no security requirement.Confidence Score: 5/5
Safe to merge; all new code is well-tested and the only concern is a minor configuration edge-case that does not affect deployments using the default settings.
All three major features (rate limiting, token cache, auth bridge refactor) are covered by new tests and the logic is sound. The one rough edge — TRUSTED_PROXIES falling back to ExtractIPFromXFFHeader() with an empty option set when every CIDR is invalid — only affects operators who set the env var to a malformed value and does not cause a security hole, just potentially less-effective rate limiting.
backend/internal/bootstrap/router_bootstrap.go — the TRUSTED_PROXIES fallback when all CIDRs are invalid.
Prompt To Fix All With AI
Reviews (2): Last reviewed commit: "fix: add rate limiting to webhooks and a..." | Re-trigger Greptile