Skip to content

Commit 3fe6bf7

Browse files
committed
Addressed review comments
1 parent 9915555 commit 3fe6bf7

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed
Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +0,0 @@
1-
{
2-
"category": "Amazon Elastic Container Service (ECS)",
3-
"contributor": "",
4-
"type": "bugfix",
5-
"description": "HTTP(S) credential provider requires the implementation to verify that the resolved addresses for the host are actually loopback addresses."
6-
}

core/auth/src/main/java/software/amazon/awssdk/auth/credentials/ContainerCredentialsProvider.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package software.amazon.awssdk.auth.credentials;
1717

1818
import java.io.IOException;
19-
import java.net.Inet6Address;
2019
import java.net.InetAddress;
2120
import java.net.URI;
2221
import java.net.UnknownHostException;
@@ -66,8 +65,8 @@
6665
public final class ContainerCredentialsProvider
6766
implements HttpCredentialsProvider,
6867
ToCopyableBuilder<ContainerCredentialsProvider.Builder, ContainerCredentialsProvider> {
69-
private static final Predicate<InetAddress> ALLOWED_HOSTS_IPv4_RULES = InetAddress::isLoopbackAddress;
70-
private static final Predicate<InetAddress> ALLOWED_HOSTS_IPv6_RULES = InetAddress::isLoopbackAddress;
68+
private static final Predicate<InetAddress> IS_LOOPBACK_ADDRESS = InetAddress::isLoopbackAddress;
69+
private static final Predicate<InetAddress> ALLOWED_HOSTS_RULES = IS_LOOPBACK_ADDRESS;
7170
private static final String HTTPS = "https";
7271

7372
private final String endpoint;
@@ -226,6 +225,15 @@ private boolean isHttps(URI endpoint) {
226225
return Objects.equals(HTTPS, endpoint.getScheme());
227226
}
228227

228+
/**
229+
* Determines if the addresses for a given host are resolved to a loopback address.
230+
* <p>
231+
* This is a best-effort in determining what address a host will be resolved to. DNS caching might be disabled,
232+
* or could expire between this check and when the API is invoked.
233+
* </p>
234+
* @param host The name or IP address of the host.
235+
* @return A boolean specifying whether the host is allowed as an endpoint for credentials loading.
236+
*/
229237
private boolean isAllowedHost(String host) {
230238
try {
231239
InetAddress[] addresses = InetAddress.getAllByName(host);
@@ -242,11 +250,7 @@ private boolean isAllowedHost(String host) {
242250
}
243251

244252
private boolean matchesAllowedHostRules(InetAddress inetAddress) {
245-
if (inetAddress instanceof Inet6Address) {
246-
return ALLOWED_HOSTS_IPv6_RULES.test(inetAddress);
247-
}
248-
249-
return ALLOWED_HOSTS_IPv4_RULES.test(inetAddress);
253+
return ALLOWED_HOSTS_RULES.test(inetAddress);
250254
}
251255
}
252256

0 commit comments

Comments
 (0)