-
Notifications
You must be signed in to change notification settings - Fork 1.6k
skip origin Authorization on CONNECT proxy request #2234
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
hyperxpro
merged 2 commits into
AsyncHttpClient:main
from
madib06ops:connect-strip-origin-auth
Jul 4, 2026
+192
−4
Merged
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
65 changes: 65 additions & 0 deletions
65
client/src/test/java/org/asynchttpclient/netty/request/ConnectRequestAuthorizationTest.java
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 |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| /* | ||
| * Copyright (c) 2026 AsyncHttpClient Project. All rights reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.asynchttpclient.netty.request; | ||
|
|
||
| import io.netty.handler.codec.http.HttpHeaderNames; | ||
| import org.asynchttpclient.Realm; | ||
| import org.asynchttpclient.Request; | ||
| import org.asynchttpclient.proxy.ProxyServer; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.asynchttpclient.Dsl.basicAuthRealm; | ||
| import static org.asynchttpclient.Dsl.config; | ||
| import static org.asynchttpclient.Dsl.get; | ||
| import static org.asynchttpclient.Dsl.proxyServer; | ||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| /** | ||
| * A CONNECT request opens the proxy tunnel and is sent to the proxy in the clear, so it must not carry the | ||
| * origin {@code Authorization} header (which would expose the origin credentials to the proxy). The header | ||
| * belongs only on the request sent through the established tunnel. | ||
| */ | ||
| public class ConnectRequestAuthorizationTest { | ||
|
|
||
| private static NettyRequestFactory factory() { | ||
| return new NettyRequestFactory(config().build()); | ||
| } | ||
|
|
||
| @Test | ||
| public void connectRequestDoesNotCarryOriginAuthorization() { | ||
|
hyperxpro marked this conversation as resolved.
|
||
| Request request = get("https://origin.example.com/resource").build(); | ||
| Realm realm = basicAuthRealm("user", "secret").setUsePreemptiveAuth(true).build(); | ||
| ProxyServer proxy = proxyServer("proxy.example.com", 8080).build(); | ||
|
|
||
| NettyRequest connect = factory().newNettyRequest(request, true, proxy, realm, null); | ||
|
|
||
| assertFalse(connect.getHttpRequest().headers().contains(HttpHeaderNames.AUTHORIZATION), | ||
| "CONNECT request must not expose the origin Authorization to the proxy"); | ||
| } | ||
|
|
||
| @Test | ||
| public void tunneledRequestKeepsOriginAuthorization() { | ||
| Request request = get("https://origin.example.com/resource").build(); | ||
| Realm realm = basicAuthRealm("user", "secret").setUsePreemptiveAuth(true).build(); | ||
| ProxyServer proxy = proxyServer("proxy.example.com", 8080).build(); | ||
|
|
||
| NettyRequest tunneled = factory().newNettyRequest(request, false, proxy, realm, null); | ||
|
|
||
| assertTrue(tunneled.getHttpRequest().headers().contains(HttpHeaderNames.AUTHORIZATION), | ||
| "the request sent through the tunnel must still carry the origin Authorization"); | ||
| } | ||
| } | ||
112 changes: 112 additions & 0 deletions
112
client/src/test/java/org/asynchttpclient/proxy/ConnectRequestNtlmAuthorizationTest.java
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 |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| /* | ||
| * Copyright (c) 2026 AsyncHttpClient Project. All rights reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.asynchttpclient.proxy; | ||
|
|
||
| import jakarta.servlet.ServletException; | ||
| import jakarta.servlet.http.HttpServletRequest; | ||
| import jakarta.servlet.http.HttpServletResponse; | ||
| import org.asynchttpclient.AsyncHttpClient; | ||
| import org.asynchttpclient.RequestBuilder; | ||
| import org.asynchttpclient.Response; | ||
| import org.asynchttpclient.test.EchoHandler; | ||
| import org.asynchttpclient.util.HttpConstants; | ||
| import org.eclipse.jetty.proxy.ConnectHandler; | ||
| import org.eclipse.jetty.server.Handler; | ||
| import org.eclipse.jetty.server.Request; | ||
| import org.eclipse.jetty.server.Server; | ||
| import org.eclipse.jetty.server.ServerConnector; | ||
| import org.junit.jupiter.api.AfterEach; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.concurrent.atomic.AtomicReference; | ||
|
|
||
| import static org.asynchttpclient.Dsl.asyncHttpClient; | ||
| import static org.asynchttpclient.Dsl.config; | ||
| import static org.asynchttpclient.Dsl.get; | ||
| import static org.asynchttpclient.Dsl.ntlmAuthRealm; | ||
| import static org.asynchttpclient.Dsl.proxyServer; | ||
| import static org.asynchttpclient.test.TestUtils.addHttpConnector; | ||
| import static org.asynchttpclient.test.TestUtils.addHttpsConnector; | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
|
||
| /** | ||
| * NTLM (like Kerberos and SPNEGO) uses {@code perConnectionAuthorizationHeader} in {@code NettyRequestSender} | ||
| * rather than the per-request path in {@code NettyRequestFactory}. That header must not be attached to the | ||
| * CONNECT request, which is sent to the proxy in the clear before the tunnel exists. | ||
| */ | ||
| public class ConnectRequestNtlmAuthorizationTest { | ||
|
|
||
| private final List<Server> servers = new ArrayList<>(); | ||
| private int httpsPort; | ||
| private int proxyPort; | ||
| private final AtomicReference<String> connectAuthorization = new AtomicReference<>(); | ||
|
|
||
| private int startServer(Handler handler, boolean secure) throws Exception { | ||
| Server server = new Server(); | ||
| ServerConnector connector = secure ? addHttpsConnector(server) : addHttpConnector(server); | ||
| server.setHandler(handler); | ||
| server.start(); | ||
| servers.add(server); | ||
| return connector.getLocalPort(); | ||
| } | ||
|
|
||
| @BeforeEach | ||
| public void setUp() throws Exception { | ||
| httpsPort = startServer(new EchoHandler(), true); | ||
| proxyPort = startServer(new RecordingConnectHandler(), false); | ||
| } | ||
|
|
||
| @AfterEach | ||
| public void tearDown() { | ||
| servers.forEach(server -> { | ||
| try { | ||
| server.stop(); | ||
| } catch (Exception ignored) { | ||
| // couldn't stop server | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| @Test | ||
| public void connectRequestDoesNotCarryPreemptiveNtlmAuthorization() throws Exception { | ||
| try (AsyncHttpClient client = asyncHttpClient(config().setUseInsecureTrustManager(true))) { | ||
| RequestBuilder rb = get("https://localhost:" + httpsPort + "/foo/test") | ||
| .setProxyServer(proxyServer("localhost", proxyPort)) | ||
| .setRealm(ntlmAuthRealm("user", "secret").setUsePreemptiveAuth(true)); | ||
|
|
||
| Response response = client.executeRequest(rb.build()).get(); | ||
| assertEquals(200, response.getStatusCode()); | ||
| assertNull(connectAuthorization.get(), | ||
| "CONNECT request must not expose the origin NTLM Authorization to the proxy"); | ||
| } | ||
| } | ||
|
|
||
| private class RecordingConnectHandler extends ConnectHandler { | ||
| @Override | ||
| public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) | ||
| throws IOException, ServletException { | ||
| if (HttpConstants.Methods.CONNECT.equalsIgnoreCase(request.getMethod())) { | ||
| connectAuthorization.set(request.getHeader("Authorization")); | ||
| } | ||
| super.handle(target, baseRequest, request, response); | ||
| } | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.