Skip to content

fix(security): remove proxy and cookie auth headers on insecure redirect - #653

Merged
Michael Mainer (MIchaelMainer) merged 26 commits into
mainfrom
mmainer/redirect-sec
Feb 27, 2026
Merged

fix(security): remove proxy and cookie auth headers on insecure redirect#653
Michael Mainer (MIchaelMainer) merged 26 commits into
mainfrom
mmainer/redirect-sec

Conversation

@MIchaelMainer

@MIchaelMainer Michael Mainer (MIchaelMainer) commented Feb 11, 2026

Copy link
Copy Markdown
Contributor

Current behavior is that RedirectHandler only removes Authorization header on redirects that change host and scheme.

This PR addresses the scenario where proxy authorization, cookie authorization, or API Key headers are present on redirect.

Security Changes to RedirectHandler

1. Sensitive Header Scrubbing on Redirects

File: src/http/httpClient/Middleware/Options/RedirectHandlerOption.cs

  • Added ScrubSensitiveHeaders callback property - allows customization of which headers to remove during redirects. Useful for API Keys and other custom authorization headers.
  • Added DefaultScrubSensitiveHeaders static method implementing secure default behavior:
    • Removes Authorization and Cookie headers when redirecting to a different host or scheme
    • Removes Proxy-Authorization header when no proxy is active for the destination

2. Proxy-Aware Header Handling

File: src/http/httpClient/Middleware/RedirectHandler.cs

  • Added GetProxyResolver() method - returns a function that checks if a proxy applies to a destination URI
  • Added GetProxyFromFinalHandler() method - traverses the handler chain to extract IWebProxy from HttpClientHandler, SocketsHttpHandler, or WinHttpHandler
  • Integrated scrubbing callback into redirect flow

Why These Changes Matter

Header Risk Without Scrubbing
Authorization Credentials leaked to untrusted redirect target
Cookie Session tokens leaked cross-domain
Proxy-Authorization Proxy credentials sent directly to origin when proxy no longer applies

Ref: microsoft/kiota-java#2081

Comment thread tests/http/httpClient/Middleware/RedirectHandlerTests.cs Fixed
Comment thread tests/http/httpClient/Middleware/RedirectHandlerTests.cs Fixed
Comment thread tests/http/httpClient/Middleware/RedirectHandlerTests.cs Fixed
Comment thread tests/http/httpClient/Middleware/RedirectHandlerTests.cs Fixed
Comment thread tests/http/httpClient/Middleware/RedirectHandlerTests.cs Fixed
Comment thread tests/http/httpClient/Middleware/RedirectHandlerTests.cs Fixed
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
Comment thread tests/http/httpClient/Middleware/RedirectHandlerTests.cs Fixed
Comment thread tests/http/httpClient/Middleware/RedirectHandlerTests.cs Fixed
Comment thread tests/http/httpClient/Middleware/RedirectHandlerTests.cs Fixed
Comment thread tests/http/httpClient/Middleware/RedirectHandlerTests.cs Fixed
@github-project-automation github-project-automation Bot moved this to In Progress 🚧 in Kiota Feb 11, 2026
Comment thread src/http/httpClient/Middleware/RedirectHandler.cs Outdated

@baywet Vincent Biret (baywet) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a question regarding the proxy authorization

@MIchaelMainer Michael Mainer (MIchaelMainer) changed the title fix: remove proxy and cookie auth headers on insecure redirect fix(security): remove proxy and cookie auth headers on insecure redirect Feb 12, 2026
…t require a proxy

Remove ProxyAuthorization if:  No proxy is configured (header is meaningless without a proxy) OR proxy is configured but the redirect URL is bypassed (won't use the proxy); Keep ProxyAuthorization if proxy is configured AND the redirect URL will use the proxy
…r on redirect

This is useful for scenarios like API keys
Comment thread tests/http/httpClient/Middleware/RedirectHandlerTests.cs Fixed
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
Comment thread src/http/httpClient/Middleware/Options/RedirectHandlerOption.cs Outdated
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has conflicting changes, the author must resolve the conflicts before this pull request can be merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

5 participants