feat(proxy): mask proxy credentials in console and API output

Show user:pass as xxxxx:xxxxx in "Using ... Proxy" lines (full URI with -d), hide Basic provider hostnames, and redact proxy URIs in REST API error responses and remote session logs.
This commit is contained in:
imSp4rky
2026-08-31 09:45:19 -06:00
parent a01ff594da
commit 57ddefc69b
8 changed files with 81 additions and 48 deletions
+5 -1
View File
@@ -6,6 +6,7 @@ from requests.utils import prepend_scheme_if_needed
from urllib3.util import parse_url
from unshackle.core.proxies.proxy import Proxy
from unshackle.core.utils.redact import mask_proxy
class Basic(Proxy):
@@ -49,6 +50,9 @@ class Basic(Proxy):
proxy = prepend_scheme_if_needed(proxy, "http")
parsed_proxy = parse_url(proxy)
if not parsed_proxy.host:
raise ValueError(f"The proxy '{proxy}' is not a valid proxy URI supported by Python-Requests.")
raise ValueError(
f"The proxy '{mask_proxy(proxy, mask_host=True, allow_debug=False)}' "
"is not a valid proxy URI supported by Python-Requests."
)
return proxy
+10 -2
View File
@@ -9,6 +9,8 @@ import logging
import re
from typing import Any, List, Optional
from unshackle.core.utils.redact import mask_proxy
log = logging.getLogger("proxies")
@@ -85,13 +87,19 @@ def resolve_proxy(proxy: str, proxy_providers: List[Any]) -> Optional[str]:
proxy_uri = provider.get_proxy(query)
if not proxy_uri:
raise ValueError(f"Proxy provider {requested_provider} had no proxy for {query}")
log.info(f"Using {provider.__class__.__name__} Proxy: {proxy_uri}")
log.info(
f"Using {provider.__class__.__name__} Proxy: "
f"{mask_proxy(proxy_uri, provider.__class__.__name__ == 'Basic', allow_debug=False)}"
)
return proxy_uri
for provider in proxy_providers:
proxy_uri = provider.get_proxy(query)
if proxy_uri:
log.info(f"Using {provider.__class__.__name__} Proxy: {proxy_uri}")
log.info(
f"Using {provider.__class__.__name__} Proxy: "
f"{mask_proxy(proxy_uri, provider.__class__.__name__ == 'Basic', allow_debug=False)}"
)
return proxy_uri
raise ValueError(f"No proxy provider had a proxy for {proxy}")