Proxy authentication is the check a proxy server runs to confirm that a client is allowed to use it before it forwards any traffic. The client proves who it is with credentials, such as a username and password, or by connecting from an approved IP address. If the check fails, the proxy refuses the request. Over HTTP, a proxy that needs credentials answers with a 407 status code.
Username/Password vs. IP Whitelisting
- Username/password authentication sends credentials in the
Proxy-Authorizationheader, so it does not depend on the client's IP address - IP whitelisting authorizes specific source IPs or subnets without credentials, so requests from any other IP are refused
How the 407 Challenge Works
- Challenge: A proxy that needs credentials answers an unauthenticated request with
407 Proxy Authentication Required. The response must include aProxy-Authenticateheader that names the scheme to use, such asBasic. - Retry: The client repeats the request with a
Proxy-Authorizationheader that carries its credentials, for exampleProxy-Authorization: Basic <credentials>. - 407 vs. 401: A 407 works like a 401 Unauthorized, but it means the proxy needs credentials, not the website.
- Scope:
Proxy-Authorizationapplies only to the proxy that asked for it. In a chain of proxies, the first proxy that expects credentials consumes the header.
Keeping Proxy Credentials Secure
- Basic is not encryption: The Basic scheme only base64-encodes
username:password. Base64 is reversible, so this is equivalent to sending the credentials in clear text. - Prefer encrypted connections: MDN recommends HTTPS whenever authentication is used, and especially with Basic. Some clients, such as curl, can connect to the proxy itself over TLS with an
https://proxy URL. - Encode special characters: curl URL-decodes the username and password in a proxy string, so a password containing
@must be written as%40and a colon as%3a.