Skip to content

Treat *.example.com in NO_PROXY like .example.com - #1277

Open
RaphaelFakhri wants to merge 1 commit into
pydantic:mainfrom
RaphaelFakhri:fix-no-proxy-wildcard-subdomain
Open

RaphaelFakhri wants to merge 1 commit into
pydantic:mainfrom
RaphaelFakhri:fix-no-proxy-wildcard-subdomain

Conversation

@RaphaelFakhri

@RaphaelFakhri RaphaelFakhri commented Oct 19, 2026 •

Copy link
Copy Markdown

Summary

A NO_PROXY entry such as *.example.com never matches. get_environment_proxies() prepends * to plain hostnames, which turns the entry into all://**.example.com, and URLPattern compiles that to ^(.+\.)?\*\.example\.com$. Requests to www.example.com still go through the proxy.

This change maps a leading *. to the same mount key as a leading . (all://*.example.com), so the entry matches subdomains of example.com. Go's net/http handles *. the same way.

Checklist

  • I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.

Fixes #1276

View guided diff

@codspeed

codspeed Bot commented Oct 19, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 17 untouched benchmarks
⏩ 7 skipped benchmarks1


Comparing RaphaelFakhri:fix-no-proxy-wildcard-subdomain (afb7c9b) with main (5b26c25)

Open in CodSpeed

Footnotes

  1. 7 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

1 issue found across 3 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/httpx2/httpx2/_utils.py">

<violation number="1" location="src/httpx2/httpx2/_utils.py:78">
P2: This branch accepts slash-bearing wildcard entries such as `NO_PROXY=*.example.com/path`, then `URLPattern` ignores the path and bypasses the proxy for the entire wildcard domain. Keep the existing slash guard on this branch so malformed non-CIDR entries are ignored while wildcard ports remain supported.</violation>
</file>

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

mounts[f"all://{hostname}"] = None
elif hostname.startswith("["):
mounts[f"all://{hostname}"] = None
elif hostname.startswith("*."):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2: This branch accepts slash-bearing wildcard entries such as NO_PROXY=*.example.com/path, then URLPattern ignores the path and bypasses the proxy for the entire wildcard domain. Keep the existing slash guard on this branch so malformed non-CIDR entries are ignored while wildcard ports remain supported.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At src/httpx2/httpx2/_utils.py, line 78:

<comment>This branch accepts slash-bearing wildcard entries such as `NO_PROXY=*.example.com/path`, then `URLPattern` ignores the path and bypasses the proxy for the entire wildcard domain. Keep the existing slash guard on this branch so malformed non-CIDR entries are ignored while wildcard ports remain supported.</comment>

<file context>
@@ -75,6 +75,9 @@ def get_environment_proxies() -> dict[str, str | None]:
                 mounts[f"all://{hostname}"] = None
             elif hostname.startswith("["):
                 mounts[f"all://{hostname}"] = None
+            elif hostname.startswith("*."):
+                # NO_PROXY=*.google.com is treated like .google.com
+                mounts[f"all://{hostname}"] = None
</file context>
Suggested change
elif hostname.startswith("*."):
elif hostname.startswith("*.") and "/" not in hostname:

This branch has not been deployed

No deployments
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.

*.example.com in NO_PROXY never bypasses the proxy

1 participant