Skip to content

Fix: strip Cookie header on cross-origin redirects in RedirectHandler - #2007

Merged
Ramses Sanchez-Hernandez (ramsessanchez) merged 3 commits into
devfrom
fix/redirect-handler-strip-cookie-header
Oct 15, 2026
Merged

Ramses Sanchez-Hernandez (ramsessanchez) merged 3 commits into
devfrom
fix/redirect-handler-strip-cookie-header

Conversation

@ramsessanchez

Copy link
Copy Markdown
Contributor

Security fix: strip Cookie header on cross-origin redirects

Problem

RedirectHandler only removed the Authorization header before following a 3xx redirect to a different origin. The Cookie header (and any other forwarded headers) continued to be sent to the new redirect target, including when the redirect pointed to a different scheme, host, or port. This could leak session cookies to an untrusted host.

Fix

Aligns this SDK with the fix shipped in microsoft-kiota-http-go v1.5.5+ (CVE-2026-44503): when a redirect crosses origins (different scheme, host, or port), both the Authorization and Cookie headers are now stripped before the redirected request is sent. Other headers are left untouched.

Changes

  • src/middleware/MiddlewareUtil.ts: added removeRequestHeader(), a header-removal helper that works across the possible HeadersInit representations (Request, Headers, header-array, plain object), matching by key case-insensitively.
  • src/middleware/RedirectHandler.ts: added a COOKIE_HEADER constant and now removes both Authorization and Cookie via removeRequestHeader() when shouldDropAuthorizationHeader() determines the redirect is cross-origin.
  • test/common/middleware/RedirectHandler.ts: added tests verifying Cookie is preserved on same-origin redirects, and that both Authorization and Cookie are dropped (while unrelated custom headers are preserved) on cross-origin redirects.

Validation

  • node node_modules\typescript\bin\tsc -b tsconfig-sub-cjs.json — passed
  • node node_modules\mocha\bin\mocha.js --require isomorphic-fetch --reporter dot lib/test/common/**/*.js lib/test/node/**/*.js — 359 passing

The RedirectHandler middleware only removed the Authorization header
before following a 3xx redirect to a different origin, while still
forwarding the Cookie header to the new host. This allowed session
cookies to leak to a different scheme/host/port on redirect.

This aligns the behavior with the fix shipped in microsoft-kiota-http-go
v1.5.5+, which strips both Authorization and Cookie headers when the
redirect target has a different scheme, host, or port than the original
request.

- Added removeRequestHeader() in MiddlewareUtil.ts, supporting Request,
  Headers, header-array, and plain-object header representations
  (case-insensitive key match).
- RedirectHandler now drops both Authorization and Cookie headers on
  cross-origin redirects using the new helper.
- Added tests covering Cookie header retention on same-origin redirects
  and removal (while preserving unrelated custom headers) on
  cross-origin redirects.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 6f3ec234-f644-4f5f-835d-575129c4af42
@ramsessanchez
Ramses Sanchez-Hernandez (ramsessanchez) merged commit be51dad into dev Oct 15, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants