Skip to content

fix: substitute forward slash, not backslash, when encoding base64url - #104

Open
mmorales-post wants to merge 1 commit into
Mastercard:mainfrom
mmorales-post:fix/base64url-forward-slash
Open

fix: substitute forward slash, not backslash, when encoding base64url#104
mmorales-post wants to merge 1 commit into
Mastercard:mainfrom
mmorales-post:fix/base64url-forward-slash

Conversation

@mmorales-post

Copy link
Copy Markdown

PR checklist

  • An issue/feature request has been created for this PR
  • Pull Request title clearly describes the work in the pull request and the Pull Request description provides details about how to validate the work
  • File the PR against the master branch
  • The code in this PR is covered by unit tests

Link to issue/feature request: #103

Description

toEncodedString substituted \ instead of / when converting base64 to base64url, so
forward slashes were left unescaped in every JWE segment. This changes the regex to /\//g.

Both the current and corrected encodings decode successfully, so this is backward
compatible.

Two tests added to test/jwe-crypto.test.js:

  • #encryptData() asserts every segment of 25 generated tokens matches ^[A-Za-z0-9_-]+$.
    The loop keeps the assertion independent of the random content encryption key and IV.
  • #toEncodedString() covers the substitution directly through rewire, including that a
    non base64url target format is left untouched.

Both fail on main and pass with the fix. Full suite: 192 passing.

Validated on Node 24.

@mmorales-post
mmorales-post marked this pull request as ready for review August 24, 2026 19:47
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.

1 participant