Uh oh!
There was an error while loading. Please reload this page.
feat: Add Sb-Forwarded-For header and IP-based rate limiting - #2295
Conversation
Uh oh!
There was an error while loading. Please reload this page.
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 |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
As described.
143af17 to
e107e91CompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
As described.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
As described.
As described.
As described.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
cstockton
left a comment
There was a problem hiding this comment.
Looks good to me aside from a small nit on TODO code
Uh oh!
There was an error while loading. Please reload this page.
As described.
As described.
Uh oh!
There was an error while loading. Please reload this page.
Resets the main branch (`master`) to have the same changeset as 2.184.0 but under 2.185.0. Original release please notes: ### Features * Add Sb-Forwarded-For header and IP-based rate limiting ([#2295](#2295)) ([e8f679b](e8f679b)) * allow amr claim to be array of strings or objects ([#2274](#2274)) ([607da43](607da43)) * Treat rate limit header value as comma-separated list ([#2282](#2282)) ([5f2e279](5f2e279)) ### Bug Fixes * check each type independently ([#2290](#2290)) ([d9de0af](d9de0af)) * fix the wrong error return value ([#1950](#1950)) ([e2dfb5d](e2dfb5d)) * **indexworker:** remove pg_trgm extension ([#2301](#2301)) ([c553b10](c553b10)) * **oauth-server:** allow custom URI schemes in client redirect URIs ([#2298](#2298)) ([ea72f57](ea72f57)) * tighten email validation rules ([#2304](#2304)) ([33bb372](33bb372)) --------- Co-authored-by: depthfirst-app[bot] <184448029+depthfirst-app[bot]@users.noreply.github.com>
🤖 I have created a release *beep* *boop* --- ## [2.185.0](v2.184.0...v2.185.0) (2026-01-12) ### Features * Add Sb-Forwarded-For header and IP-based rate limiting ([#2295](#2295)) ([e8f679b](e8f679b)) * allow amr claim to be array of strings or objects ([#2274](#2274)) ([607da43](607da43)) * reset main branch to 2.185.0 ([#2325](#2325)) ([b9d0500](b9d0500)) * Treat rate limit header value as comma-separated list ([#2282](#2282)) ([5f2e279](5f2e279)) ### Bug Fixes * additional provider and issuer checks ([#2326](#2326)) ([cb79a74](cb79a74)) * check each type independently ([#2290](#2290)) ([d9de0af](d9de0af)) * fix the wrong error return value ([#1950](#1950)) ([e2dfb5d](e2dfb5d)) * **indexworker:** remove pg_trgm extension ([#2301](#2301)) ([c553b10](c553b10)) * **oauth-server:** allow custom URI schemes in client redirect URIs ([#2298](#2298)) ([ea72f57](ea72f57)) * tighten email validation rules ([#2304](#2304)) ([33bb372](33bb372)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
## 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 by `GOTRUE_SECURITY_SB_FORWARDED_FOR_ENABLED`. When this feature is enabled, both `utilities.GetIPAddress` and rate limiting will use the first value of the `Sb-Forwarded-For` header as the IP address/rate limiting key. If the feature is disabled or the `Sb-Forwarded-For` header 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-For` header 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-For` can 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 the `Sb-Forwarded-For` header and inserts it into the request context if `GOTRUE_SECURITY_SB_FORWARDED_FOR_ENABLED` is true. Consumers of the `Sb-Forwarded-For` header can use `sbff.GetIPAddress` to retrieve the parsed IP address. `utilities.GetIPAddress` will prefer the result of `sbff.GetIPAddress` as the end-user IP address if the feature is enabled and the `Sb-Forwarded-For` header contains a value value. Similarly, Auth will use the end user IP address as determined by `sbff.GetIPAddress` as the rate limiting key under the same circumstances. If the feature is not enabled or the `Sb-Forwarded-For` header is absent or otherwise invalid, Auth will default to existing/legacy behavior.
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.