Skip to content

Fix iri, iri-reference, uri and uri-reference - #1071

Merged
stevehu merged 1 commit into
networknt:masterfrom
justin-tay:gh1070
Jun 21, 2024
Merged

stevehu merged 1 commit into
networknt:masterfrom
justin-tay:gh1070

Conversation

@justin-tay

@justin-tay justin-tay commented Jun 21, 2024 •

Copy link
Copy Markdown
Collaborator

Closes #1070

This fixes iri, iri-reference, uri and uri-reference formats to allow inputs conforming to RFC 3986 / RFC 3987 for which URI will throw a syntax error as it implements RFC 2396.

In particular inputs like http://, // and about: are now accepted.

A more complete and proper fix will likely require an additional library like Apache Jena IRI but will defer this until it is really needed.

@stevehu
stevehu merged commit b93a66e into networknt:master Jun 21, 2024
@justin-tay
justin-tay deleted the gh1070 branch July 2, 2024 01:59
stevehu pushed a commit that referenced this pull request Nov 20, 2026
* Check the authority of uri, uri-reference, iri and iri-reference

java.net.URI falls back to a registry-based authority when it cannot
parse the authority as a server, and then checks neither the port, the
userinfo nor the host. So http://example.com:abc/path, //a@b@example.com/,
http://[::ffff:01.2.3.4] and an IPv6 address without brackets were
accepted.

AbstractRFC3986Format now checks a parsed authority against RFC 3986
section 3.2 for all four formats: the port is digits only, the userinfo
holds no other "@", the host is a reg-name or an IPv6 literal without
leading zeros in an embedded IPv4 address (reusing the ipv6 pattern), and
the IRI formats also allow RFC 3987 ucschar in the userinfo and the host.
URI#parseServerAuthority() is not used because it rejects valid
reg-names such as a_b.example. http:// and about: (#1071) stay valid.

Add the 12 failing JSON-Schema-Test-Suite cases to the vendored uri,
uri-reference, iri and iri-reference suite files (draft 6, 7, 2019-09,
2020-12 and draft-next) and a unit test for the edge cases.

Closes #1389

* Address review: IRI hosts, bidi characters, zone ids and cleanup

- IriFormat and IriReferenceFormat no longer run the IPv6 pattern on the
  decoded authority, which rejected a valid reg-name such as 1%3A%3A2.
  The port check already rejects an IPv6 address without brackets.
- The IRI formats reject the bidirectional formatting characters U+200E,
  U+200F and U+202A to U+202E in the userinfo and the host (RFC 3987
  section 4.1).
- The bracketed host is checked with a new IPv6Format.isValid, shared
  with the ipv6 format, instead of a copy of its checks. The branches for
  a missing "]" and for the port after "]" are removed: java.net.URI only
  returns a bracketed host after a successful server parse.
- UriAuthorityFormatTest drops two rows that never reached the new code
  and covers the cases above.
- The uri cases are added to the draft 3 and draft 4 suite files too.
- CHANGELOG: zone ids are now rejected, iri and iri-reference already
  rejected an IPv6 address without brackets, and third-party subclasses
  of AbstractRFC3986Format get the check and the isInternationalized()
  hook.

* Reject bidi formatting characters anywhere in an IRI

RFC 3987 section 4.1 forbids the bidirectional formatting characters
U+200E, U+200F and U+202A to U+202E anywhere in an IRI, not only in the
authority. iri and iri-reference now reject them in the path, the query
and the fragment too; the check moves from ucschar to the whole value.

The CHANGELOG example for a second "@" now uses an absolute URI, and an
unrelated whitespace change is reverted.

* Address review: guard the IPv6 bracket, wider bidi set, IRI-only bidi check

- The bracketed host check returns false instead of throwing if no "]"
  follows the "[".
- The IRI formats also reject U+061C (ALM) and the isolates U+2066 to
  U+2069, which can reorder the displayed text like the RFC 3987 list.
- The bidi check moves into IriFormat and IriReferenceFormat, so
  isInternationalized() controls only ucschar in the userinfo and host.
  It scans with a charAt loop.
- The draft 3 suite change is reverted: draft 3 has no runner.
- Tests cover bidi in the userinfo, a percent-encoded bidi character,
  and the added characters. The CHANGELOG is updated.

* Make containsBidiFormatting available to IRI-like subclasses

Address review: a subclass of AbstractRFC3986Format in another package
for an IRI-like format can now call containsBidiFormatting from its
validate(), and the CHANGELOG says it should.
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.

"http://" should be considered as a valid iri-reference

2 participants