Repository navigation
do not hand system proxy credentials to the origin server - #925
Conversation
|
@Hsnmohd HttpClient always requests credentials for a given authentication scope consisting of a combination of a host name, a port, a realm and a scheme. Conceptually, would consider it possible for a proxy and a server to use the same port on the same host and have different security model and access control? |
|
Not really. A host:port is one listener. It can act as both a proxy and an origin (httpd with mod_proxy, say), but that's still one endpoint under one admin, and the realm is what separates its protection spaces. Keying credentials on (host, port, realm, scheme) is right, and this PR doesn't change that. The leak comes from the requestor type, not the scope. On a 401 from an origin, the provider asks the Authenticator for SERVER and then for PROXY at the origin's host:port, which tells the Authenticator the origin is a proxy. The JDK's own clients only ask for PROXY on a 407 from the configured proxy, so the usual Authenticator hands out the proxy password whenever
|
@Hsnmohd There is no leak as long as proxy / server share the same host and port. |
|
@Hsnmohd You still want the requester type to be factored in when requesting credentials, this needs to be solved differently. The correct way would be by extending |
|
@ok2c Fair, the host:port check was the wrong tool for that. Reworked it the way you suggested: The challenge type is left out of |
@Hsnmohd These two scopes being equal, does not feel right. I think challenge type must be included in |
|
@Hsnmohd Please re-base your change-set on the latest master. |
SystemDefaultCredentialsProvider asked java.net.Authenticator for RequestorType.PROXY credentials whenever no SERVER credentials were found, whatever host issued the challenge. With an Authenticator that answers proxy requests, as is common for corporate proxies, any origin server replying 401 Basic was sent the proxy credentials. Use the challenge type now carried by AuthScope to pick the requestor type: SERVER for target challenges, PROXY for proxy challenges. Untyped scopes keep the SERVER-then-PROXY lookup.
00f7494 to
246e2f2
Compare
|
@ok2c Rebased. It's down to the |
SystemDefaultCredentialsProvider, the default credentials provider of every client builder, falls back to asking java.net.Authenticator for RequestorType.PROXY credentials for whatever host issued the challenge, so with the common
getRequestorType() == PROXYauthenticator any origin server that answers 401 Basic is sent the JVM's proxy credentials (reproduced with HttpClients.createDefault() and HttpAsyncClients.createDefault(), direct and behind a proxy); skip the PROXY lookup when the auth scope is the host:port of the request being executed, which leaves 407 handling for forwarded and CONNECT requests unchanged.