Open
Description
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 Java URL
. How to reproduce:
@Test
void testUrl() throws Exception {
ServerSocket serverSocket = new ServerSocket(0, 50);
try (val executor = Executors.newVirtualThreadPerTaskExecutor()) {
executor.submit(() -> {
try {
val socket = serverSocket.accept();
try (var is = socket.getInputStream(); var os = socket.getOutputStream()) {
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
var firstLine = reader.readLine(); // e.g. 'GET /http/foo HTTP/1.1'
System.out.println("Request Line: " + firstLine);
socket.close();
}
} catch (IOException e) {
// ignored
}
});
String url = "http://localhost:" + serverSocket.getLocalPort() + "/abc/../123";
Request request = new Request.Builder().url(url).build();
OkHttpClient client = new OkHttpClient().newBuilder().build();
try (var response = client.newCall(request).execute()) {
System.out.println(response);
}
}
}
Outputs:
Request Line: GET /123 HTTP/1.1
Expected:
Request Line: GET /abc/../123 HTTP/1.1
Similar problems:
- OkHttpClient automatically replaces a
\
with a/
in the URL - OkHttpClient automatically escapes non-standard URL characters such as
|<>"
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?