Skip to content

Commit d832273

Browse files
aledbfclaude
andcommitted
fix(oci): read an ASCII auth host as Node.js 24 does
Node.js 24's URL parser only lower-cases a host that is all ASCII; it no longer checks its xn-- labels as Punycode, so xn--a, xn-- and xn--.example are hosts where Node.js 22 rejected them. The ts-oracle golden recorded Node.js 22's answers on one machine while CI ran Node.js 24, so the oracle gate failed there. domainToASCII now lower-cases any ASCII domain, and five more golden cases pin the rule. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 400e1f6 commit d832273

2 files changed

Lines changed: 89 additions & 22 deletions

File tree

‎internal/oci/testdata/ts-oracle/authpolicy.json‎

Lines changed: 85 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,7 +1118,11 @@
11181118
"registry.example=xn--a"
11191119
]
11201120
],
1121-
"error": "Invalid authority 'xn--a'."
1121+
"result": {
1122+
"registry.example": [
1123+
"xn--a"
1124+
]
1125+
}
11221126
},
11231127
{
11241128
"fn": "parseCrossOriginAuthHosts",
@@ -1310,7 +1314,11 @@
13101314
"registry.example=xn--.example"
13111315
]
13121316
],
1313-
"error": "Invalid authority 'xn--.example'."
1317+
"result": {
1318+
"registry.example": [
1319+
"xn--.example"
1320+
]
1321+
}
13141322
},
13151323
{
13161324
"fn": "parseCrossOriginAuthHosts",
@@ -1319,7 +1327,11 @@
13191327
"registry.example=XN--.example"
13201328
]
13211329
],
1322-
"error": "Invalid authority 'XN--.example'."
1330+
"result": {
1331+
"registry.example": [
1332+
"xn--.example"
1333+
]
1334+
}
13231335
},
13241336
{
13251337
"fn": "parseCrossOriginAuthHosts",
@@ -1954,6 +1966,76 @@
19541966
[]
19551967
],
19561968
"result": false
1969+
},
1970+
{
1971+
"name": "ascii xn-- label only lower-cased: xn--zz-",
1972+
"fn": "parseCrossOriginAuthHosts",
1973+
"args": [
1974+
[
1975+
"registry.example=xn--zz-"
1976+
]
1977+
],
1978+
"result": {
1979+
"registry.example": [
1980+
"xn--zz-"
1981+
]
1982+
}
1983+
},
1984+
{
1985+
"name": "ascii xn-- label only lower-cased: xn--Ab",
1986+
"fn": "parseCrossOriginAuthHosts",
1987+
"args": [
1988+
[
1989+
"registry.example=xn--Ab"
1990+
]
1991+
],
1992+
"result": {
1993+
"registry.example": [
1994+
"xn--ab"
1995+
]
1996+
}
1997+
},
1998+
{
1999+
"name": "ascii xn-- label only lower-cased: a.xn--",
2000+
"fn": "parseCrossOriginAuthHosts",
2001+
"args": [
2002+
[
2003+
"registry.example=a.xn--"
2004+
]
2005+
],
2006+
"result": {
2007+
"registry.example": [
2008+
"a.xn--"
2009+
]
2010+
}
2011+
},
2012+
{
2013+
"name": "ascii xn-- label only lower-cased: xn---",
2014+
"fn": "parseCrossOriginAuthHosts",
2015+
"args": [
2016+
[
2017+
"registry.example=xn---"
2018+
]
2019+
],
2020+
"result": {
2021+
"registry.example": [
2022+
"xn---"
2023+
]
2024+
}
2025+
},
2026+
{
2027+
"name": "ascii xn-- label only lower-cased: xn--a.xn--b",
2028+
"fn": "parseCrossOriginAuthHosts",
2029+
"args": [
2030+
[
2031+
"registry.example=xn--a.xn--b"
2032+
]
2033+
],
2034+
"result": {
2035+
"registry.example": [
2036+
"xn--a.xn--b"
2037+
]
2038+
}
19572039
}
19582040
]
19592041
}

‎internal/oci/whatwghost.go‎

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -138,19 +138,13 @@ var whatwgIDNA = idna.New(
138138
idna.VerifyDNSLength(false),
139139
)
140140

141-
// domainToASCII is WHATWG domain to ASCII (beStrict false). A pure-ASCII domain
142-
// with no "xn--" label only lower-cases, as the standard allows.
141+
// domainToASCII is WHATWG domain to ASCII (beStrict false) as Node.js 26 (the
142+
// version versions.yaml pins for the oracle) runs it: a pure-ASCII domain is
143+
// only lower-cased, its "xn--" labels not checked as Punycode.
143144
func domainToASCII(domain string) (string, error) {
144-
if isASCII(domain) && !hasPunycodeLabel(domain) {
145+
if isASCII(domain) {
145146
return strings.ToLower(domain), nil
146147
}
147-
// x/net/idna decodes a bare "xn--" label to an empty one; UTS #46, as
148-
// Node's ICU implements it, fails it as an empty Punycode label.
149-
for label := range strings.SplitSeq(domain, ".") {
150-
if strings.EqualFold(label, "xn--") {
151-
return "", errInvalidHost
152-
}
153-
}
154148
out, err := whatwgIDNA.ToASCII(domain)
155149
if err != nil || out == "" {
156150
return "", errInvalidHost
@@ -167,15 +161,6 @@ func isASCII(s string) bool {
167161
return true
168162
}
169163

170-
func hasPunycodeLabel(domain string) bool {
171-
for label := range strings.SplitSeq(domain, ".") {
172-
if strings.HasPrefix(strings.ToLower(label), "xn--") {
173-
return true
174-
}
175-
}
176-
return false
177-
}
178-
179164
// isForbiddenDomainCodePoint is the WHATWG forbidden domain code point set:
180165
// the forbidden host code points, C0 controls, '%' and DEL.
181166
func isForbiddenDomainCodePoint(r rune) bool {

0 commit comments

Comments
 (0)