-
Notifications
You must be signed in to change notification settings - Fork 5.1k
fix(client): sanitize newlines in proxy env vars before httpx sees them #3631
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -94,6 +94,15 @@ | |
|
|
||
| WORKLOAD_IDENTITY_API_KEY_PLACEHOLDER = "workload-identity-auth" | ||
|
|
||
| _PROXY_ENV_VARS = ("HTTP_PROXY", "HTTPS_PROXY", "NO_PROXY", "http_proxy", "https_proxy", "no_proxy") | ||
|
|
||
|
|
||
| def _sanitize_proxy_env_vars() -> None: | ||
| for key in _PROXY_ENV_VARS: | ||
| val = os.environ.get(key) | ||
| if val is not None and "\n" in val: | ||
| os.environ[key] = ",".join(p.strip() for p in val.splitlines() if p.strip()) | ||
|
Comment on lines
+103
to
+104
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a proxy value contains a lone Useful? React with 👍 / 👎. |
||
|
|
||
|
|
||
| def _has_header(headers: Headers, header: str) -> bool: | ||
| header = header.lower() | ||
|
|
@@ -262,6 +271,7 @@ def __init__( | |
| parsed[line[:colon].strip()] = line[colon + 1 :].strip() | ||
| default_headers = {**parsed, **(default_headers if is_mapping_t(default_headers) else {})} | ||
|
|
||
| _sanitize_proxy_env_vars() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When callers follow the documented Useful? React with 👍 / 👎. |
||
| super().__init__( | ||
| version=__version__, | ||
| base_url=base_url, | ||
|
|
@@ -868,6 +878,7 @@ def __init__( | |
| parsed[line[:colon].strip()] = line[colon + 1 :].strip() | ||
| default_headers = {**parsed, **(default_headers if is_mapping_t(default_headers) else {})} | ||
|
|
||
| _sanitize_proxy_env_vars() | ||
| super().__init__( | ||
| version=__version__, | ||
| base_url=base_url, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
ALL_PROXYorall_proxyis the configured fallback proxy and contains a trailing or embedded newline, it remains untouched and HTTPX2 still receives the invalid character during default client construction. The existing proxy tests explicitly clear both spellings because HTTPX2 recognizes them, so include them alongside the other supported proxy environment variables.Useful? React with 👍 / 👎.