Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hide proxy password in server log #50

Merged
merged 6 commits into from
Feb 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading