Skip to content

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

Merged
MIchaelMainer merged 26 commits intomainfrom
mmainer/redirect-sec
Feb 27, 2026
Merged

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

Conversation

@MIchaelMainer
Copy link
Copy Markdown
Member

@MIchaelMainer MIchaelMainer commented Feb 11, 2026

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

@MIchaelMainer MIchaelMainer requested a review from a team as a code owner February 11, 2026 18:07
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
adrian05-ms
adrian05-ms previously approved these changes Feb 11, 2026
@github-project-automation github-project-automation bot moved this to In Progress 🚧 in Kiota Feb 11, 2026
gavinbarron
gavinbarron previously approved these changes Feb 11, 2026
Copy link
Copy Markdown
Member

@baywet baywet left a comment

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 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
ramsessanchez and others added 3 commits February 13, 2026 12:45
…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
MIchaelMainer and others added 3 commits February 19, 2026 15:32
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
@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.

@github-project-automation github-project-automation bot moved this from In Progress 🚧 to Done ✔️ in Kiota Feb 27, 2026
@MIchaelMainer MIchaelMainer deleted the mmainer/redirect-sec branch February 27, 2026 19:07
This was referenced Mar 3, 2026
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