@@ -98,7 +98,7 @@ function ipToInt(ip) {
9898/**
9999 * Represents the proxy configuration for an agent. The built-in http and https agent
100100 * implementation have one of this when they are configured to use a proxy.
101- * @property {string } href - Full URL of the proxy server .
101+ * @property {string } href - Proxy server URL with credentials redacted .
102102 * @property {string } host - Full host including port, e.g. 'localhost:8080'.
103103 * @property {string } hostname - Hostname without brackets for IPv6 addresses.
104104 * @property {number } port - Port number of the proxy server.
@@ -109,13 +109,27 @@ function ipToInt(ip) {
109109 */
110110class ProxyConfig {
111111 constructor ( proxyUrl , keepAlive , noProxyList ) {
112- const { host, hostname, port, protocol, username, password } = new URL ( proxyUrl ) ;
112+ let parsedUrl ;
113+ try {
114+ parsedUrl = new URL ( proxyUrl ) ;
115+ } catch {
116+ throw new ERR_PROXY_INVALID_CONFIG ( `Invalid proxy URL: ${ proxyUrl } ` ) ;
117+ }
118+ const { host, hostname, port, protocol, username, password } = parsedUrl ;
113119 this . href = proxyUrl ; // Full URL of the proxy server.
114120 this . host = host ; // Full host including port, e.g. 'localhost:8080'.
115121 this . hostname = hostname . replace ( / ^ \[ | \] $ / g, '' ) ; // Trim off the brackets from IPv6 addresses.
116122 this . port = port ? NumberParseInt ( port , 10 ) : ( protocol === 'https:' ? 443 : 80 ) ;
117123 this . protocol = protocol ; // Protocol of the proxy server, e.g. 'http:' or 'https:'.
118124
125+ if ( username || password ) {
126+ parsedUrl . username = '' ;
127+ parsedUrl . password = '' ;
128+ this . href = parsedUrl . href ;
129+ } else {
130+ this . href = proxyUrl ;
131+ }
132+
119133 if ( username || password ) {
120134 // If username or password is provided, prepare the proxy-authorization header.
121135 const auth = `${ decodeURIComponent ( username ) } :${ decodeURIComponent ( password ) } ` ;
0 commit comments