Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions sdk/clientcore/core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

### Bugs Fixed

- Fixed `ProxyOptions` suffix wildcards in non-proxy hosts dropping a literal character, causing unintended hosts
to bypass the proxy, and fixed an exception for the `.*` entry.

- Restricted JDK HTTP proxy credentials to authentication challenges from the configured proxy host and port,
preventing destination servers or other proxies from receiving them.
- Fixed HTTP timeout resolution to prefer explicit builder values, then builder-specific configuration, then global
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ public ProxyOptions setCredentials(String username, String password) {
* <p>
* The expected format of the passed string is a {@code '|'} delimited list of hosts which should bypass the proxy.
* Individual host strings may contain regex characters such as {@code '*'}.
* For example, {@code storage1*} bypasses the proxy for hosts beginning with {@code storage1}, and
* {@code 10.*} bypasses it for hosts beginning with {@code 10.} (the period is literal).
*
* @param nonProxyHosts Hosts that bypass the proxy.
* @return the updated ProxyOptions object
Expand Down Expand Up @@ -441,22 +443,16 @@ private static String sanitizeNonProxyHosts(String[] nonProxyHosts) {
*/
if (sanitizedNonProxyHost.endsWith(".")) {
suffixWildcard = ".*?";
sanitizedNonProxyHost = sanitizedNonProxyHost.substring(0, sanitizedNonProxyHost.length() - 2);
sanitizedNonProxyHost = sanitizedNonProxyHost.substring(0, sanitizedNonProxyHost.length() - 1);
} else if (sanitizedNonProxyHost.endsWith(".?")) {
suffixWildcard = ".*?";
sanitizedNonProxyHost = sanitizedNonProxyHost.substring(0, sanitizedNonProxyHost.length() - 3);
sanitizedNonProxyHost = sanitizedNonProxyHost.substring(0, sanitizedNonProxyHost.length() - 2);
} else if (sanitizedNonProxyHost.endsWith("*?")) {
suffixWildcard = ".*?";
sanitizedNonProxyHost = sanitizedNonProxyHost.substring(0, sanitizedNonProxyHost.length() - 3);
} else if (sanitizedNonProxyHost.endsWith("*")) {
suffixWildcard = ".*?";
sanitizedNonProxyHost = sanitizedNonProxyHost.substring(0, sanitizedNonProxyHost.length() - 2);
} else if (sanitizedNonProxyHost.endsWith(".*?")) {
suffixWildcard = ".*?";
sanitizedNonProxyHost = sanitizedNonProxyHost.substring(0, sanitizedNonProxyHost.length() - 4);
} else if (sanitizedNonProxyHost.endsWith(".*")) {
} else if (sanitizedNonProxyHost.endsWith("*")) {
suffixWildcard = ".*?";
sanitizedNonProxyHost = sanitizedNonProxyHost.substring(0, sanitizedNonProxyHost.length() - 3);
sanitizedNonProxyHost = sanitizedNonProxyHost.substring(0, sanitizedNonProxyHost.length() - 1);
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,47 @@ private static Stream<Arguments> nonProxyHostsSupplier() {
return argumentsList.stream();
}

@ParameterizedTest
@MethodSource("nonProxyHostSuffixSupplier")
@Execution(ExecutionMode.SAME_THREAD)
public void nonProxyHostSuffix(String entry, String host, boolean expected) {
ProxyOptions codeOptions
= new ProxyOptions(ProxyOptions.Type.HTTP, InetSocketAddress.createUnresolved("localhost", 7777))
.setNonProxyHosts(entry);
Configuration javaConfiguration = createJavaEnvConfiguration(7777, null, null, entry, false);
Configuration explicitConfiguration = createExplicitConfiguration(7777, null, null, entry);
Configuration environmentConfiguration
= setJavaSystemProxyPrerequisiteToTrue("http://localhost:7777", entry.replace('|', ','), true);

ProxyOptions[] options = new ProxyOptions[] {
codeOptions,
fromConfiguration(javaConfiguration),
fromConfiguration(explicitConfiguration),
fromConfiguration(environmentConfiguration) };
for (ProxyOptions option : options) {
Pattern pattern = compile(option.getNonProxyHosts(), Pattern.CASE_INSENSITIVE);
assertEquals(expected, pattern.matcher(host).matches(),
() -> String.format("Expected Pattern '%s' to match '%s': %s.", pattern.pattern(), host, expected));
}
}

private static Stream<Arguments> nonProxyHostSuffixSupplier() {
return Stream.of(Arguments.of("storage1*", "storage1.example.com", true),
Arguments.of("storage1*", "storage2.example.com", false), Arguments.of("10.*", "10.0.0.1", true),
Arguments.of("10.*", "100.64.0.1", false), Arguments.of("storage1*?", "storage1.example.com", true),
Arguments.of("storage1*?", "storage2.example.com", false),
Arguments.of("storage1.?", "storage1.example.com", true),
Arguments.of("storage1.?", "storage2.example.com", false), Arguments.of("192.168.", "192.168.0.1", true),
Arguments.of("192.168.", "192.16.0.1", false), Arguments.of("storage1.*", "storage1.example.com", true),
Arguments.of("storage1.*", "storage1other.example.com", false),
Arguments.of("storage1.*?", "storage1.example.com", true),
Arguments.of("storage1.*?", "storage1other.example.com", false), Arguments.of(".*", "example.com", true),
Arguments.of(".*?", "example.com", true), Arguments.of("*", "example.com", true),
Arguments.of("*?", "example.com", true), Arguments.of("a*", "abc", true), Arguments.of("a*", "bcd", false),
Arguments.of("storage1*|10.*", "storage2.example.com", false),
Arguments.of("storage1*|10.*", "10.0.0.1", true));
}

@Test
public void sanitizeNoProxyDoesNotSplitEscapedCommas() {
String noProxy = "noproxy\\,withescapedcomma";
Expand Down
3 changes: 3 additions & 0 deletions sdk/core/azure-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

### Bugs Fixed

- Fixed `ProxyOptions` suffix wildcards in non-proxy hosts dropping a literal character, causing unintended hosts
to bypass the proxy, and fixed an exception for the `.*` entry.

- Fixed `RetryPolicy` synchronous retry backoff not restoring the thread's interrupt status after catching
`InterruptedException`, which caused callers to silently lose the interruption signal.
- Fixed `FluxUtil.toFluxByteBuffer` emitting each partial read backed by an array of the full chunk size, which caused
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ public ProxyOptions setCredentials(String username, String password) {
* <p>
* The expected format of the passed string is a {@code '|'} delimited list of hosts which should bypass the proxy.
* Individual host strings may contain regex characters such as {@code '*'}.
* For example, {@code storage1*} bypasses the proxy for hosts beginning with {@code storage1}, and
* {@code 10.*} bypasses it for hosts beginning with {@code 10.} (the period is literal).
*
* @param nonProxyHosts Hosts that bypass the proxy.
* @return the updated ProxyOptions object
Expand Down Expand Up @@ -454,22 +456,16 @@ private static String sanitizeNonProxyHosts(String[] nonProxyHosts) {
*/
if (sanitizedNonProxyHost.endsWith(".")) {
suffixWildcard = ".*?";
sanitizedNonProxyHost = sanitizedNonProxyHost.substring(0, sanitizedNonProxyHost.length() - 2);
sanitizedNonProxyHost = sanitizedNonProxyHost.substring(0, sanitizedNonProxyHost.length() - 1);
} else if (sanitizedNonProxyHost.endsWith(".?")) {
suffixWildcard = ".*?";
sanitizedNonProxyHost = sanitizedNonProxyHost.substring(0, sanitizedNonProxyHost.length() - 3);
sanitizedNonProxyHost = sanitizedNonProxyHost.substring(0, sanitizedNonProxyHost.length() - 2);
} else if (sanitizedNonProxyHost.endsWith("*?")) {
suffixWildcard = ".*?";
sanitizedNonProxyHost = sanitizedNonProxyHost.substring(0, sanitizedNonProxyHost.length() - 3);
} else if (sanitizedNonProxyHost.endsWith("*")) {
suffixWildcard = ".*?";
sanitizedNonProxyHost = sanitizedNonProxyHost.substring(0, sanitizedNonProxyHost.length() - 2);
} else if (sanitizedNonProxyHost.endsWith(".*?")) {
suffixWildcard = ".*?";
sanitizedNonProxyHost = sanitizedNonProxyHost.substring(0, sanitizedNonProxyHost.length() - 4);
} else if (sanitizedNonProxyHost.endsWith(".*")) {
} else if (sanitizedNonProxyHost.endsWith("*")) {
suffixWildcard = ".*?";
sanitizedNonProxyHost = sanitizedNonProxyHost.substring(0, sanitizedNonProxyHost.length() - 3);
sanitizedNonProxyHost = sanitizedNonProxyHost.substring(0, sanitizedNonProxyHost.length() - 1);
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,47 @@ private static Stream<Arguments> nonProxyHostsSupplier() {
return argumentsList.stream();
}

@ParameterizedTest
@MethodSource("nonProxyHostSuffixSupplier")
@Execution(ExecutionMode.SAME_THREAD)
public void nonProxyHostSuffix(String entry, String host, boolean expected) {
ProxyOptions codeOptions
= new ProxyOptions(ProxyOptions.Type.HTTP, InetSocketAddress.createUnresolved("localhost", 7777))
.setNonProxyHosts(entry);
Configuration javaConfiguration = createJavaEnvConfiguration(null, null, entry, false);
Configuration explicitConfiguration = createExplicitConfiguration(null, null, entry);
Configuration environmentConfiguration
= setJavaSystemProxyPrerequisiteToTrue("http://localhost:7777", entry.replace('|', ','), true);

ProxyOptions[] options = new ProxyOptions[] {
codeOptions,
fromConfiguration(javaConfiguration),
fromConfiguration(explicitConfiguration),
fromConfiguration(environmentConfiguration) };
for (ProxyOptions option : options) {
Pattern pattern = compile(option.getNonProxyHosts(), Pattern.CASE_INSENSITIVE);
assertEquals(expected, pattern.matcher(host).matches(),
() -> String.format("Expected Pattern '%s' to match '%s': %s.", pattern.pattern(), host, expected));
}
}

private static Stream<Arguments> nonProxyHostSuffixSupplier() {
return Stream.of(Arguments.of("storage1*", "storage1.example.com", true),
Arguments.of("storage1*", "storage2.example.com", false), Arguments.of("10.*", "10.0.0.1", true),
Arguments.of("10.*", "100.64.0.1", false), Arguments.of("storage1*?", "storage1.example.com", true),
Arguments.of("storage1*?", "storage2.example.com", false),
Arguments.of("storage1.?", "storage1.example.com", true),
Arguments.of("storage1.?", "storage2.example.com", false), Arguments.of("192.168.", "192.168.0.1", true),
Arguments.of("192.168.", "192.16.0.1", false), Arguments.of("storage1.*", "storage1.example.com", true),
Arguments.of("storage1.*", "storage1other.example.com", false),
Arguments.of("storage1.*?", "storage1.example.com", true),
Arguments.of("storage1.*?", "storage1other.example.com", false), Arguments.of(".*", "example.com", true),
Arguments.of(".*?", "example.com", true), Arguments.of("*", "example.com", true),
Arguments.of("*?", "example.com", true), Arguments.of("a*", "abc", true), Arguments.of("a*", "bcd", false),
Arguments.of("storage1*|10.*", "storage2.example.com", false),
Arguments.of("storage1*|10.*", "10.0.0.1", true));
}

@Test
public void sanitizeNoProxyDoesNotSplitEscapedCommas() {
String noProxy = "noproxy\\,withescapedcomma";
Expand Down
Loading