-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a
UriCompliance.Violation.USER_INFO
to deprecate user info in…
… `HttpURI` (#12012) As per [RFC9110](https://datatracker.ietf.org/doc/html/rfc9110#name-deprecation-of-userinfo-in-) user info is deprecated in server implementations. The new violation for USER_DATA is included by default in 12.0.x, but will be removed in 12.1.x
- Loading branch information
Showing
7 changed files
with
386 additions
and
76 deletions.
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.