Skip to content

Do not forward request credentials across origins on redirects - #343690

Merged
Karthik Nadig (karthiknadig) merged 3 commits into
microsoft:mainfrom
mcumming:dev/mcumming/marketplace-redirect-hardening
Nov 4, 2026
Merged

Karthik Nadig (karthiknadig) merged 3 commits into
microsoft:mainfrom
mcumming:dev/mcumming/marketplace-redirect-hardening

Conversation

@mcumming

@mcumming Michael Cummings (MSFT) (mcumming) commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Related to microsoft/vscode#325412.

Summary

Keep application-supplied request credentials bound to their origin when redirects are followed. This change is scoped to the Node/Electron request service and its tests; it does not select marketplace tokens or change their lifetime.

Behavior

  • Node and manually followed Electron redirects resolve relative and protocol-relative locations to an exact HTTP(S) destination before comparing origins. Invalid or non-HTTP(S) destinations are not followed by that path.
  • A scheme, host, or effective-port change removes case-insensitive Authorization, Cookie, and Cookie2 headers and explicit basic credentials. Same-origin credentials, proxy authorization, and unrelated headers are preserved. Removed credentials are not restored by a later return to the original origin.
  • Header filtering does not mutate the caller's header object. Electron manual redirects preserve full destination URLs, including leading double slashes and encoded query components.
  • Electron method/body handling follows Chromium's redirect decision: POST-to-GET rewrites drop the body and its headers, while 307/308 retain them. Redirect handling preserves cancellation.

Redirect behavior and compatibility

Transport followRedirects omitted Explicit numeric limit
Node Existing three-redirect default Follow at most the supplied budget; 0 returns the redirect response.
Electron, no explicit origin credentials Chromium automatic handling, twenty-redirect default Manual handling enforces the supplied budget; 0 disables following.
Electron, explicit origin credentials Manual handling, twenty-redirect default Manual handling enforces the supplied budget; 0 disables following.

Explicit origin credentials include case-insensitive Authorization/Cookie/Cookie2 headers, basic-credential fields, and URL userinfo. Proxy authorization alone does not select manual mode. Each manual hop carries its remaining numeric budget, so stripping credentials cannot switch a chain to automatic handling or reset its limit.

Credential-bearing manual handling and enforced explicit limits are intentional request-service behavior changes affecting all main/shared-process callers, not only marketplace requests. Both default Electron modes have twenty-hop budgets rather than inheriting Node's three-hop default. Native session-managed authentication remains Chromium-owned.

Validation

Command Result
npm run typecheck-client Passed on the local implementation.
node build\next\build-fast.ts --client-only Passed.
node --check .\test\unit\electron\index.js Passed.
$env:VSCODE_SKIP_PRELAUNCH = '1'; .\scripts\test.bat --run src\vs\platform\request\test\node\requestService.test.ts --run src\vs\platform\request\test\electron-main\requestService.test.ts --grep 'Request Service(?! Kerberos lookup)' Passed: 89 tests.

Exercise real Electron automatic and explicit-limit modes, including a successful chain longer than three hops, cross-origin and out-and-back credential removal, signed URLs, method/body transitions, exhausted/zero budgets, and cancellation. The focused command excludes the unchanged environment-dependent Kerberos lookup case, not redirect cases.

Drafted with GitHub Copilot.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Unresolved redirect regressions and the security-sensitive Electron lifecycle require fixes and final human validation.

2 open issues
What changed in this PR

This PR hardens the shared request service against forwarding credentials across origins during redirects, following up on the marketplace authentication review without changing token negotiation.

Changes:

  • Resolve HTTP(S) redirect targets and strip origin credentials when the scheme, host, or effective port changes.
  • Handle Electron redirects manually to enforce credential policy and redirect limits on every hop.
  • Add Node and real Electron coverage for credentials, redirect chains, limits, method changes, and cancellation.
File Description
test/​unit/​electron/​index.js Adds an IPC bridge for tests using real Electron requests.
src/​vs/​platform/​request/​test/​node/​requestService.test.ts Covers redirect resolution, credential removal, limits, and cancellation.
src/​vs/​platform/​request/​test/​electron-main/​requestService.test.ts Tests Electron redirects against two loopback origins.
src/​vs/​platform/​request/​node/​requestService.ts Implements origin-aware credential stripping and manual Electron redirects.

Review effort: Balanced

@mariaghiondea

Copy link
Copy Markdown

Karthik Nadig (@karthiknadig) this is ready for your review. Thank you.

@mcumming
Michael Cummings (MSFT) (mcumming) force-pushed the dev/mcumming/marketplace-redirect-hardening branch from 2db314a to c2c857c Compare October 26, 2026 19:01
@mcumming

Copy link
Copy Markdown
Contributor Author

CI investigation: macOS WebKit stall

The only underlying failure in https://github.com/microsoft/vscode/actions/runs/40382927764 is Browser-Unit / macOS (job 121783881730). PR Gate fails because it aggregates that result; the other workflow jobs succeeded or were skipped.

The WebKit page stopped making progress in ChatPetWidget / cancels an interrupted host transition without leaving a floating overlay or pending animation. After 34,833 completed tests, the watchdog aborted it following 309 seconds without progress. The page no longer responded to evaluation, and its WebContent process was using 100% CPU. This is a browser-process stall, not a redirect test assertion failure.

The ChatPet test and widget are unchanged by this four-file PR. The failing browser runner excludes Node/Electron test modules and does not use this PR's Electron harness. Current main was also checked: neither the affected ChatPet test nor its widget has an upstream fix since the PR's base, so another rebase is not a demonstrated remedy. No unrelated code, skips, timeouts, or empty CI-trigger commits have been added.

I attempted gh run rerun 40382927764 --repo microsoft/vscode --failed; GitHub rejected it with Must have admin rights to Repository. A repository maintainer needs to rerun the failed jobs on the existing head c2c857c8b9a780f4b7be6ade59857c0d7a860a72. The check remains unresolved until that rerun succeeds. The separate VS Code PR Check is awaiting collaborator approvals, not another build failure.

Drafted with GitHub Copilot.

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.

Thanks. The Node path looks solid: redirect targets are resolved once, origins are compared normalized, origin credentials are stripped on any scheme/host/port change while Proxy-Authorization is kept, and they stay stripped on A→B→A chains. The real Electron tests are a nice touch.

Requesting changes for the Electron side (inline): switching every Electron-net request to manual redirects also changes the redirect limit for all main- and shared-process traffic. As Sandeep asked on #325815, this also needs chrmarti's review, since it affects every request-service consumer.


Review assisted by Copilot.

Resolve redirect locations before checking normalized origins, and remove origin credentials permanently after crossing an origin boundary. Handle Electron redirects manually so the same policy, redirect budget and cancellation apply to its transport.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 4359771f-3634-4c5e-9a56-5461a0c081aa
Pass the full URL to Electron so redirect paths beginning with two slashes are not parsed as authorities. Remove request-body headers and Origin when Chromium changes the method and drops the body, while retaining headers for method-preserving redirects and never mutating the caller's header object.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 4359771f-3634-4c5e-9a56-5461a0c081aa
Keep Chromium automatic redirects for credential-free requests without an explicit budget. Use manual redirects with a twenty-hop Electron default for origin credentials and honor explicit numeric budgets throughout the chain; keep Node's three-hop default.

Cover actual Electron mode selection, long chains, exact limits, host and port changes, basic credentials, signed paths, method/header transitions, and cancellation.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 4359771f-3634-4c5e-9a56-5461a0c081aa
@mcumming
Michael Cummings (MSFT) (mcumming) force-pushed the dev/mcumming/marketplace-redirect-hardening branch from 2b4d0c9 to b87c5a6 Compare November 2, 2026 19:57
@mariaghiondea

Copy link
Copy Markdown

Karthik Nadig (@karthiknadig) ready for your review again

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.

Thanks, this addresses my concern. Credential-free Electron requests without an explicit limit keep Chromium's automatic redirects, requests with credentials or an explicit limit use manual handling with a 20-hop default, and Node keeps 3. Honoring followRedirects: 0 on Electron also matches what the existing callers (MCP gallery, Agent Host downloads) already expect.

LGTM. Christof Marti (@chrmarti), Sandeep asked for your review of the request-service redirect changes on #325815; they now live here, so could you take a look?


Review assisted by Copilot.

@karthiknadig
Karthik Nadig (karthiknadig) merged commit ccbfade into microsoft:main Nov 4, 2026
55 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.146.0 milestone Nov 4, 2026
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.

7 participants