Skip to content

fix: send proxy credentials with the CONNECT request of HTTPS tunnels - #1574

Open
jlouvel wants to merge 2 commits into
3.0from
fix/netty-proxy-connect-auth
Open

jlouvel wants to merge 2 commits into
3.0from
fix/netty-proxy-connect-auth

Conversation

@jlouvel

@jlouvel jlouvel commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator

Closes #1569.

For HTTPS requests through an HTTP proxy, the Netty client opened the CONNECT tunnel without credentials, so an authenticating proxy refused it. The Proxy-Authorization header built from Request.getProxyChallengeResponse() was then sent to the origin server inside the tunnel, which leaked the proxy credentials to the origin.

The request's proxy credentials now go on the CONNECT request only, and a proxy refusal with a challenge comes back as a regular 407 response, as it already does for a forward proxy.

Changes

  • NettyClientCall: for tunneled exchanges, the Proxy-Authorization header is moved out of the request headers and kept for the CONNECT request. A HttpProxyConnectException carrying a Proxy-Authenticate header becomes a 407 response with its proxy challenge requests. Other refusals are still connector errors.
  • NettyClientHelper:
    • The header is sent with the CONNECT request.
    • Tunnels are pooled per origin and per proxy identity (scheme + identifier, so Digest nonces don't create new pools).
    • The TLS/ALPN/HTTP handlers are added only once the tunnel is established. Before, Netty failed the buffered TLS writes before completing the proxy connect future, so the refusal surfaced as a TLS/ALPN failure ("Failed to select the application-level protocol") and the 407 was lost.
    • The setup of directly connected channels is unchanged.
  • ProxyTestCase: the test proxy can require credentials on CONNECT and records them. New tests cover credentials on the CONNECT request only (none reach the origin), reuse of the authenticated tunnel, and the 407 challenge. The HTTPS setup is factored into helpers.
  • changes.md: entry under 3.0 Milestone 2, Bugs fixed.

Validation

./mvnw -B -pl org.restlet -P default,test verify: 2,217 tests passed, 0 failures. JaCoCo checks are met. SpotBugs reports 8 findings, under the threshold of 9.

Stack

This is the first of a stack of proxy fixes for the Netty client (#1569, #1570, #401, #1571, #1573, #1572). The next PRs are based on this branch.

🤖 Generated with Claude Code

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The pool can send requests through another user’s authenticated tunnel, and additional proxy handling and connection-management defects remain unresolved.

5 open issues
What changed in this PR

This PR addresses HTTPS proxy authentication in the Netty client by moving proxy credentials onto CONNECT requests rather than sending them to the origin server.

Changes:

  • Sends proxy authorization with CONNECT and exposes challenged tunnel refusals as 407 responses.
  • Separates tunnel pools by proxy identity and delays TLS/HTTP setup until CONNECT succeeds.
  • Adds authentication, credential-leak prevention, tunnel-reuse, and challenge tests, plus a changelog entry.
File Description
org.restlet/​src/​test/​java/​org/​restlet/​engine/​connector/​ProxyTestCase.java Adds authenticated CONNECT tests and reusable HTTPS setup helpers.
org.restlet/​src/​main/​java/​org/​restlet/​engine/​netty/​NettyClientHelper.java Updates tunnel authorization, pool selection, and protocol initialization.
org.restlet/​src/​main/​java/​org/​restlet/​engine/​netty/​NettyClientCall.java Separates proxy credentials from origin headers and translates challenged refusals.
changes.md Documents the HTTPS proxy authentication fix under 3.0 Milestone 2.

Review effort: Balanced

jlouvel and others added 2 commits November 1, 2026 08:43
The Netty client opened CONNECT tunnels without credentials, so an
authenticating proxy refused them, and the Proxy-Authorization header of
the request was sent to the origin server inside the tunnel.

- NettyClientCall: move the Proxy-Authorization header of tunneled
  exchanges out of the request headers, and return a refusal of the proxy
  carrying a Proxy-Authenticate challenge as a 407 response, like for a
  forward proxy.
- NettyClientHelper: send the header with the CONNECT request, keep
  tunnels apart per proxy credentials, and only add the TLS and HTTP
  handlers once the tunnel is established, so that the refusal of the
  proxy is reported as is rather than as a TLS handshake failure.
- ProxyTestCase: authenticating test proxy, tunnel reuse, 407 challenge.

Closes #1569.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Jerome Louvel <374450+jlouvel@users.noreply.github.com>
Review follow-ups for the CONNECT credentials of HTTPS tunnels.

- NettyClientCall: identify the tunnels of proxy credentials with a
  SHA-256 fingerprint of the scheme, raw value, identifier, secret and
  realm, so that different tokens or passwords never share a tunnel and
  the pool keys don't keep credentials in clear. Return only the
  Proxy-Authenticate challenges of a refused tunnel, not the entity
  headers of its discarded body.
- NettyClientHelper: the pools of an origin share its connection permits,
  so maxConnectionsPerDestination still bounds the connections across
  proxy credentials, an idle tunnel of other credentials being closed when
  needed. The pools of proxy credentials are dropped once they have no
  connection left.
- ProxyTestCase: tunnel per credentials, shared connection limit, no
  entity headers on a refused tunnel.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jlouvel
jlouvel force-pushed the fix/netty-proxy-connect-auth branch from 97714d6 to c42cc64 Compare November 1, 2026 13:46
@sonarqubecloud

sonarqubecloud Bot commented Nov 1, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants