[security] fix(providers): guard credentialed redirects#1237
[security] fix(providers): guard credentialed redirects#1237Hinotoi-agent wants to merge 4 commits into
Conversation
|
Thanks for the context here. I swept through the related work, and this is now duplicate or superseded. Keep open for maintainer review: current main still has the credentialed redirect gap, and the latest PR head covers the previously omitted provider credential headers, but it intentionally changes provider redirect compatibility and needs explicit maintainer acceptance before merge. Canonical path: Close this PR as superseded by #1226. So I’m closing this here and keeping the remaining discussion on #1226. Review detailsBest possible solution: Close this PR as superseded by #1226. Do we have a high-confidence way to reproduce the issue? Yes from source inspection: current main sends credentialed shared-provider and OpenAI dashboard requests through unguarded URLSession redirect handling. I did not run live provider probes because repository policy avoids real cookie/account validation unless explicitly requested. Is this the best way to solve the issue? Mostly yes: a central ProviderHTTPClient redirect guard is the narrow maintainable place to enforce the credential boundary, and the latest head covers the current provider credential headers found in source. The remaining question is not a code defect but whether maintainers accept the stricter compatibility behavior. Security review: Security review cleared: The diff is a credential-boundary hardening and I found no concrete new security or supply-chain concern beyond the explicit compatibility tradeoff. AGENTS.md: found and applied where relevant. What I checked:
Likely related people:
Codex review notes: model gpt-5.5, reasoning high; reviewed against 4756ba06bf42. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9fa979532a
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
Addressed the remaining P1 items in
Validation:
|
|
@clawsweeper re-review Please re-review the latest PR head. |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Addressed the latest rank-up items in
Compatibility decision for maintainers: this PR intentionally keeps the stricter fail-closed redirect behavior. Provider HTTP requests only follow same-origin HTTPS redirects, and credentials are stripped even on allowed redirects. If any provider/custom endpoint requires authenticated redirects, please explicitly accept that compatibility trade-off or tell me which redirect behavior to relax before merge. Local validation:
@clawsweeper re-review please |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
Summary
This PR hardens credentialed provider HTTP requests against redirects that could otherwise carry sensitive request headers to an attacker-controlled or downgraded destination.
ProviderHTTPClientsession for production provider calls.Cookie,Authorization, and API-key headers even on allowed same-origin HTTPS redirects.URLSession.shared.Security issues covered
Cookie,Authorization, or API-key headers could follow redirects without a central credential boundaryBefore this PR
Most provider fetchers send requests through
ProviderHTTPClient, but the production session used URLSession's default redirect handling. Several provider requests attach sensitive headers directly to the originalURLRequest, including cookies and API-key-style headers. ChatGPT web dashboard usage and identity calls also usedURLSession.shareddirectly with a cookie header.That meant redirect behavior was controlled per-call-site, or not guarded at all, unless the individual provider had custom redirect diagnostics. The already-merged #1226 fixed manual cookie reattachment for Amp/Ollama. This PR addresses the broader shared-client/direct-call path that remains outside that provider-specific fix.
After this PR
ProviderHTTPClientnow uses aURLSessionTaskDelegatein production. For each HTTP redirect it:The ChatGPT web dashboard requests now use
ProviderHTTPClient.shared, so their cookie-bearing usage/identity calls get the same redirect guard as other provider transports.OpenAIDashboardBrowserCookieImporter.fetchSignedInEmailFromAPIalso uses the guarded provider client for its cookie-bearing/backend-api/meand/api/auth/sessionprobes.Risk / compatibility
This is intentionally conservative for provider usage fetches because these calls may carry imported browser cookies or account/API credentials. Same-origin HTTPS redirects still work, but sensitive headers are stripped on the redirected request. Accepted compatibility impact: provider endpoints that currently require credentials after a redirect may fail until they return the final credentialed endpoint directly or perform their own credential re-challenge on the final URL. The security boundary is preferred here over implicit credential propagation through redirects.
XCTest still uses
URLSession.sharedin the existing test environment so registered URLProtocol stubs continue to work on macOS; the redirect guard is covered through focused unit tests on the delegate helper.Validation
swift /tmp/codexbar-redirect-guard-smoke.swift✅swift build --target CodexBarCore✅git diff --check✅swift test --filter ProviderHTTPClientTestsblocked by existing dependency/test setup issue inKeyboardShortcutspreviews:external macro implementation type 'PreviewsMacros.SwiftUIView' could not be found for macro 'Preview(_:body:)'.Notes for reviewers
No real secrets or account data are included. Test credential values are redacted placeholders only.
Follow-up validation for 11d0b5c
Addressed the remaining ClawSweeper rank-up item by broadening the redirect sanitizer to cover provider credential headers used by current callers:
X-DashScope-API-Key/x-dashscope-api-keyOasis-Token/oasis-tokenX-Amz-Security-Token/x-amz-security-tokenRegression coverage was extended in
ProviderHTTPClientTestsso same-origin HTTPS redirects must strip those headers while preserving non-sensitive headers likeAccept.Redacted after-fix proof:
Local focused test status:
Redirect compatibility note for maintainers: this PR still intentionally keeps the stricter fail-closed redirect policy: provider HTTP requests only follow same-origin HTTPS redirects, and credentials are stripped even on those allowed redirects. If any provider/custom endpoint relies on authenticated redirects, please explicitly accept that compatibility trade-off or tell me which redirect behavior to relax before merge.