fix: sanitize NO_PROXY env vars containing newline characters#3304
fix: sanitize NO_PROXY env vars containing newline characters#3304JiwaniZakir wants to merge 1 commit into
Conversation
Newlines in NO_PROXY/no_proxy (common in Docker/.env files) cause httpx.InvalidURL when the client is initialized. Strip and rejoin entries before httpx reads the environment. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e1663abe4a
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| kwargs.setdefault("timeout", DEFAULT_TIMEOUT) | ||
| kwargs.setdefault("limits", DEFAULT_CONNECTION_LIMITS) | ||
| kwargs.setdefault("follow_redirects", True) | ||
| _sanitize_proxy_env_vars() |
There was a problem hiding this comment.
Skip NO_PROXY sanitization when trust_env is false
Calling _sanitize_proxy_env_vars() unconditionally in DefaultHttpxClient mutates process-wide environment variables even when the caller passes trust_env=False, which is supposed to disable environment-based proxy behavior. In that scenario, creating an SDK client still rewrites NO_PROXY/no_proxy for the entire process, potentially changing proxy behavior for other libraries or later subprocesses that read the same env vars. Gate this sanitization on kwargs.get("trust_env", True) (and similarly for async) to avoid unexpected global side effects.
Useful? React with 👍 / 👎.
When
NO_PROXYorno_proxycontains newline characters (common in Docker and.envfiles), httpx fails withInvalidURLbecause it doesn't split on newlines when parsing the env var.This adds a
_sanitize_proxy_env_vars()helper that normalizes newlines to commas before the httpx client is instantiated in_DefaultHttpxClientand_DefaultAsyncHttpxClient. Tests cover both uppercase and lowercase variants.Fixes #3303