Repository navigation
Conversation
|
The |
|
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. |
There was a problem hiding this comment.
🟢 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
Alan Zimmer (alzimmermsft)
left a comment
There was a problem hiding this comment.
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)? |
Description
Fixes #51341.
ProxyOptionsturns 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 affectssetNonProxyHosts,http.nonProxyHosts,http.proxy.non-proxy-hosts, andNO_PROXY, in bothazure-coreandclientcore.storage1*(storage.*?), matchesstorage2.example.com(storage1.*?)10.*(10.*?), matches100.64.0.1(10\..*?)192.168.(192\.16.*?), matches192.16.0.1(192\.168\..*?).example.com(.*?example\.com), matchesbadexample.com((?:.*?\.)?example\.com)[::1]([::1]), a character class that matches1but not[::1](\Q[::1]\E).*,.*?StringIndexOutOfBoundsException(.*?)azure-coreis 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, and2uses the fixed parser. The plan is to make2the default in a future release, keep1available for a while after that, and then remove it.fromConfigurationreads the setting from the configuration it's given, andsetNonProxyHostsreads it from the global configuration. The setting is documented in thesetNonProxyHostsJavaDoc and the CHANGELOG rather than added as a publicConfigurationconstant, since it's meant to go away.1is the released code, except that.*and.*?no longer throw. Compared withmainover 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.clientcoreisn't GA, so it uses the fixed parser unconditionally.The fixed parser changes:
*(and a?after it). A.before the wildcard stays as a literal dot, so10.*and192.168.only match hosts starting with10.and192.168.. This also removes the suffix branches that couldn't be reached..now matches the domain and its subdomains, like curl and Python do, so.example.commatchesexample.comandapi.example.combut notbadexample.com.[::1](part of the JDK's defaulthttp.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 toPattern.quote. Other entries are still compiled as regex, since thesetNonProxyHostsJavaDoc says they can contain regex characters.azure-core-http-vertxconverts the regex back into Vert.x's non-proxy host list. That conversion turns(10\..*?)into10*, which Vert.x compiles as10..*(matching100.64.0.1), and Vert.x compares entries without a wildcard case-sensitively. Version1keeps that conversion. With version2, the builder no longer sets the proxy onHttpClientOptions, since a request can't opt out of a proxy set there. Instead,VertxHttpClientmatches each request's host against the regex, the same way the other HTTP clients do, and callsRequestOptions.setProxyOptionsonly when the host should use the proxy. It reuses one Vert.xProxyOptionsinstance per client, so pooled connections are still shared. The builder learns which version built the regex through a new internal accessor,ProxyOptionsAccessHelper. Vert.xHttpClientOptionspassed tohttpClientOptionsare 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 version2through every entry point, and version1'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=trueon Vert.x 4.5.35: 672 tests, 0 failures, 1 skipped, and no Checkstyle, SpotBugs, or RevApi issues.update_versions.py --version-override vertx_5.2withVERSION_OVERRIDE_TESTS=true: 672 tests, 0 failures, 1 skipped.clientcoreis unchanged since the previous revision, wheremvn -f sdk/clientcore/core/pom.xml -Dtest=ProxyOptionsTests testpassed 103 tests.All SDK Contribution checklist:
General Guidelines and Best Practices
Testing Guidelines
Written with the help of Copilot