Repository navigation
fix(supabase): drop trace headers when a redirect leaves the Supabase hosts - #1895
Conversation
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: supabase/supabase-flutter/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (3)
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review. 📝 WalkthroughWalkthrough
ChangesTrace propagation across redirects
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~25 minutes Change: Bug fix Sequence Diagram(s)sequenceDiagram
participant Caller
participant TracePropagationClient
participant InnerClient
participant RedirectHost
Caller->>TracePropagationClient: Send request with trace context
TracePropagationClient->>InnerClient: Send request with eligible trace headers
InnerClient->>TracePropagationClient: Return redirect response
TracePropagationClient->>InnerClient: Send eligible redirected request
InnerClient->>RedirectHost: Forward redirected request
Suggested reviewers: Merge Risk: ⚪ Minimal · up to Traced requests that are redirected to third-party hosts now drop the added trace headers, and redirect handling otherwise matches the previous behavior. No merge-blocking risk introduced by this change remains. Security Architecture ReviewSecurity architecture risk: 🟠 High · up to Redirects can now resend some traced write requests to a new destination. That can expose the request body and API key, including when a redirect switches from HTTPS to HTTP. The risk depends on whether a server returns such a redirect; ordinary third-party redirects do receive stronger trace-header protection. Retained concerns
Security review detailsSecurity Blast Radius
Security Findings and Attack Paths
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
|
The following capabilities are marked
These may have been renamed, removed, or never registered. Please update the capability matrix. |
**What this changes** The functions client stops forwarding the Supabase `apiKey` header when a response redirects to a different host. A redirect that stays on the Supabase host is unaffected, and `follow_redirects` stays on, so normal behavior does not change. **The problem** `AsyncFunctionsClient` and `SyncFunctionsClient` create their default `httpx` client with `follow_redirects=True`, and every request carries the project `apiKey` header. `httpx` removes the `Authorization` header when a response redirects away from the origin, but it forwards custom headers unchanged. So if an invoked edge function responds with a redirect to another host, `httpx` follows it and sends the `apiKey` header to that host. When the SDK is created with the `service_role` key, which is the normal server side configuration, that key is secret and bypasses Row Level Security. Forwarding it to a host the project does not control is a credential disclosure. The trigger is a cross host redirect from an invoked function, for example an open redirect driven by user input, or a function authored by a lower trust teammate. **The fix** Wrap the default client in a small `httpx` subclass that overrides `_redirect_headers` to drop the `apiKey` header when the redirect target host differs from the current host. This mirrors how `httpx` already treats `Authorization`, and how the other Supabase client libraries handle redirect headers (see supabase/supabase-flutter#1895, which strips credential headers when a redirect leaves the Supabase hosts). A user supplied `http_client` is left untouched, since its redirect policy is the caller's to set. **Tests** Two tests on the functions client, async and sync: - a cross host redirect drops both `apiKey` and `Authorization` at the next hop - a same host redirect keeps the `apiKey` **Related** This is the same class of issue as GHSA-r4q5-vmmm-2653 (custom authentication headers leaked to cross domain redirect targets), in the Python SDK. **Scope** This PR covers the functions client, where the redirect is driven by user deployed function code and is the realistic exploit path. The same `follow_redirects=True` plus `apiKey` pattern exists in the auth, storage, and postgrest clients, which talk to Supabase controlled hosts. Happy to extend the same guard to those in a follow up if you prefer it in one place. --------- Co-authored-by: Lukas Klingsbo <[email protected]>
Summary
TracePropagationClientdecided whether to addtraceparent,tracestateandbaggagefrom the URL a request is sent to, then left redirects to the inner client. That client copies every header onto the redirected request:dart:iofor GET and HEAD redirects and a 303 on a POST, and clients likecupertino_httporcronet_httpfor writes too. A Supabase host redirecting a traced request to another host therefore handed that host the trace headers, includingbaggage, which carries whatever the application puts in it.When the client has added trace headers to a request, it now turns off
followRedirectson it and follows the redirects itself:dart:iodoes.Request. A streamed or multipart request answered with a 307 or 308 is returned unfollowed, since its body cannot be read twice.Locationis resolved against the current URL, andmaxRedirectsand loop detection surface as aClientException, asIOClientreports them.dart:iodrops are removed:authorization,www-authenticate,proxy-authorization,proxy-authenticate,cookieandcookie2. Following redirects here is never less safe than leaving them todart:io.IOClientdoes.Requests without added trace headers and requests that already set
followRedirectstofalseare sent unchanged.Two behavior changes for requests carrying trace headers: with the default client, a 307 or 308 on a POST, PUT, PATCH or DELETE is now followed, where
dart:ioreturned it. With a custom client that follows those itself, a streamed upload answered with a 307 or 308 now comes back unfollowed.On the web nothing changes:
BrowserClientturnsfollowRedirects: falseinto aClientExceptionon any redirect, and the browser gives no access to the hops. The README and theTracePropagationOptionsdartdoc go back to the unqualified "third-party hosts never receive them" from before #1887, with the web called out as the exception.apikeyis still copied to every hop, asdart:iodoes. Dropping it on a redirect to another host is a separate change.Testing
redirectsgroup intrace_propagation_test.dart, VM only. It covers:Location;followRedirects: false, left to the inner client.dart:ioservers, with a tracedselect()answered with a 302 and anrpc()answered with a 307, both redirected to a third-party host:traceparentandbaggage;melos formatandmelos analyzeare clean, and thesupabase(220) andsupabase_flutter(102) suites pass.Closes SDK-1975.
Summary by CodeRabbit