Loosen the validation rule for URI authority - #5854
Merged
Merged
Conversation
Motivation: The authority part in a URI was validated by `URI.parseServerAuthority()` which only allows alphanumeric characters, `.` and `-`. https://github.com/openjdk/jdk/blob/dc35f3e8a84c8f622a4cabb8aee0f96de2e2ea30/src/java.base/share/classes/java/net/URI.java#L3513-L3515 As a result, if underscore (`_`) is set in an authority, `URISyntaxException` is raised. We think the rule is too strict because a request can also be sent to an instance when CSLB is used. `_` is a valid character in a DNS record. Users may want to send a host whose name is `beta_api.cloud.somewhere.com`. Related: line#5814 Modifications: - Remove the usage of `URI.parseServerAuthority()` in `SchemeAndAuthority` - Parse a hostname and a port from a raw authority. Result: - Validation is relaxed to permit underscores (_) in URI's authority. - Closes line#5814
Contributor
trustin
reviewed
Aug 2, 2024
| "foo#bar", // Authority with fragment | ||
| "[192.168.0.1]", // Bracketed IPv4 | ||
| "[::1", "::1]", // Incomplete IPv6 | ||
| "[::1]%eth0", // IPv6 with scope |
Contributor
There was a problem hiding this comment.
I think an IPv6 address with scope is represented like this:
[::1%eth0]:8080
In this case, we should simply strip the scope and normalize into:
[::1]:8080
However, [::1]%eth0 should remain failing.
ikhoon
force-pushed
the
allow_underscore_authority
branch
from
August 3, 2024 05:42
bf7bbf2 to
5ab1d61
Compare
ikhoon
commented
Aug 8, 2024
…AndAuthorityTest.java
…AndAuthorityTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation:
The authority part in a URI was validated by
URI.parseServerAuthority()which only allows alphanumeric characters,.and-.https://github.com/openjdk/jdk/blob/dc35f3e8a84c8f622a4cabb8aee0f96de2e2ea30/src/java.base/share/classes/java/net/URI.java#L3513-L3515
As a result, if underscore (
_) is set in an authority,URISyntaxExceptionis raised. We think the rule is too strict because a request can also be sent to an instance when CSLB is used._is a valid character in a DNS record. Users may want to send a request to a host whose name isbeta_api.cloud.instance-123.somewhere.com.Related: #5814
Modifications:
URI.parseServerAuthority()inSchemeAndAuthorityResult:
Endpoint.host()#5814