Skip to content

fix(crypto): reject non-canonical base64url input - #34

Merged
ExorTek merged 1 commit into
masterfrom
fix/crypto-base64url-canonical
Aug 6, 2026
Merged

fix(crypto): reject non-canonical base64url input#34
ExorTek merged 1 commit into
masterfrom
fix/crypto-base64url-canonical

Conversation

@ExorTek

@ExorTek ExorTek commented Aug 6, 2026

Copy link
Copy Markdown
Owner

Independent. This one carries a behaviour change — see the note at the bottom.

Node ignores the unused low bits of a final base64url character, so four distinct strings decoded to the same bytes:

decode('aGVsbG8') → "hello"      decode('aGVsbG9') → "hello"
decode('aGVsbG-') → "hello"      decode('aGVsbG_') → "hello"

Four spellings, one value — enough to slip past anything keyed on the encoded form rather than the bytes: a deny list, a dedupe set, a replay cache.

@exortek/shared/base64url already guards this with a round-trip check; crypto's own decoder validated the alphabet but not the canonical form. It now re-encodes and compares.

The JOSE stack (jwt, jws, jwe, jwk, paseto, security) already routes through the strict shared decoder, so this is confined to crypto's public encode surface. Verified separately that a malleated JWS signature is rejected with INVALID_SIGNATURE.

Behaviour change — released as a minor, not a patch. Input that previously decoded may now raise INVALID_ENCODING. Padding is still accepted, and everything encode produces still round-trips. The changeset spells this out for consumers.

Node ignores the unused low bits of a final base64url character, so
'aGVsbG8', 'aGVsbG9', 'aGVsbG-' and 'aGVsbG_' all decoded to "hello". Four
spellings, one value — enough to slip past anything keyed on the encoded form
rather than the bytes: a deny list, a dedupe set, a replay cache.

`@exortek/shared/base64url` already guards this with a round-trip check;
crypto's own decoder validated the alphabet but not the canonical form. It now
re-encodes and compares, accepting padding and everything `encode` produces.

Behaviour change, so a minor rather than a patch — input that previously
decoded may now raise INVALID_ENCODING.
Copilot AI lite review requested due to automatic review settings August 6, 2026 09:11

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@ExorTek
ExorTek merged commit b827c5c into master Aug 6, 2026
3 checks passed
@ExorTek
ExorTek deleted the fix/crypto-base64url-canonical branch August 6, 2026 09:27
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