Repository navigation
Do not forward request credentials across origins on redirects - #343690
Karthik Nadig (karthiknadig) merged 3 commits into
Conversation
There was a problem hiding this comment.
🔵 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
|
Karthik Nadig (@karthiknadig) this is ready for your review. Thank you. |
2db314a to
c2c857c
Compare
CI investigation: macOS WebKit stallThe only underlying failure in https://github.com/microsoft/vscode/actions/runs/40382927764 is The WebKit page stopped making progress in 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 Drafted with GitHub Copilot. |
Karthik Nadig (karthiknadig)
left a comment
There was a problem hiding this comment.
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
2b4d0c9 to
b87c5a6
Compare
|
Karthik Nadig (@karthiknadig) ready for your review again |
Karthik Nadig (karthiknadig)
left a comment
There was a problem hiding this comment.
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.


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
Authorization,Cookie, andCookie2headers 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.Redirect behavior and compatibility
followRedirectsomitted0returns the redirect response.0disables following.0disables 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
npm run typecheck-clientnode build\next\build-fast.ts --client-onlynode --check .\test\unit\electron\index.js$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)'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.