-
Notifications
You must be signed in to change notification settings - Fork 910
Validate that localhost resolves to loopback address #3672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a similar change we need to make for IMDS?
{ | ||
"category": "Amazon Elastic Container Service (ECS)", | ||
"contributor": "", | ||
"type": "bugfix", | ||
"description": "HTTP(S) credential provider requires the implementation to verify that the resolved addresses for the host are actually loopback addresses." | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably don't want a changelog entry for this one, since it's security-related. Otherwise we'd want to talk with security about wording.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will remove.
if (inetAddress instanceof Inet6Address) { | ||
return ALLOWED_HOSTS_IPv6_RULES.test(inetAddress); | ||
} | ||
|
||
return ALLOWED_HOSTS_IPv4_RULES.test(inetAddress); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since these are the same predicate, can we simplify this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Merged into a single constant. If later on, there is a need to differentiate between IPv4 and IPv6 we can create separate constants.
|
||
private boolean isAllowedHost(String host) { | ||
try { | ||
InetAddress[] addresses = InetAddress.getAllByName(host); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add a comment that this is best-effort: if DNS caching is disabled or the cache expires between our check here and when we actually invoke the API, the endpoint might not be loopback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will add Javadoc.
f112c47
to
040b4ae
Compare
It appears IMDS clients can configure the endpoint, and even when not, the default values are |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, added a small non-functional comment/question. Non-blocking.
"%s has an invalid host. Host should resolve to a loopback" + | ||
" address.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also include that making it HTTPS is an alternative way to fix it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. Updated exception message.
a52266a
to
a8711bc
Compare
f93ee93
to
86fbfc2
Compare
d177fd0
to
76df19e
Compare
SonarCloud Quality Gate failed. |
Motivation and Context
HTTP(S) credential provider requires the implementation to verify that the resolved addresses for the host are actually loopback addresses.
InetAddress is used to resolve DNS names.
Testing
Added unit tests.
Screenshots (if appropriate)
Types of changes
Checklist
mvn install
succeedsscripts/new-change
script and following the instructions. Commit the new file created by the script in.changes/next-release
with your changes.License