-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Added a UriCompliance.Violation.USER_INFO
to deprecate user info in HttpURI
#12012
Merged
gregw
merged 3 commits into
jetty-12.0.x
from
experiment/12.0.x/deprecateHttpUriUserInfo
Jul 9, 2024
+386
−76
Merged
Changes from 1 commit
Commits
Show all changes
3 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
191 changes: 138 additions & 53 deletions
191
jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/HttpURI.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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 |
---|---|---|
|
@@ -34,6 +34,7 @@ | |
import static org.hamcrest.Matchers.nullValue; | ||
import static org.hamcrest.Matchers.sameInstance; | ||
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; | ||
|
@@ -59,6 +60,7 @@ public void testBuilder() | |
|
||
assertThat(uri.getScheme(), is("http")); | ||
assertThat(uri.getUser(), is("user:password")); | ||
assertTrue(uri.hasViolation(Violation.USER_INFO)); | ||
assertThat(uri.getHost(), is("host")); | ||
assertThat(uri.getPort(), is(8888)); | ||
assertThat(uri.getPath(), is("/ignored/../p%61th;ignored/info;param")); | ||
|
@@ -81,6 +83,7 @@ public void testBuilder() | |
|
||
assertThat(uri.getScheme(), is("https")); | ||
assertThat(uri.getUser(), nullValue()); | ||
assertFalse(uri.hasViolation(Violation.USER_INFO)); | ||
assertThat(uri.getHost(), is("[::1]")); | ||
assertThat(uri.getPort(), is(8080)); | ||
assertThat(uri.getPath(), is("/some%20encoded/evening;id=12345")); | ||
|
@@ -98,6 +101,7 @@ public void testExample() | |
|
||
assertThat(uri.getScheme(), is("http")); | ||
assertThat(uri.getUser(), is("user:password")); | ||
assertTrue(uri.hasViolation(Violation.USER_INFO)); | ||
assertThat(uri.getHost(), is("host")); | ||
assertThat(uri.getPort(), is(8888)); | ||
assertThat(uri.getPath(), is("/ignored/../p%61th;ignored/info;param")); | ||
|
@@ -155,11 +159,8 @@ public void testParse() | |
assertThat(uri.getHost(), is("foo")); | ||
assertThat(uri.getPath(), is("/bar")); | ||
|
||
// We do allow nulls if not encoded. This can be used for testing 2nd line of defence. | ||
builder.uri("http://fo\000/bar"); | ||
uri = builder.asImmutable(); | ||
assertThat(uri.getHost(), is("fo\000")); | ||
assertThat(uri.getPath(), is("/bar")); | ||
// We do not allow nulls if not encoded. | ||
assertThrows(IllegalArgumentException.class, () -> builder.uri("http://fo\000/bar").asImmutable()); | ||
} | ||
|
||
@Test | ||
|
@@ -327,6 +328,7 @@ public void testBasicAuthCredentials() | |
assertEquals("http://user:[email protected]:8888/blah", uri.toString()); | ||
assertEquals(uri.getAuthority(), "example.com:8888"); | ||
assertEquals(uri.getUser(), "user:password"); | ||
assertTrue(uri.hasViolation(Violation.USER_INFO)); | ||
} | ||
|
||
@Test | ||
|
@@ -1198,4 +1200,36 @@ public void testFromBad(String scheme, String server, int port, String expectedS | |
HttpURI httpURI = HttpURI.from(scheme, server, port, null); | ||
assertThat(httpURI.asString(), is(expectedStr)); | ||
} | ||
|
||
public static Stream<String> badAuthorities() | ||
{ | ||
return Stream.of( | ||
"http://#host/path", | ||
"https:// host/path", | ||
"https://h st/path", | ||
"https://h\000st/path", | ||
"https://h%GGst/path", | ||
"https://host%/path", | ||
"https://host%0/path", | ||
"https://host%u001f/path", | ||
"https://host%:8080/path", | ||
"https://host%0:8080/path", | ||
"https://user%@host/path", | ||
"https://user%0@host/path", | ||
"https://host:notport/path", | ||
"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]/" | ||
); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("badAuthorities") | ||
public void testBadAuthority(String uri) | ||
{ | ||
assertThrows(IllegalArgumentException.class, () -> HttpURI.from(uri)); | ||
} | ||
} |
This file contains 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 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 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
Oops, something went wrong.
Oops, something went wrong.
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.
Can we split the good and bad tests apart.
Also, can we use a hostname in the URI that is different than the one used in the
Host: local
header to make sure understand which host it is using?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.
I did that, but it only saves a couple of lines and requires 40 lines to be duplicated, so a net loss. It also makes it hard to see the difference between the 200 and 400 tests, which is good to see exactly what we are testing. So I prefer it as a single test.
I added a bunch more tests, including ones that allow HttpCompliance with different authorities.