Repository navigation
Check the authority of uri, uri-reference, iri and iri-reference - #1390
Conversation
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: (networknt#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 networknt#1389
|
Thanks for this. With format assertions on, the PR passes all the vendored suite cases and every assertion case in the upstream Should fix
Tests / cleanup
Pre-existing, related to the question in #1389
|
- 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.
|
Thanks for the careful review. Fixed in f1741ab:
On 8, agreed: |
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.
|
Also rejects bidi formatting characters in the path, query and fragment of iri and iri-reference (RFC 3987 section 4.1). |
|
Thanks, f1741ab and cb7d826 address everything we agreed on. With format assertions on, all vendored suite cases pass (7,709) and so do the 44 unit cases. I re-checked the fixed cases on the built branch: A few smaller points on the new code:
|
… 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.
|
Thanks, all six are in 99a4891:
|
|
Thanks, 99a4891 covers all six. I re-ran the format tests on the built branch (49 unit cases and 7,709 suite cases pass) and all upstream uri/iri assertion cases still pass. On that build, the new bidi characters (U+061C, U+2066–U+2069) are rejected in the host, userinfo and fragment, the percent-encoded form stays valid, and the Two small, non-blocking points:
Either can land here or later. Looks good to me otherwise, and the follow-up for the fallback regex works for me. |
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.
|
Thanks. Point 1 is in fa9de11: |
|
Thanks, fa9de11 looks good: it builds and the format tests pass. Doing One thing to keep in mind for that follow-up: Approving from my side. |
|
Hi Steve, just a gentle reminder on this one when you have a moment. Once it’s in, I’ll open the follow-up for the fallback regex and AbstractRFC3987Format |
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