Repository navigation
fix(encodings): refuse punctuation in Punycode digits - #51
Merged
Merged
Conversation
The digit lookup relied on unsigned comparisons, as in the RFC 3492 sample code, but JavaScript subtraction is signed. Characters below '0', between '9' and 'A', and between 'Z' and 'a' came out as small or negative digits, so 'xn--mnchen-3y!' decoded to a wrong label instead of the 'non-basic digit' error. Check each digit range explicitly.
Collaborator
|
Thank you for your contribution and for taking the time to improve DecodeBox. Really appreciate your work! |
…c-digit # Conflicts: # src/engine/tests/operations.verified.test.ts
…HNU0906/DecodeBox into fix/punycode-non-basic-digit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes
The Punycode digit lookup follows the RFC 3492 sample code, which relies on unsigned comparisons (
cp - 48 < 10). In JavaScript the subtraction is signed, so characters below0, between9andA, and betweenZandacame out as small or negative digits instead of hitting the "non-basic digit" check. From Punycode then returned a wrong label:xn--mnchen-3y!gave "m" + U+0881 + "nchen" andxn--[]gavexz. Each digit range is now checked explicitly, so those inputs are refused.Related issue
none
How it was tested
New case in
operations.verified.test.ts:xn--mnchen-3YA(upper-case digits) still decodes tomünchen, andxn--mnchen-3y!,xn--a:bandxn--[]are refused with the non-basic digit error. The test fails on main.Locally on Node 24 and Node 22:
npm run lint,npm run typecheck,npm run test -- --run,npm run buildandnpm run check:sdk-dist, plus the CI Chrome load check and the GraalJS Java provider checks.Checklist
npm run lint,npm run typecheck,npm run testandnpm run buildall pass locallyanyintroduced in application codeeval,new Function,dangerouslySetInnerHTML, orinnerHTMLassignment