Skip to content

Use the scheme's default port in Basic proxy authentication lookups - #131

Draft
Federico Brancasi (federicobrancasi) wants to merge 1 commit into
mainfrom
fbrancasi/proxy-auth-default-port
Draft

Federico Brancasi (federicobrancasi) wants to merge 1 commit into
mainfrom
fbrancasi/proxy-auth-default-port

Conversation

@federicobrancasi

Copy link
Copy Markdown
Member

When a proxy on its scheme's default port asks for Basic authentication (for example a PAC result PROXY proxy.example:80, or http.proxy set to https://proxy.example), createProxyAuthorizationLookup calls lookupAuthorization with port: 0. In VS Code the login dialog then says "The proxy proxy.example:0 requires a username and password.", and the credentials are stored under proxy.example:0, separately from the ones Electron stores under proxy.example:80 for VS Code's own requests, so the user is asked twice. Why: the lookup uses port: Number(url.port), and URL.port is '' when the port is the scheme's default (new URL('http://proxy.example:80').port === ''), so Number('') gives 0.

This PR passes the scheme's default port (80 for http:, 443 for https:) when the proxy URL has none, as Electron does.

How to test

Command Result
npm run test:unit 40 passing; the new test "createProxyAuthorizationLookup looks up Basic credentials with the default port of proxies without a port" fails without the change
npm run compile passes

When a proxy on its scheme's default port asks for Basic authentication (for example a PAC result `PROXY proxy.example:80`, or `http.proxy` set to `https://proxy.example`), `createProxyAuthorizationLookup` calls `lookupAuthorization` with `port: 0`. In VS Code the login dialog then says "The proxy proxy.example:0 requires a username and password.", and the credentials are stored under `proxy.example:0`, separately from the ones Electron stores under `proxy.example:80` for VS Code's own requests, so the user is asked twice. Why: the lookup uses `port: Number(url.port)`, and `URL.port` is `''` when the port is the scheme's default (`new URL('http://proxy.example:80').port === ''`), so `Number('')` gives `0`.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues block the fix aligning Basic proxy credential lookups with scheme-specific default ports.

No open issues 🎉

What changed in this PR

This PR corrects Basic proxy authentication lookups to use the scheme’s default port instead of 0, aligning credential lookups with Electron and avoiding duplicate authentication prompts.

Changes:

  • Use port 80 for HTTP and 443 for HTTPS when URL.port is empty.
  • Add regression coverage for an explicit HTTP default port and an omitted HTTPS port.
  • Document the fix in the changelog.
File Description
tests/​src/​createProxyAuthorizationLookup.test.ts Tests default-port values passed to credential lookups.
src/​index.ts Applies scheme-specific default ports for Basic authentication.
CHANGELOG.md Records the fix under version 0.46.1.

Review effort: Balanced

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