Repository navigation
Fix: strip Cookie header on cross-origin redirects in RedirectHandler - #2007
Merged
Ramses Sanchez-Hernandez (ramsessanchez) merged 3 commits intoOct 15, 2026
Merged
Ramses Sanchez-Hernandez (ramsessanchez) merged 3 commits into
Ramses Sanchez-Hernandez (ramsessanchez) merged 3 commits into
Conversation
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
Ramses Sanchez-Hernandez (ramsessanchez)
requested a review
from a team
as a code owner
October 13, 2026 22:39
Adrian (adrian05-ms)
approved these changes
Oct 14, 2026
Ramses Sanchez-Hernandez (ramsessanchez)
merged commit Oct 15, 2026
be51dad
into
dev
8 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Security fix: strip Cookie header on cross-origin redirects
Problem
RedirectHandleronly removed theAuthorizationheader before following a 3xx redirect to a different origin. TheCookieheader (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-gov1.5.5+ (CVE-2026-44503): when a redirect crosses origins (different scheme, host, or port), both theAuthorizationandCookieheaders are now stripped before the redirected request is sent. Other headers are left untouched.Changes
src/middleware/MiddlewareUtil.ts: addedremoveRequestHeader(), a header-removal helper that works across the possibleHeadersInitrepresentations (Request,Headers, header-array, plain object), matching by key case-insensitively.src/middleware/RedirectHandler.ts: added aCOOKIE_HEADERconstant and now removes bothAuthorizationandCookieviaremoveRequestHeader()whenshouldDropAuthorizationHeader()determines the redirect is cross-origin.test/common/middleware/RedirectHandler.ts: added tests verifyingCookieis preserved on same-origin redirects, and that bothAuthorizationandCookieare dropped (while unrelated custom headers are preserved) on cross-origin redirects.Validation
node node_modules\typescript\bin\tsc -b tsconfig-sub-cjs.json— passednode node_modules\mocha\bin\mocha.js --require isomorphic-fetch --reporter dot lib/test/common/**/*.js lib/test/node/**/*.js— 359 passing