Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: consistent proxy auth handling #146

Merged
merged 4 commits into from
Oct 23, 2024
Merged

Conversation

barjin
Copy link
Contributor

@barjin barjin commented Oct 23, 2024

Extracts and reuses the getBasic helper function.

Uses this helper to generate the Basic authentication header in the proxy hooks (before, this was done further down the line by http2-wrapper, see the related issue).

@barjin barjin added the adhoc Ad-hoc unplanned task added during the sprint. label Oct 23, 2024
@barjin barjin requested review from janbuchar and B4nan October 23, 2024 13:50
@barjin barjin self-assigned this Oct 23, 2024
@github-actions github-actions bot added this to the 101st sprint - Tooling team milestone Oct 23, 2024
@github-actions github-actions bot added the t-tooling Issues with this label are in the ownership of the tooling team. label Oct 23, 2024
CHANGELOG.md Outdated Show resolved Hide resolved
src/auth.ts Outdated Show resolved Hide resolved
@barjin barjin merged commit eea94e5 into master Oct 23, 2024
8 checks passed
@barjin barjin deleted the fix/consistent-auth-handling branch October 23, 2024 14:08
@azerum
Copy link

azerum commented Oct 27, 2024

Thanks for fixing! This has robbed me a few hours with proxy provider that used ; and . for passing params

There might be a potential issue: the code uses URL to parse url string and decodeURIComponent to retrieve the original username/password from parsed URL

URL uses percent-encoding scheme different from that of decodeURIComponent. The only difference I've found so far is using % in username. It is allowed, but decodeURIComponent breaks with it

new URL('http://us%r:[email protected]').username
'us%r'
decodeURIComponent('us%r')
Uncaught URIError: URI malformed

Perhaps most providers don't use %, but technically we would use inverse of percent-encoding URL does - percentDecodeBytes() from whatwg-url. Not sure if dependency is worth it

P.S.

For URL spec, see https://url.spec.whatwg.org/#concept-basic-url-parser, section authority state. Here's the step-by-step parsing of URL:

  1. https://url.spec.whatwg.org/#api-url-parser

  2. (Step 3) https://url.spec.whatwg.org/#concept-basic-url-parser

  3. The last link as a state machine of parser. Not super readable, but we can see how username/password is parsed in "authority state" section

  4. In "authority state", here's the loop that parses username/password character-by-character:

  1. For each codePoint in buffer:
    4.1. If codePoint is U+003A (:) and passwordTokenSeen is false, then set passwordTokenSeen to true and continue.
    4.2. Let encodedCodePoints be the result of running UTF-8 percent-encode codePoint using the userinfo percent-encode set.
    4.3. If passwordTokenSeen is true, then append encodedCodePoints to url’s password.
    4.4. Otherwise, append encodedCodePoints to url’s username.

Note that username/password user special set of characters for percent-decoding, which does not include %, that's why encoding does not touch it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
adhoc Ad-hoc unplanned task added during the sprint. t-tooling Issues with this label are in the ownership of the tooling team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants