-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
Unable to send request URL path with dot-segments (without resolving) #8657
Comments
OkHttp tries strongly to follow the specifications and do the right thing in all cases. But there are some extra methods like |
From the tests, it may still be doing more changes than you want https://github.com/square/okhttp/blob/okhttp_4x/okhttp/src/test/java/okhttp3/HttpUrlTest.java So if this is not enough then I'm not sure we will introduce APIs to use (what we would consider based on specs) less correct paths. |
Thanks for replying 👍
New example below
Would you be able to point me in the direction of where this is implemented? Maybe then I can understand what transformations you do and how to work around them. |
Yeah I fully appreciate that you want to implement the spec correctly, but maybe you don't want to permit sending these characters at all if they are not valid URLs. My concern is mainly around the automatic transformations that you are doing and the vulnerabilities that could be introduced as a result when dealing with URLs sent between different libraries/servers/implementations. Jetty for example will by default raise exceptions for some of these invalid URLs (although this can be disabled and allowed to pass-through) |
This example is using ... instead of .. |
The tests refer to https://datatracker.ietf.org/doc/html/rfc3986#section-5.4 which seems pretty clear for parsing. I believe if we don't do this, things like caching won't work correctly. So this isn't likely to change. |
Sorry! Yes you are right, it is the HttpUrl object that modifies them:
|
@swankjesse thoughts? |
What also seems odd is that the // No encoding
var url1 = HttpUrl.get("https://example.com/").newBuilder().addEncodedPathSegments("foo/../bar").build();
assertThat(url1.toString()).isEqualTo("https://example.com/bar");
// Encoded once
var url2 = HttpUrl.get("https://example.com/").newBuilder().addEncodedPathSegments("foo/%2e%2e/bar").build();
assertThat(url2.toString()).isEqualTo("https://example.com/bar");
// Encoded twice
var url3 = HttpUrl.get("https://example.com/").newBuilder().addEncodedPathSegments("foo/%252e%252e/bar").build();
assertThat(url3.toString()).isEqualTo("https://example.com/foo/%252e%252e/bar"); |
Interestingly it is possible to do this: HttpUrl mockUrl = spy(HttpUrl.get(url));
when(mockUrl.encodedPath()).thenReturn("/abc/../123");
Request request = new Request.Builder().url(mockUrl).build(); resulting in:
which is used here when sending the request:
|
It doesn't seem to be possible to send a URL with raw / unresolved dot-segments.
The problem happens even when passing a Java
String
or JavaURL
. How to reproduce:Outputs:
Expected:
Similar problems:
\
with a/
in the URL|<>"
An example reason this could be a problem is if you are using untrusted / external input to build a URL then you don't want to risk allowing access to an unexpected web-server directory via
..
or an unexpected\
to/
conversion.Is there anyway to disable this URL normalisation behaviour?
The text was updated successfully, but these errors were encountered: