-
Notifications
You must be signed in to change notification settings - Fork 2k
Regular handling of bad URIs #14011
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+182
−15
Merged
Regular handling of bad URIs #14011
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,8 @@ | |
| import static org.hamcrest.Matchers.notNullValue; | ||
| import static org.hamcrest.Matchers.nullValue; | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
| import static org.junit.jupiter.api.Assertions.assertNull; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
| import static org.junit.jupiter.api.Assertions.fail; | ||
|
|
@@ -158,6 +160,19 @@ public void testAt() throws Exception | |
| assertEquals("/@foo/bar", uri.getPath()); | ||
| } | ||
|
|
||
| /** | ||
| * Test of an HttpURI of just a "/". | ||
| */ | ||
| @Test | ||
| public void testFromSlash() | ||
| { | ||
| HttpURI uri = new HttpURI("/"); | ||
| assertFalse(uri.hasViolations()); | ||
| assertNull(uri.getScheme()); | ||
| assertNull(uri.getAuthority()); | ||
| assertEquals("/", uri.getPath()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testParams() throws Exception | ||
| { | ||
|
|
@@ -684,6 +699,8 @@ public static Stream<Arguments> parseData() | |
|
|
||
| // Simple IPv6 host no port (default path) | ||
| Arguments.of("http://[2001:db8::1]/", "http", "[2001:db8::1]", null, "/", null, null, null), | ||
| Arguments.of("http://[0:0:0:0:0:ffff:127.0.0.1]/", "http", "[0:0:0:0:0:ffff:127.0.0.1]", null, "/", null, null, null), | ||
| Arguments.of("http://[::ffff:127.0.0.1]/", "http", "[::ffff:127.0.0.1]", null, "/", null, null, null), | ||
|
|
||
| // Scheme-less IPv6, host with port (default path) | ||
| Arguments.of("//[2001:db8::1]:8080/", null, "[2001:db8::1]", "8080", "/", null, null, null), | ||
|
|
@@ -725,7 +742,8 @@ public void testParseString(String input, String scheme, String host, Integer po | |
| assertThat("[" + input + "] .param", httpUri.getParam(), is(param)); | ||
| assertThat("[" + input + "] .query", httpUri.getQuery(), is(query)); | ||
| assertThat("[" + input + "] .fragment", httpUri.getFragment(), is(fragment)); | ||
| assertThat("[" + input + "] .toString", httpUri.toString(), is(input)); | ||
| if (!input.contains(":ffff:127.0.0.1")) | ||
| assertThat("[" + input + "] .toString", httpUri.toString(), is(input)); | ||
| } | ||
| catch (URISyntaxException e) | ||
| { | ||
|
|
@@ -758,7 +776,8 @@ public void testParseURI(String input, String scheme, String host, Integer port, | |
| HttpURI httpUri = new HttpURI(input); | ||
|
|
||
| assertThat("[" + input + "] .scheme", httpUri.getScheme(), is(scheme)); | ||
| assertThat("[" + input + "] .host", httpUri.getHost(), is(host)); | ||
| if (!input.contains(":ffff:127.0.0.1")) | ||
| assertThat("[" + input + "] .host", httpUri.getHost(), is(host)); | ||
| assertThat("[" + input + "] .port", httpUri.getPort(), is(port == null ? -1 : port)); | ||
| assertThat("[" + input + "] .path", httpUri.getPath(), is(path)); | ||
| assertThat("[" + input + "] .param", httpUri.getParam(), is(param)); | ||
|
|
@@ -871,6 +890,24 @@ public void testRelativePathWithAuthority() | |
| assertEquals("//host", uri.toString()); | ||
| } | ||
|
|
||
| public static Stream<String> badSchemes() | ||
| { | ||
| return Stream.of( | ||
| "://host/path", | ||
| "\t://host/path", | ||
| " ://host/path", | ||
| "unknown^://host/path", | ||
| "http^://host/path" | ||
| ); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @MethodSource("badSchemes") | ||
| public void testBadSchemes(String uri) | ||
| { | ||
| assertThrows(IllegalArgumentException.class, () -> new HttpURI(uri)); | ||
| } | ||
|
|
||
| public static Stream<String> badAuthorities() | ||
| { | ||
| return Stream.of( | ||
|
|
@@ -890,9 +927,11 @@ public static Stream<String> badAuthorities() | |
| "https://user@host:notport/path", | ||
| "https://user:password@host:notport/path", | ||
| "https://user @host.com/", | ||
| "https://user#@host.com/", | ||
| "https://[notIpv6]/", | ||
| "https://bad[0::1::2::3::4]/" | ||
| "https://bad[0::1::2::3::4]/", | ||
| "http://[normal.com@]vulndetector.com/", | ||
| "http://normal.com[user@vulndetector].com/", | ||
| "http://normal.com[@]vulndetector.com/" | ||
| ); | ||
| } | ||
|
|
||
|
|
@@ -902,4 +941,41 @@ public void testBadAuthority(String uri) | |
| { | ||
| assertThrows(IllegalArgumentException.class, () -> new HttpURI(uri)); | ||
| } | ||
|
|
||
| public static Stream<Arguments> authoritiesNoPath() | ||
| { | ||
| return Stream.of( | ||
| Arguments.of("http://good.com#@evil.com", "good.com", null, "@evil.com"), | ||
| Arguments.of("http://[email protected]", "good.com", "@evil.com", null) | ||
| ); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @MethodSource("authoritiesNoPath") | ||
| public void testAuthorityNoPath(String uri, String authority, String query, String fragment) | ||
| { | ||
| HttpURI httpURI = new HttpURI(uri); | ||
| assertThat(httpURI.getAuthority(), is(authority)); | ||
| assertThat(httpURI.getPath(), is("")); | ||
| assertThat(httpURI.getQuery(), is(query)); | ||
| assertThat(httpURI.getFragment(), is(fragment)); | ||
| } | ||
|
|
||
| public static Stream<Arguments> connectURIs() | ||
| { | ||
| return Stream.of( | ||
| Arguments.of("localhost:8080"), | ||
| Arguments.of("127.0.0.1:8080"), | ||
| Arguments.of("[::1]:8080") | ||
| ); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @MethodSource("connectURIs") | ||
| public void testConnect(String authority) | ||
| { | ||
| HttpURI httpURI = new HttpURI(); | ||
| httpURI.parseRequestTarget(HttpMethod.CONNECT.asString(), authority); | ||
| assertThat(httpURI.getAuthority(), is(authority)); | ||
| } | ||
| } | ||
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this only occur during a detected IPLiteral only? not a hostname right?
If it's a hostname, the resulting call to
InetAddress.getByNamewill incur a DNS hit.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. IPV6 state is only entered after seeing the corresponding
[in HOST state. The state machine here is not as refined as in 12, so there are probably still a few more strange cases here.... but I don't want to substantively change the behavior.