Skip to content

examples: add idna-add-post-recheck - #186

Open
astrogilda wants to merge 1 commit into
uber-go:mainfrom
astrogilda:idna-add-post-recheck
Open

examples: add idna-add-post-recheck#186
astrogilda wants to merge 1 commit into
uber-go:mainfrom
astrogilda:idna-add-post-recheck

Conversation

@astrogilda

Copy link
Copy Markdown

Add an examples/ patch that rechecks the output of a UTS-46 mapping idna.*.ToASCII call for an IP literal.

UTS-46 NFKC mapping folds some Unicode digits to their ASCII equivalents. A host that does not parse as an IP literal before mapping can parse as one after, bypassing pre-mapping checks. The patch inserts:

if _, ipErr := netip.ParseAddr(strings.TrimRight(out, ".")); ipErr == nil {
    return "", errIDNAIPLiteralSmuggle
}

TrimRight handles multiple trailing dots. The trim applies only to the ParseAddr argument, leaving the ToASCII result unchanged.

This is the gopatch equivalent of Semgrep rule semgrep/semgrep-rules#3841 and CodeQL query github/codeql#21784.

Notes:

  • Matches the out, err := ...ToASCII(...) assignment form. Direct return ...ToASCII(x) is not matched.
  • Assumes a (string, error) return signature.
  • The error sentinel is assumed to be a package-level var. Since gopatch lacks an add-if-absent primitive for top-level declarations, the sentinel must be added separately.
  • Punycode ToASCII, StrictNoIPLiteral(), and url.Parse callers are out of scope.

I will sign the CLA.

Add an IP-literal recheck after a UTS-46 mapping ToASCII call. UTS-46 NFKC mapping can fold some Unicode digits to ASCII. A host that is not an IP literal before mapping can become one after. This patch rechecks the mapped output with netip.ParseAddr and returns an error if it parses as an IP.

Signed-off-by: Sankalp Gilda <sankalp.gilda@gmail.com>
@CLAassistant

CLAassistant commented Jun 25, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@astrogilda

Copy link
Copy Markdown
Author

Open since 25 June with the CLA green, no reviewer requested and no comment.

Before I spend more on it: does this project accept contributed examples at all? If not, say so and I will close it. The example rewrites a call site to add the post-IDNA IP-literal recheck.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants