[{"data":1,"prerenderedAt":36},["ShallowReactive",2],{"blog:post:en:keep-proxy-credentials-out-of-logs-and-urls":3,"blog:related:en:keep-proxy-credentials-out-of-logs-and-urls":23},{"slug":4,"lang":5,"title":6,"summary":7,"date":8,"tags":9,"tag_slugs":15,"thumbnail_url":16,"translations":17,"body":18,"asset_base":19,"checksum":20,"published_at":21,"content_updated_at":22},"keep-proxy-credentials-out-of-logs-and-urls","en","Keep Proxy Credentials Out of Logs and URLs","Proxy credentials leak through URLs, debug logs, and shell history. Learn concrete patterns to keep them out of Python, Node.js, cURL, and CI.","2026-11-14",[10,11,12,13,14],"security","proxy-configuration","python","curl","nodejs",[10,11,12,13,14],"https://blog-api.ro-proxy.com/api/blog/posts/keep-proxy-credentials-out-of-logs-and-urls/thumbnail.svg?lang=en",[5],"Proxy credentials are not just another environment variable. They are the keys to an exit IP, and they often travel through places that were never designed to keep secrets: URLs, debug logs, shell history, CI output, and error trackers. A leaked proxy username and password can let someone else burn your bandwidth, trigger blocks against your account, or blend abusive traffic into your automation. The fix is not one setting. It is a small set of habits applied everywhere a proxy is configured.\n\n## Why proxy credentials leak so easily\n\nThe most common pattern is also the most convenient:\n\n`http://USERNAME:PASSWORD@GATEWAY_HOST:HTTP_PORT`\n\nThat string is easy to paste into a script, a cURL command, or a browser setting. It is also easy to copy into an exception message. Many HTTP libraries include the request URL in errors. APM tools capture URLs. Shell history captures command lines. Process listings can expose arguments. CI logs capture everything unless you mask it.\n\nDebug logging makes the problem worse. HTTP clients often log request headers at debug level, including `Proxy-Authorization`. A single verbose run in staging can put a working credential into a log aggregation system with a long retention period.\n\nRotating proxies add scale. If every proxy has its own username and password, one leaked line exposes one proxy, not the whole pool. That is better than a shared secret, but it is still enough for someone to abuse that exit IP. Treat every proxy credential as a password, because that is what it is.\n\n## Keep secrets out of command lines and URLs\n\nFor cURL, avoid `-x http://USERNAME:PASSWORD@GATEWAY_HOST:HTTP_PORT`. Use a config file with restrictive permissions:\n\n```bash\n# ~/.proxy-curl.conf\nproxy = GATEWAY_HOST:HTTP_PORT\nproxy-user = USERNAME:PASSWORD\n```\n\n```bash\nchmod 600 ~/.proxy-curl.conf\ncurl --config ~/.proxy-curl.conf --silent --show-error \\\n  https://api.ipify.org?format=json\n```\n\nThe config file keeps the credential out of shell history and out of the process list. For a SOCKS5 port, use the same file with:\n\n```bash\nproxy = socks5h://GATEWAY_HOST:SOCKS5_PORT\nproxy-user = USERNAME:PASSWORD\n```\n\n`socks5h` asks the proxy to resolve DNS, which avoids a local DNS lookup leaking the destination. If you need HTTP and HTTPS through the same HTTP port, the first config is enough; cURL will use `CONNECT` for HTTPS.\n\nIf you are configuring a RoProxy proxy, use `GATEWAY_HOST` with `HTTP_PORT` for both HTTP and HTTPS; Pro and Business plans also provide `SOCKS5_PORT`.\n\nA quick check: `ps aux | grep curl` should not show your password. `history | grep proxy` should not show it either. If either does, stop using that credential and clean the history.\n\n## Build proxy URLs at runtime, then redact\n\nIn application code, read credentials from environment variables or a secret manager. Build the proxy URL at runtime. Never commit it. When you log an error, redact the userinfo section before it reaches the logger.\n\nPython example:\n\n```python\nimport os\nfrom urllib.parse import quote\nimport requests\n\nuser = quote(os.environ['PROXY_USER'], safe='')\npassword = quote(os.environ['PROXY_PASS'], safe='')\nhost = os.environ['GATEWAY_HOST']\nport = os.environ['HTTP_PORT']\nproxy_url = f'http://{user}:{password}@{host}:{port}'\n\ndef redact(text):\n    return text.replace(f'{user}:{password}', '***:***')\n\nsession = requests.Session()\nsession.proxies = {'http': proxy_url, 'https': proxy_url}\n\ntry:\n    response = session.get('https://api.ipify.org?format=json', timeout=20)\n    response.raise_for_status()\n    print(response.json())\nexcept requests.RequestException as exc:\n    print('request failed:', redact(str(exc)))\n```\n\n`quote` matters. A password containing `@`, `:`, or `/` will break the URL if you do not encode it. The redaction function is deliberately narrow: it removes the exact credential pair, not every `@` character.\n\nFor structured logging, add a filter at the handler level:\n\n```python\nimport logging\n\nclass SecretFilter(logging.Filter):\n    def __init__(self, secrets):\n        super().__init__()\n        self.secrets = [s for s in secrets if s]\n\n    def filter(self, record):\n        message = record.getMessage()\n        for secret in self.secrets:\n            message = message.replace(secret, '***')\n        record.msg = message\n        record.args = ()\n        return True\n\nhandler = logging.StreamHandler()\nhandler.addFilter(SecretFilter([f'{user}:{password}', password]))\nlogging.getLogger().addHandler(handler)\n```\n\nAttach the filter to handlers, not just to one logger. A child logger can propagate a record to a parent handler, and the handler filter catches it.\n\n## Node.js pattern\n\nThe same idea works in Node.js. Use a well-known proxy agent, keep the URL in memory, and redact before printing:\n\n```js\nconst https = require('https');\nconst { HttpsProxyAgent } = require('https-proxy-agent');\n\nconst user = encodeURIComponent(process.env.PROXY_USER);\nconst pass = encodeURIComponent(process.env.PROXY_PASS);\nconst proxyUrl = `http://${user}:${pass}@${process.env.GATEWAY_HOST}:${process.env.HTTP_PORT}`;\n\nfunction redact(text) {\n  return text.replace(`${user}:${pass}`, '***:***');\n}\n\nconst agent = new HttpsProxyAgent(proxyUrl);\n\nhttps.get('https://api.ipify.org?format=json', { agent }, (res) => {\n  let body = '';\n  res.on('data', (chunk) => body += chunk);\n  res.on('end', () => console.log(body));\n}).on('error', (err) => {\n  console.error('request failed:', redact(err.message));\n});\n```\n\nDo not pass the proxy URL to a generic logger, a crash reporter, or a test snapshot. If a library logs the agent options, wrap or disable that logging in production. In development, use a temporary credential and keep retention short.\n\n## CI and shell hygiene\n\nCI is where secrets leak most often because the goal is visibility. A few rules:\n\n- Store proxy credentials as masked CI secrets, never as plain repository variables.\n- Avoid `set -x` around proxy setup. If you need tracing, turn it off before exporting credentials.\n- Do not echo the proxy URL, even partially. Print the host and port if you need to confirm configuration.\n- Keep test fixtures and snapshots free of real credentials. Use placeholders like `USERNAME` and `PASSWORD`.\n- Scrub artifacts. A failing test that dumps `session.proxies` will upload the secret.\n\nA small pre-flight check in a shell script:\n\n```bash\nset +x\n: \"${PROXY_USER:?missing PROXY_USER}\"\n: \"${PROXY_PASS:?missing PROXY_PASS}\"\n: \"${GATEWAY_HOST:?missing GATEWAY_HOST}\"\n: \"${HTTP_PORT:?missing HTTP_PORT}\"\n```\n\nThis fails fast without printing the values.\n\n## Detect accidental exposure\n\nYou cannot redact what you do not know about. Add a log scan for the userinfo pattern `://...@` in application logs and CI output. In error tracking, configure scrubbing for `Authorization`, `Proxy-Authorization`, and URL userinfo. In browser automation, remember that proxy settings may be stored in a profile directory; do not commit that directory.\n\nIf a credential does appear in a log, treat it as compromised. Remove that proxy from automation, stop using the credential, and review where the log was shipped. A single leaked proxy credential is not a catastrophe, but reusing it after exposure is.\n\n## Conclusion\n\nProxy credential hygiene is mostly about removing convenience shortcuts. Use config files or secret managers instead of inline URLs. Build proxy URLs at runtime, URL-encode the username and password, and redact before logging. Keep debug logs off in production and mask secrets in CI. If you use RoProxy, each proxy has its own username and password, so apply these habits per proxy rather than assuming one shared secret covers the pool. Check the exit IP with `https://api.ipify.org?format=json` after configuration, and verify that neither the command line nor the logs expose the credential.\n","https://blog-api.ro-proxy.com/api/blog/posts/keep-proxy-credentials-out-of-logs-and-urls/assets","65157db512cfe24c80966f313b121fe36484d9b58bffe06d42c97027306bd8b2","2026-11-14T01:05:57.287708Z","2026-11-14T01:05:57.288957Z",[24,28,32],{"slug":25,"title":26,"summary":27},"configuring-rotating-proxies-nextjs-ssr-fetching","Configuring Rotating Proxies for Next.js SSR Fetching","Learn how to route Next.js server‑side data fetching through rotating proxies, handle authentication, and rotate IPs on demand using the RoProxy API.",{"slug":29,"title":30,"summary":31},"diagnose-http-502-forward-proxy","How to Diagnose HTTP 502 Errors Behind a Forward Proxy","Trace the CONNECT tunnel, TLS handshake, and HTTP response to separate proxy-generated 502s from origin failures, then isolate, retry, and escalate the real cause.",{"slug":33,"title":34,"summary":35},"testing-http3-quic-with-proxies","Testing HTTP/3 (QUIC) Connectivity Through Proxies","Learn how to verify HTTP/3 support and graceful fallback to HTTP/1.1 by routing client traffic through proxies, capturing packets, and measuring latency for reliable API performance testing.",1794816128102]