Skip to content

Decode URL credentials in the patched http/https like Node.js - #130

Draft
Federico Brancasi (federicobrancasi) wants to merge 1 commit into
mainfrom
fbrancasi/decode-url-credentials
Draft

Federico Brancasi (federicobrancasi) wants to merge 1 commit into
mainfrom
fbrancasi/decode-url-credentials

Conversation

@federicobrancasi

Copy link
Copy Markdown
Member

An extension that calls https.get('https://user%40example.com:p%40ss@host/') in VS Code sends Authorization: Basic with the still-encoded credentials user%40example.com:p%40ss, so the server rejects them with 401. Plain Node.js sends user@example.com:p@ss. A user name or password that contains @, :, /, #, % or a space has to be percent-encoded in a URL, so this hits every such credential. Why: when the patched get/request turns the URL into options, it sets options.auth = ${parsed.username}:${parsed.password}``, but URL.username and `URL.password` are percent-encoded. Node.js' own `urlToHttpOptions` decodes them with `decodeURIComponent`. With the default `http.proxySupport` (`override`), every extension request goes through this code, also for direct connections.

This PR decodes the user name and password with decodeURIComponent, as Node.js does.

How to test

Command Result
npm run test:unit 40 passing; the new test "createHttpPatch decodes the credentials of a URL like Node.js" fails without the change
npm run compile passes

An extension that calls `https.get('https://user%40example.com:p%40ss@host/')` in VS Code sends `Authorization: Basic` with the still-encoded credentials `user%40example.com:p%40ss`, so the server rejects them with 401. Plain Node.js sends `user@example.com:p@ss`. A user name or password that contains `@`, `:`, `/`, `#`, `%` or a space has to be percent-encoded in a URL, so this hits every such credential. Why: when the patched `get`/`request` turns the URL into options, it sets `options.auth = `${parsed.username}:${parsed.password}``, but `URL.username` and `URL.password` are percent-encoded. Node.js' own `urlToHttpOptions` decodes them with `decodeURIComponent`. With the default `http.proxySupport` (`override`), every extension request goes through this code, also for direct connections.

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 are reported for the URL credential-decoding change.

No open issues 🎉

What changed in this PR

This PR aligns URL credential handling in the patched HTTP/HTTPS client with Node.js, fixing authentication failures when usernames or passwords contain percent-encoded characters.

Changes:

  • Decode URL usernames and passwords before setting options.auth.
  • Add a regression test comparing patched and native Node.js authentication.
  • Document the fix in the changelog.
File Description
tests/​src/​createHttpPatch.test.ts Tests decoded credentials against native Node.js behavior.
src/​index.ts Decodes URL credentials with decodeURIComponent.
CHANGELOG.md Records the credential-decoding fix for 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