Skip to content

Commit

Permalink
hide proxy password in server log (#50)
Browse files Browse the repository at this point in the history
* hide proxy password in server log

* fixup! hide proxy password in server log

* fixup! fixup! hide proxy password in server log

* fixup! fixup! fixup! hide proxy password in server log

* fixup! fixup! fixup! fixup! hide proxy password in server log

* fixup! fixup! fixup! fixup! fixup! hide proxy password in server log
  • Loading branch information
Karry authored Feb 12, 2025
1 parent c98155c commit ffcb42d
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions server/src/session_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,31 @@ export class SessionManager {
proxy = `http://${proxy}`;
}

let loggedProxy: string = proxy;
try {
const parsedUrl = new URL(proxy);
if (parsedUrl.password) {
loggedProxy = proxy.replace(parsedUrl.password, "****");
}
} catch (e) {
this.logger.warn(`Fail to parse proxy url ${proxy}: ${e}`);
return undefined;
}

switch (protocol) {
case "http":
case "https":
this.logger.log(`Using HTTP/HTTPS proxy: ${proxy}`);
this.logger.log(`Using HTTP/HTTPS proxy: ${loggedProxy}`);
return new HttpsProxyAgent(proxy);
case "socks":
case "socks4":
case "socks4a":
case "socks5":
case "socks5h":
this.logger.log(`Using SOCKS proxy: ${proxy}`);
this.logger.log(`Using SOCKS proxy: ${loggedProxy}`);
return new SocksProxyAgent(proxy);
default:
this.logger.warn(`Unsupported proxy protocol: ${proxy}`);
this.logger.warn(`Unsupported proxy protocol: ${loggedProxy}`);
return undefined;
}
}
Expand Down

0 comments on commit ffcb42d

Please sign in to comment.