-
Notifications
You must be signed in to change notification settings - Fork 584
feat: Add Sb-Forwarded-For header and IP-based rate limiting #2295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+613
−7
Conversation
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
Pull Request Test Coverage Report for Build 20444605904Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
jnschaeffer
commented
Dec 17, 2025
cstockton
reviewed
Dec 17, 2025
As described.
143af17 to
e107e91
Compare
As described.
cstockton
reviewed
Dec 19, 2025
cstockton
reviewed
Dec 19, 2025
cstockton
reviewed
Dec 19, 2025
cstockton
requested changes
Dec 19, 2025
cstockton
reviewed
Dec 19, 2025
As described.
As described.
As described.
As described.
cstockton
approved these changes
Dec 22, 2025
Contributor
cstockton
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me aside from a small nit on TODO code
As described.
As described.
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.
What kind of change does this PR introduce?
This PR adds support for IP address forwarding using a new header,
Sb-Forwarded-For, optionally gated byGOTRUE_SECURITY_SB_FORWARDED_FOR_ENABLED. When this feature is enabled, bothutilities.GetIPAddressand rate limiting will use the first value of theSb-Forwarded-Forheader as the IP address/rate limiting key.If the feature is disabled or the
Sb-Forwarded-Forheader contains an invalid value, Auth will fall back to existing behavior.What is the current behavior?
There are currently two paths along which users are likely to use IP address information. The first is IP tracking (e.g., logging, MFA challenge validation, and CAPTCHA challenge validation). The second is rate limiting. Both of these follow slightly different logical paths, relying on the
X-Forwarded-Forheader explicitly in the former case and a separate rate limiting key header in the latter.The presence of these two paths results in some friction for users.
X-Forwarded-Forcan be (and frequently is) rewritten by proxies or otherwise spoofed, and there is no guarantee that a rate limiting key in the rate limit header is an IP address.What is the new behavior?
The API uses a new middleware,
sbff.Middleware, that parses theSb-Forwarded-Forheader and inserts it into the request context ifGOTRUE_SECURITY_SB_FORWARDED_FOR_ENABLEDis true. Consumers of theSb-Forwarded-Forheader can usesbff.GetIPAddressto retrieve the parsed IP address.utilities.GetIPAddresswill prefer the result ofsbff.GetIPAddressas the end-user IP address if the feature is enabled and theSb-Forwarded-Forheader contains a value value. Similarly, Auth will use the end user IP address as determined bysbff.GetIPAddressas the rate limiting key under the same circumstances.If the feature is not enabled or the
Sb-Forwarded-Forheader is absent or otherwise invalid, Auth will default to existing/legacy behavior.