Repository navigation
fetch: use standard base64 for proxy Basic auth credentials - #31782
Conversation
Proxy-Authorization: Basic <...> was encoded with the base64url alphabet (- _, no padding) instead of the standard alphabet (+ / with = padding) that HTTP Basic auth requires. Credentials whose standard base64 contains + or / (e.g. DataImpulse session tokens) were mangled, so strict proxies could not decode them and closed the connection. The buffer was already sized for the padded/standard length, so only the encoder call changes.
|
Warning Review limit reached
More reviews will be available in 3 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughThe PR fixes proxy authentication by switching from URL-safe Base64 encoding to standard Base64 encoding in the ChangesProxy Authentication Encoding
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
|
@robobun idk if you can take feedback from users here but this does NOT fix the problem user@0 mctk % bun-31782 checktok still happens |
There was a problem hiding this comment.
LGTM — one-line swap to the standard base64 encoder for Proxy-Authorization (RFC 7617), buffer already sized for padded output, with solid regression tests.
Extended reasoning...
Overview
The runtime change is a single line in src/http/AsyncHTTP.rs: build_proxy_authorization() now calls bun_base64::encode (standard alphabet, +//, =-padded) instead of bun_base64::encode_url_safe (-/_, unpadded) when building the Proxy-Authorization: Basic <…> header. I verified in src/base64/lib.rs / src/bun_core/util.rs that encode has the identical (dest, source) -> usize signature and that the buffer was already sized via encode_len_from_size → standard_encoder_calc_size, i.e. the padded length, so no allocation/buffer change is needed. The rest of the diff adds two regression tests in test/js/bun/http/proxy.test.ts that capture the actual on-wire header for both the absolute-form HTTP path and the CONNECT tunnel path and assert the exact standard-base64 bytes.
Security risks
None introduced. This affects only how user-supplied proxy credentials are base64-encoded into a header that was already being sent; the standard alphabet is what RFC 7617 mandates and what every HTTP proxy expects. No new inputs, no new code paths, no auth logic change.
Level of scrutiny
Low. The fix is mechanical (one encoder swapped for its sibling with the same signature), the rationale is unambiguous (HTTP Basic auth is standard base64, not base64url), and it's covered by targeted tests that assert the exact header value and self-check that the fixture actually distinguishes the two alphabets. No CODEOWNERS apply to either file.
Other factors
The bug-hunting pass surfaced only a consistency nit: two pre-existing long-password tests above the new block still decode the captured header with "base64url". That's not a functional issue (Node/Bun's base64url decoder accepts the standard alphabet, and the all-'a' fixture encodes identically in both), so it doesn't block approval. No outstanding reviewer comments and no prior reviews from me on this PR.
…explicit proxy The in-process fetch() tests assume the explicit `proxy` option is used for localhost targets. An ambient NO_PROXY/HTTP_PROXY/HTTPS_PROXY (set in some CI/dev environments) makes those fetches bypass the proxy, so they capture nothing and fail. Clear the six proxy vars file-wide in beforeAll (via assignment — a delete doesn't propagate to the HTTP client's getenv) and restore them in afterAll. Subprocess-based tests pass their own explicit env and are unaffected.
The header now uses standard base64 (not base64url) for Basic auth, so decode the captured Proxy-Authorization with "base64" to match — keeping the assertions consistent with the encoding under test.
|
CI status for maintainers: this diff is green — it only touches The red lanes on build #60222 are pre-existing tests unrelated to this change, aggregated across all 15 failing jobs:
Already spent the one CI re-roll (it produced #60222), so not pushing another per policy. Reporter has confirmed the fix works against a live DataImpulse proxy. Safe to merge over the unrelated registry flake. |
|
@robobun oddly enough, it seems to now work with those latest changes @Jarred-Sumner looks fine to merge, fixed the issue aight |
Fixes #31780
Repro
DataImpulse proxy credentials (and others with session tokens) routinely contain characters whose base64 encoding differs between the standard and URL-safe alphabets. Plain ASCII creds like
user:passencode identically in both, which is why it worked for some proxies but not DataImpulse.Cause
build_proxy_authorization()insrc/http/AsyncHTTP.rsbuilt theProxy-Authorization: Basic <...>header withbun_base64::encode_url_safe— the base64url alphabet (-/_, no=padding). HTTP Basic auth (RFC 7617) requires the standard alphabet (+//, with=padding).For example,
sub-user:sess>>id?ffencodes as:c3ViLXVzZXI6c2Vzcz4+aWQ/ZmY=c3ViLXVzZXI6c2Vzcz4-aWQ_ZmYA strict proxy decodes the header with the standard alphabet, gets garbage, rejects the credential, and closes the socket — producing the reporter's error. (The
.zigreference had the samestd.base64.url_safecall, so this is a long-standing bug, not a port regression.)Fix
Swap to the standard, padded encoder
bun_base64::encode(identical(dest, source) -> usizesignature). The buffer is already sized with the standard/padded length (encode_len_from_size==standard_encoder_calc_size), so no buffer-size change is needed.This is the only proxy-auth encode site. Other
encode_url_safecallers are legitimately URL-safe and are untouched.Verification
Added two cases to
test/js/bun/http/proxy.test.tscovering both proxy paths (absolute-form HTTP target and CONNECT HTTPS tunnel), using credentials whose standard base64 contains+and/. An in-process proxy captures theProxy-Authorizationheader; thefetchruns in a subprocess with proxy-bypass env cleared so the explicitproxyoption is honored.Basic c3ViLXVzZXI6c2Vzcz4-aWQ_ZmY(base64url) — failsBasic c3ViLXVzZXI6c2Vzcz4+aWQ/ZmY=(standard) — passes