Skip to content

fix(encodings): refuse punctuation in Punycode digits - #51

Merged
m4sh-wacker merged 4 commits into
OWASP:mainfrom
VISHNU0906:fix/punycode-non-basic-digit
Dec 1, 2026
Merged

m4sh-wacker merged 4 commits into
OWASP:mainfrom
VISHNU0906:fix/punycode-non-basic-digit

Conversation

@VISHNU0906

Copy link
Copy Markdown
Contributor

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 below 0, between 9 and A, and between Z and a came 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" and xn--[] gave xz. 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 to münchen, and xn--mnchen-3y!, xn--a:b and xn--[] 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 build and npm 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 test and npm run build all pass locally
  • Tests added or updated, including a case that would have failed before this change
  • No any introduced in application code
  • No eval, new Function, dangerouslySetInnerHTML, or innerHTML assignment
  • No new runtime dependency (or it was discussed in an issue first, linked above)
  • User-facing strings go through the i18n map (engine error text only, no UI change)
  • Layout / RTL and keyboard checks (no UI change)
  • Malformed and hostile input handled without crashing or hanging the tab

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.
@m4sh-wacker

Copy link
Copy Markdown
Collaborator

Thank you for your contribution and for taking the time to improve DecodeBox. Really appreciate your work!

@m4sh-wacker
m4sh-wacker merged commit 6da262b into OWASP:main Dec 1, 2026
6 checks passed
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