Skip to content

fix: sanitize NO_PROXY newlines#3305

Open
nightcityblade wants to merge 2 commits into
openai:mainfrom
nightcityblade:fix/issue-3303
Open

fix: sanitize NO_PROXY newlines#3305
nightcityblade wants to merge 2 commits into
openai:mainfrom
nightcityblade:fix/issue-3303

Conversation

@nightcityblade
Copy link
Copy Markdown

  • I understand that this repository is auto-generated and my pull request may not be merged

Changes being requested

Sanitize newline and carriage-return separators in NO_PROXY/no_proxy before constructing the SDK's default httpx clients, so Docker/.env-style multiline NO_PROXY values do not raise httpx.InvalidURL.

Fixes #3303

Additional context & links

Tests run:

  • uv run pytest -o addopts='' tests/test_client.py -k 'no_proxy_environment_variable_with_newlines or proxy_environment_variables'
  • uv run ruff check src/openai/_base_client.py tests/test_client.py
  • uv run pytest -o addopts='' tests/test_client.py

@nightcityblade nightcityblade requested a review from a team as a code owner May 24, 2026 15:08
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: 9ac1cd1640

ℹ️ 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".

Comment thread src/openai/_base_client.py Outdated
Comment on lines +829 to +830
if value is not None:
os.environ[key] = _sanitize_no_proxy(value)
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 Avoid mutating process env while constructing clients

Writing the sanitized value back into os.environ makes client construction mutate global process state, so creating one SDK client permanently rewrites NO_PROXY/no_proxy for all other code in the same process. This can cause hard-to-debug cross-library side effects (or racey behavior in multi-threaded apps) unrelated to this client instance; the sanitization should be scoped to the httpx initialization path rather than persisted globally.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks, fixed in a5d226f. The NO_PROXY/no_proxy cleanup is now scoped to the default httpx client proxy map construction instead of writing back to os.environ, and the tests assert the environment value remains unchanged.

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