Skip to content

fix: sanitize NO_PROXY env vars containing newline characters#3304

Open
JiwaniZakir wants to merge 1 commit into
openai:mainfrom
JiwaniZakir:fix/issue-3303
Open

fix: sanitize NO_PROXY env vars containing newline characters#3304
JiwaniZakir wants to merge 1 commit into
openai:mainfrom
JiwaniZakir:fix/issue-3303

Conversation

@JiwaniZakir
Copy link
Copy Markdown

When NO_PROXY or no_proxy contains newline characters (common in Docker and .env files), httpx fails with InvalidURL because 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 _DefaultHttpxClient and _DefaultAsyncHttpxClient. Tests cover both uppercase and lowercase variants.

Fixes #3303

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>
@JiwaniZakir JiwaniZakir requested a review from a team as a code owner May 24, 2026 04:03
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

InvalidURL error when NO_PROXY environment variable contains newline characters

1 participant