Back to all posts
Keep Proxy Credentials Out of Logs and URLs

Keep Proxy Credentials Out of Logs and URLs

November 14, 2026

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.

Why proxy credentials leak so easily

The most common pattern is also the most convenient:

http://USERNAME:PASSWORD@GATEWAY_HOST:HTTP_PORT

That 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.

Debug 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.

Rotating 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.

Keep secrets out of command lines and URLs

For cURL, avoid -x http://USERNAME:PASSWORD@GATEWAY_HOST:HTTP_PORT. Use a config file with restrictive permissions:

# ~/.proxy-curl.conf
proxy = GATEWAY_HOST:HTTP_PORT
proxy-user = USERNAME:PASSWORD
chmod 600 ~/.proxy-curl.conf
curl --config ~/.proxy-curl.conf --silent --show-error \
  https://api.ipify.org?format=json

The config file keeps the credential out of shell history and out of the process list. For a SOCKS5 port, use the same file with:

proxy = socks5h://GATEWAY_HOST:SOCKS5_PORT
proxy-user = USERNAME:PASSWORD

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.

If 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.

A 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.

Build proxy URLs at runtime, then redact

In 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.

Python example:

import os
from urllib.parse import quote
import requests

user = quote(os.environ['PROXY_USER'], safe='')
password = quote(os.environ['PROXY_PASS'], safe='')
host = os.environ['GATEWAY_HOST']
port = os.environ['HTTP_PORT']
proxy_url = f'http://{user}:{password}@{host}:{port}'

def redact(text):
    return text.replace(f'{user}:{password}', '***:***')

session = requests.Session()
session.proxies = {'http': proxy_url, 'https': proxy_url}

try:
    response = session.get('https://api.ipify.org?format=json', timeout=20)
    response.raise_for_status()
    print(response.json())
except requests.RequestException as exc:
    print('request failed:', redact(str(exc)))

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.

For structured logging, add a filter at the handler level:

import logging

class SecretFilter(logging.Filter):
    def __init__(self, secrets):
        super().__init__()
        self.secrets = [s for s in secrets if s]

    def filter(self, record):
        message = record.getMessage()
        for secret in self.secrets:
            message = message.replace(secret, '***')
        record.msg = message
        record.args = ()
        return True

handler = logging.StreamHandler()
handler.addFilter(SecretFilter([f'{user}:{password}', password]))
logging.getLogger().addHandler(handler)

Attach 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.

Node.js pattern

The same idea works in Node.js. Use a well-known proxy agent, keep the URL in memory, and redact before printing:

const https = require('https');
const { HttpsProxyAgent } = require('https-proxy-agent');

const user = encodeURIComponent(process.env.PROXY_USER);
const pass = encodeURIComponent(process.env.PROXY_PASS);
const proxyUrl = `http://${user}:${pass}@${process.env.GATEWAY_HOST}:${process.env.HTTP_PORT}`;

function redact(text) {
  return text.replace(`${user}:${pass}`, '***:***');
}

const agent = new HttpsProxyAgent(proxyUrl);

https.get('https://api.ipify.org?format=json', { agent }, (res) => {
  let body = '';
  res.on('data', (chunk) => body += chunk);
  res.on('end', () => console.log(body));
}).on('error', (err) => {
  console.error('request failed:', redact(err.message));
});

Do 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.

CI and shell hygiene

CI is where secrets leak most often because the goal is visibility. A few rules:

  • Store proxy credentials as masked CI secrets, never as plain repository variables.
  • Avoid set -x around proxy setup. If you need tracing, turn it off before exporting credentials.
  • Do not echo the proxy URL, even partially. Print the host and port if you need to confirm configuration.
  • Keep test fixtures and snapshots free of real credentials. Use placeholders like USERNAME and PASSWORD.
  • Scrub artifacts. A failing test that dumps session.proxies will upload the secret.

A small pre-flight check in a shell script:

set +x
: "${PROXY_USER:?missing PROXY_USER}"
: "${PROXY_PASS:?missing PROXY_PASS}"
: "${GATEWAY_HOST:?missing GATEWAY_HOST}"
: "${HTTP_PORT:?missing HTTP_PORT}"

This fails fast without printing the values.

Detect accidental exposure

You 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.

If 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.

Conclusion

Proxy 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.