Skip to content

Fix non-proxy hosts matching unintended hosts - #51356

Open
vcolin7 wants to merge 2 commits into
mainfrom
vcolin7-fix-non-proxy-host-wildcards
Open

vcolin7 wants to merge 2 commits into
mainfrom
vcolin7-fix-non-proxy-host-wildcards

Conversation

@vcolin7

@vcolin7 vcolin7 commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Description

Fixes #51341.

ProxyOptions turns non-proxy hosts into a regex that the HTTP clients match against each request's host. Several entry forms produced a regex that matched hosts they shouldn't, so requests that should have gone through the proxy connected directly instead. On networks that only allow outbound traffic through the proxy, those requests fail. This affects setNonProxyHosts, http.nonProxyHosts, http.proxy.non-proxy-hosts, and NO_PROXY, in both azure-core and clientcore.

Entry Current Fixed
storage1* (storage.*?), matches storage2.example.com (storage1.*?)
10.* (10.*?), matches 100.64.0.1 (10\..*?)
192.168. (192\.16.*?), matches 192.16.0.1 (192\.168\..*?)
.example.com (.*?example\.com), matches badexample.com ((?:.*?\.)?example\.com)
[::1] ([::1]), a character class that matches 1 but not [::1] (\Q[::1]\E)
.*, .*? Throws StringIndexOutOfBoundsException (.*?)

azure-core is GA, and some setups may work today because of the over-matching, so the fixed parser is opt-in there:

  • AZURE_NON_PROXY_PARSER_VERSION, set as an environment variable or system property, selects the parser. 1, the default, keeps the current behavior, and 2 uses the fixed parser. The plan is to make 2 the default in a future release, keep 1 available for a while after that, and then remove it.
  • fromConfiguration reads the setting from the configuration it's given, and setNonProxyHosts reads it from the global configuration. The setting is documented in the setNonProxyHosts JavaDoc and the CHANGELOG rather than added as a public Configuration constant, since it's meant to go away.
  • Version 1 is the released code, except that .* and .*? no longer throw. Compared with main over every entry of up to six characters built from ., *, ?, a, 1, [, ], : and \ (about 600,000 entries), its output is identical for every entry that didn't throw before, and none throw now.

clientcore isn't GA, so it uses the fixed parser unconditionally.

The fixed parser changes:

  • Suffix wildcards now remove only the * (and a ? after it). A . before the wildcard stays as a literal dot, so 10.* and 192.168. only match hosts starting with 10. and 192.168.. This also removes the suffix branches that couldn't be reached.
  • A leading . now matches the domain and its subdomains, like curl and Python do, so .example.com matches example.com and api.example.com but not badexample.com.
  • Bracketed IPv6 literals such as [::1] (part of the JDK's default http.nonProxyHosts) are now matched literally. This is also needed for the suffix fix: [2001:db8::1]* only works today because the extra character removed makes the regex invalid, so the code falls back to Pattern.quote. Other entries are still compiled as regex, since the setNonProxyHosts JavaDoc says they can contain regex characters.

azure-core-http-vertx converts the regex back into Vert.x's non-proxy host list. That conversion turns (10\..*?) into 10*, which Vert.x compiles as 10..* (matching 100.64.0.1), and Vert.x compares entries without a wildcard case-sensitively. Version 1 keeps that conversion. With version 2, the builder no longer sets the proxy on HttpClientOptions, since a request can't opt out of a proxy set there. Instead, VertxHttpClient matches each request's host against the regex, the same way the other HTTP clients do, and calls RequestOptions.setProxyOptions only when the host should use the proxy. It reuses one Vert.x ProxyOptions instance per client, so pooled connections are still shared. The builder learns which version built the regex through a new internal accessor, ProxyOptionsAccessHelper. Vert.x HttpClientOptions passed to httpClientOptions are still used as-is.

Out of scope: unbracketed IPv6 hosts as seen by Netty, CIDR and port entries in NO_PROXY, and rewriting the sanitizer as strict glob matching.

#51347 fixes the suffix offsets. This PR also covers the trailing and leading dot, IPv6, and Vert.x cases found while reviewing it.

Validation:

  • mvn -f sdk/core/azure-core/pom.xml -Dtest=ProxyOptionsTests test: 112 tests passed. They cover version 2 through every entry point, and version 1's exact regexes when the setting is unset, 1, or unknown.
  • mvn -f sdk/core/azure-core/pom.xml install -DskipTests -Djacoco.skip=true: no Checkstyle, SpotBugs, or RevApi issues.
  • mvn -f sdk/core/azure-core-http-vertx/pom.xml verify -Djacoco.skip=true on Vert.x 4.5.35: 672 tests, 0 failures, 1 skipped, and no Checkstyle, SpotBugs, or RevApi issues.
  • The same tests on Vert.x 5.2.0, through update_versions.py --version-override vertx_5.2 with VERSION_OVERRIDE_TESTS=true: 672 tests, 0 failures, 1 skipped.
  • clientcore is unchanged since the previous revision, where mvn -f sdk/clientcore/core/pom.xml -Dtest=ProxyOptionsTests test passed 103 tests.

All SDK Contribution checklist:

  • The pull request does not introduce [breaking changes]
  • CHANGELOG is updated for new features, bug fixes or other significant changes.
  • I have read the contribution guidelines.

General Guidelines and Best Practices

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

Written with the help of Copilot

@azure-sdk-automation

Copy link
Copy Markdown
Contributor

The sdk-api-review-ready label cannot create reviews for this working PR because it affects multiple SDK packages. Use the Azure SDK CLI (azsdk apireview create) to create a review for each package.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
34 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@vcolin7 vcolin7 assigned vcolin7 and unassigned vcolin7 Nov 20, 2026
@vcolin7
vcolin7 marked this pull request as ready for review November 20, 2026 23:09
Copilot AI balanced review requested due to automatic review settings November 20, 2026 23:09

Copilot AI 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.

🟢 Approval recommended

No active review issues remain for the non-proxy host matching fixes and per-request Vert.x proxy selection changes.

No open issues 🎉

What changed in this PR

Fixes #51341 by correcting non-proxy host matching in Azure Core and Client Core, preventing unintended hosts from bypassing the proxy. The Vert.x transport now applies the same matching rules per request.

Changes:

  • Correct wildcard trimming, domain-boundary matching, and bracketed IPv6 handling.
  • Replace Vert.x’s non-proxy list conversion with case-insensitive regex matching per request.
  • Add regression tests and update JavaDoc and release notes.
File Description
sdk/​core/​azure-core/​src/​test/​java/​com/​azure/​core/​http/​ProxyOptionsTests.java Tests intended host matching across configuration sources.
sdk/​core/​azure-core/​src/​main/​java/​com/​azure/​core/​http/​ProxyOptions.java Fixes host sanitization and documents supported forms.
sdk/​core/​azure-core/​CHANGELOG.md Records non-proxy host matching fixes.
sdk/​core/​azure-core-http-vertx/​src/​test/​java/​com/​azure/​core/​http/​vertx/​VertxHttpClientProviderTests.java Updates assertions for per-request proxy selection.
sdk/​core/​azure-core-http-vertx/​src/​test/​java/​com/​azure/​core/​http/​vertx/​VertxHttpClientBuilderTests.java Tests proxy selection and direct versus proxied connections.
sdk/​core/​azure-core-http-vertx/​src/​main/​java/​com/​azure/​core/​http/​vertx/​VertxHttpClientBuilder.java Prepares proxy settings and regex without converting to Vert.x host lists.
sdk/​core/​azure-core-http-vertx/​src/​main/​java/​com/​azure/​core/​http/​vertx/​VertxHttpClient.java Selects the proxy for each request using host matching.
sdk/​core/​azure-core-http-vertx/​CHANGELOG.md Documents corrected Vert.x proxy routing.
sdk/​clientcore/​core/​src/​test/​java/​io/​clientcore/​core/​http/​models/​ProxyOptionsTests.java Adds equivalent Client Core matching regression tests.
sdk/​clientcore/​core/​src/​main/​java/​io/​clientcore/​core/​http/​models/​ProxyOptions.java Applies matching fixes and JavaDoc updates to Client Core.
sdk/​clientcore/​core/​CHANGELOG.md Records Client Core non-proxy host fixes.

Review effort: Balanced

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approval on the ClientCore changes as those aren't GA, so this breaking change is fine.

For Core though, I would think about having a configuration property / environment variable which configures controlling whether the old or new behavior is used. This way we don't break code that works because the slightly incorrect behavior, while also allowing those broken by the current behavior to work.

Let's make something like AZURE_NON_PROXY_PARSER_VERSION where the old behavior can be 1 and the new behavior be 2, defaulting to 1 for now.

@vcolin7

vcolin7 commented Nov 24, 2026 •

Copy link
Copy Markdown
Member Author

Approval on the ClientCore changes as those aren't GA, so this breaking change is fine.

For Core though, I would think about having a configuration property / environment variable which configures controlling whether the old or new behavior is used. This way we don't break code that works because the slightly incorrect behavior, while also allowing those broken by the current behavior to work.

Let's make something like AZURE_NON_PROXY_PARSER_VERSION where the old behavior can be 1 and the new behavior be 2, defaulting to 1 for now.

I don't know how I feel about introducing versioning to something like this. On the one hand, I understand that we may have users that rely on the old behavior that could be broken by these changes (bad, we don't want that) and on the other hand, we would be letting all old and new users send traffic to undesired addresses. Adding versioning would be yet another thing to keep track of while also keeping an incorrect behavior around for who knows how long.

I can reconcile doing it if we introduce it as a step to eventually change the default to the new correct mode with clear messaging and over a lengthy but finite period of time. Having "old mode" be the default for a while and then turning on "new mode" while still allowing users to use "old mode" for a while to eventually get rid of it altogether and just use "new mode". This would be much like how we handle deprecation in our public APIs.

What do you think Alan Zimmer (@alzimmermsft)?

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] ProxyOptions: suffix wildcards in non-proxy hosts strip one character too many (storage1* also matches storage2.example.com)

3 participants