Skip to content

uri, uri-reference, iri and iri-reference accept an invalid authority (port, userinfo, IP literal) #1389

Closed

Description

@ravismash

The latest JSON-Schema-Test-Suite (json-schema-org/JSON-Schema-Test-Suite@e2a68a1, format-uri.json, format-uri-reference.json, format-iri.json, format-iri-reference.json) has new cases that master (74b7e58) and 1.5.9 both fail, with format assertions on. All of them accept an authority that RFC 3986 section 3.2 rejects:

format input expected
uri http://example.com:abc/path invalid: non-numeric port
uri http://2001:0db8:85a3:0000:0000:8a2e:0370:7334 invalid: IPv6 without brackets
uri http://[::ffff:01.2.3.4] invalid: leading zero in embedded IPv4
uri-reference //example.com:abc/p invalid: non-numeric port
uri-reference //a@b@example.com/ invalid: more than one @
uri-reference //[::ffff:192.168.0.01]/p invalid: leading zero in embedded IPv4

iri and iri-reference fail the same three kinds of case (non-numeric port, two @, leading zero in embedded IPv4), 12 cases in total.

I think the cause is in AbstractRFC3986Format: when java.net.URI can't parse the authority as server-based, it silently treats it as a registry-based authority, so the port, userinfo and host are never checked. URI.parseServerAuthority() isn't a fix on its own because it rejects valid reg-names such as a_b.example.

I'd like to send a PR that checks the authority against the RFC 3986 grammar in AbstractRFC3986Format (so all four formats get it), adds the new suite cases, and keeps http:// and about: valid (#1071).

One related question: UriFormatTest.noSchemeNoAuthorityShouldPass expects "//" to be a valid uri, but RFC 3986 section 3 requires a scheme for a URI ("//" is fine as a uri-reference). Should that change too, or stay as it is?

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions