Skip to content

fix: avoid argument limit in webauthn base64url encoding#1095

Open
samsamtrum wants to merge 1 commit into
magiclabs:masterfrom
samsamtrum:fix-webauthn-large-base64url
Open

fix: avoid argument limit in webauthn base64url encoding#1095
samsamtrum wants to merge 1 commit into
magiclabs:masterfrom
samsamtrum:fix-webauthn-large-base64url

Conversation

@samsamtrum
Copy link
Copy Markdown

@samsamtrum samsamtrum commented May 26, 2026

The WebAuthn Base64URL encoder currently spreads the full byte array into String.fromCharCode. Large buffers can exceed the JavaScript argument limit and throw a RangeError before encoding.

This keeps the same byte-to-string conversion, but processes the input in bounded chunks before calling btoa. That avoids passing the entire buffer as function arguments at once while preserving the encoded output.

Verified with a local Node check:

  • outputs match the existing implementation for 0, 1, 2, 3, 32, 1024, and 100000 byte buffers
  • existing implementation throws RangeError for a 200000 byte buffer
  • updated implementation encodes the 200000 byte buffer successfully

I also tried a direct TypeScript check for this file, but the partial dependency install in this workspace is missing several type packages, so that command fails in node_modules type resolution before validating this file.

@samsamtrum samsamtrum requested a review from a team as a code owner May 26, 2026 01:08
@samsamtrum samsamtrum force-pushed the fix-webauthn-large-base64url branch from ce59f7b to 6835cad Compare May 26, 2026 01:39
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