Skip to content

Reject a trailing label separator in idn-hostname - #1384

Merged
stevehu merged 3 commits into
networknt:masterfrom
ravismash:fix/idn-hostname-trailing-separator
Nov 9, 2026
Merged

stevehu merged 3 commits into
networknt:masterfrom
ravismash:fix/idn-hostname-trailing-separator

Conversation

@ravismash

@ravismash ravismash commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Reject a trailing label separator in idn-hostname

Follow-up to #1377, as mentioned there: the JSON-Schema-Test-Suite treats a name ending in a label separator as an invalid idn-hostname, and #1377 still accepted a single one.

  • RFC5892.isValid no longer drops a trailing empty label, so example., example。, example. and example。 are rejected along with the other empty labels. hostname already rejects a trailing dot through its pattern, so the two formats now agree.
  • Re-enables the four trailing-separator cases in the vendored idn-hostname.json files (draft 7, 2019-09, 2020-12 and draft-next), 16 in all.
  • RFC5892Test.rejectsTrailingLabelSeparators tries each of the four separators after an ASCII label, a U-label and an A-label (12 combinations), alone and as the last label of a two-label name, and first asserts each name is valid without the separator. The 253-character test now expects name253 + "." to be invalid.
  • CHANGELOG: a new Breaking changes entry under Unreleased, because 3.0.9 and earlier accepted example. and an upgrade now rejects it. The Reject over-long hostnames and invalid A-labels in the hostname format #1377 entry no longer mentions trailing separators, and the known-limits line keeps only UTS 46 mapping.

This is a conformance choice: example. is a valid fully-qualified name with the root dot. Merging means following the upstream suite strictly; if you'd rather keep accepting FQDNs, this can be closed and the four suite cases left disabled.

2.x port: #1386 (same change on 2.x after #1383).

The UTS 46 mapping cases stay disabled. That's a separate, larger change.

The JSON-Schema-Test-Suite treats a trailing label separator (example., example。, example., example。) as an invalid idn-hostname, and hostname already rejects a trailing dot. networknt#1377 still accepted one trailing separator. Reject it, and re-enable the 16 upstream cases that were disabled for it.
@stevehu

stevehu commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Review of this PR (head 46870f9). I found no defect. I ran the full suite with the PR applied on master: 10,945 tests, 0 failures, 45 skipped. I also compared isValid on master and on this branch for 800,000 random names. Every difference is a valid name that ends in a label separator and is now rejected; there are no other differences. Only minor points remain, ranked most-severe first.

1. 2.x backport #1383 will disagree with master (CHANGELOG.md:15)
#1383 ports #1377 to 2.x, including the "A single trailing separator is still accepted" line and acceptsAtMostOneTrailingLabelSeparator. This PR changes master only. If #1383 merges without this change, idn-hostname accepts example. on 2.x and rejects it on master, and the two CHANGELOGs contradict each other. This change could land on #1383 first, or get its own 2.x follow-up.

2. labelCount is now a redundant alias (RFC5892.java:186)
It existed so labelCount-- could drop one trailing empty label. That line is gone, so int labelCount = labels.length; is never changed. labels.length can be used directly on lines 187 and 189.

3. The test comment overstates the matrix (RFC5892Test.java:348)
The comment, like the PR description, says each separator is tried after an ASCII label, a U-label and an A-label. That would be 12 combinations, but lines 349-352 test 4, one per separator. The code path is the same for all of them today, so this is cosmetic. A loop over separators and label kinds would match the comment, or the comment could be reworded.

@stevehu

stevehu commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

A note on whether to merge this, separate from the code review above.

This is a conformance choice rather than a bug fix. The case for merging: the upstream JSON-Schema-Test-Suite marks example. as an invalid idn-hostname, and hostname already rejects a trailing dot, so the two formats would agree.

The case against: example. was accepted in every released version up to 3.0.9. It is a valid fully-qualified domain name with the root dot, so code that validates DNS-style input may legitimately contain it. The CHANGELOG entry sits in the Unreleased entry from #1377, which makes it read as a change to unreleased behaviour. For anyone upgrading from 3.0.9 it is a new rejection. It also reverses the choice made in #1377, which kept a single trailing separator on purpose.

Recommendation: merge this only if the project wants to follow the upstream suite strictly. In that case:

If the project would rather not break callers that pass FQDNs, close this and leave the four trailing-separator suite cases disabled with their reason. Either choice is defensible; it is a policy decision for the maintainers.

…y separator and label kind

The trailing-separator rejection gets its own Breaking changes entry
in Unreleased, because 3.0.9 and earlier accepted example. and an
upgrade now rejects it. It no longer reads as part of the networknt#1377
entry.

labelCount was only needed to drop one trailing empty label, so
labels.length is used directly.

rejectsTrailingLabelSeparators now tries all four separators after an
ASCII label, a U-label and an A-label, alone and as the last label of
a two-label name. Each name is first asserted valid without the
separator, so the rejection is caused by the trailing separator alone.
@ravismash

Copy link
Copy Markdown
Contributor Author

Thanks for the note on whether to merge. I'd go with the upstream suite, so example. is rejected and idn-hostname agrees with hostname. It's your call, though. If you'd rather keep accepting FQDNs, I'll close this and leave the four cases disabled.

If it goes in, both of your conditions are done:

  1. CHANGELOG: it's now its own Breaking changes entry under Unreleased. It says 3.0.9 and earlier accepted example., and that callers should strip the trailing dot. It's no longer part of the Reject over-long hostnames and invalid A-labels in the hostname format #1377 entry.
  2. 2.x: Backport hostname and IDNA validation fixes to 2.x #1383 has merged, so the port is Reject a trailing label separator in idn-hostname on 2.x #1386. It applies the same change on 2.x, and the 2.x CHANGELOG and tests now say a trailing separator is rejected.

From the code review:

  • labelCount is removed, and labels.length is used directly.
  • rejectsTrailingLabelSeparators loops over the four separators after an ASCII label, a U-label and an A-label. That's the 12 combinations the comment describes, each also tested as the last label of a two-label name. Each name is first asserted valid without the separator, so the separator alone causes the rejection.

Full suite with this commit: 10,945 tests, 0 failures, 45 skipped.

@stevehu

stevehu commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Review of head 2b97914 (the commit since 46870f9). I found no defect. The full suite passes on JDK 25: 10945 tests, 0 failures, 45 skipped. All earlier points are addressed: labelCount is gone, the test covers 3 label kinds × 4 separators, the entry is under Breaking changes, and the four suite cases are re-enabled. Three minor points remain, most-severe first.

1. 2.x and master disagree until #1386 lands (CHANGELOG.md:11)
#1383 is already merged and says example. is valid on 2.x. A 2.x release cut before #1386 merges accepts example. while 3.x rejects it. Merge #1386 before, or together with, any 2.x release. Its wording "Released versions up to 3.0.9" also needs rewording for 2.x.

2. Run-on @return (RFC5892.java:172)
It joins the label rules, the 253-character limit, the Bidi domain rule and the trailing-separator rule in one sentence. A short list in the method description would be clearer.

3. No format-level test (RFC5892Test.java:349)
IdnHostnameFormat.matches delegates to RFC5892.isValid, and only the vendored suite covers the format class. A one-line assertFalse(new IdnHostnameFormat().matches(null, "example.")) would pin the contract.

The isValid Javadoc lists the rules instead of joining them in the
@return sentence, and names leading and doubled separators along with
the trailing one.

idnHostnameFormatRejectsTrailingLabelSeparator checks the
IdnHostnameFormat contract directly, not only RFC5892.isValid.
ravismash added a commit to ravismash/json-schema-validator that referenced this pull request Nov 9, 2026
…t class

The entry names 2.0.8, the latest 2.x release, which skipped empty
labels: .example, a..b and example. were all valid there. It now
covers leading and doubled separators too, and links networknt#1386 and networknt#1384.

Also ports the networknt#1384 review changes: the isValid Javadoc lists the
rules, and idnHostnameFormatRejectsTrailingLabelSeparator checks the
IdnHostnameFormat contract directly.
@ravismash

Copy link
Copy Markdown
Contributor Author
  1. Agreed, Reject a trailing label separator in idn-hostname on 2.x #1386 should merge before or together with the next 2.x release. I've fixed its CHANGELOG wording there.
  2. The isValid Javadoc now lists the rules: valid labels, the 253-character limit, the Bidi domain rule, and no empty label (a leading, doubled or trailing separator).
  3. Added idnHostnameFormatRejectsTrailingLabelSeparator, which checks new IdnHostnameFormat().matches(null, "example.") directly.

Full suite with this commit: 10,946 tests, 0 failures, 45 skipped.

stevehu pushed a commit that referenced this pull request Nov 9, 2026
* Reject a trailing label separator in idn-hostname on 2.x

Port of #1384 to 2.x. The JSON-Schema-Test-Suite treats a trailing
label separator (example., example。, example., example。) as an
invalid idn-hostname, and hostname already rejects a trailing dot.
#1383 still accepted one trailing separator on 2.x. Reject it, so
2.x and master agree, and re-enable the 16 upstream cases that were
disabled for it.

* Address review: 2.x CHANGELOG wording, list the rules, test the format class

The entry names 2.0.8, the latest 2.x release, which skipped empty
labels: .example, a..b and example. were all valid there. It now
covers leading and doubled separators too, and links #1386 and #1384.

Also ports the #1384 review changes: the isValid Javadoc lists the
rules, and idnHostnameFormatRejectsTrailingLabelSeparator checks the
IdnHostnameFormat contract directly.
@stevehu

stevehu commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Review of head 772a02e (the commit since 2b97914). All three earlier points are addressed and I found no defect.

The full suite passes on JDK 25: 10946 tests, 0 failures, 45 skipped, and the new test runs.

@stevehu
stevehu merged commit 2c0b245 into networknt:master Nov 9, 2026
3 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