Devsec fix urlsanitization #180
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
The code was using indexOf() to check if a hostname contains 's3.amazonaws.com'. This is unsafe because indexOf() matches the string anywhere in the hostname, not just as the actual domain.
Example of the vulnerability:
s3.amazonaws.com.attacker.com would pass (dangerous!)
evil-s3.amazonaws.com would pass (dangerous!)
An attacker could exploit this to redirect AWS requests to a malicious server and potentially steal credentials or data.
Solution
Changed the hostname validation to use proper domain checking:
hostname === 's3.amazonaws.com' - exact match for the global S3 endpoint
hostname.endsWith('.s3.amazonaws.com')] - valid S3 subdomains only
Now only legitimate AWS S3 domains are accepted:
s3.amazonaws.com (exact match)
mybucket.s3.amazonaws.com (valid subdomain)
s3.amazonaws.com.evil.com (blocked - ends with .evil.com)
evil-s3.amazonaws.com (blocked - not a valid S3 domain)
Impact
Security: Prevents URL confusion attacks
Functionality: No breaking changes - all legitimate AWS S3 endpoints continue to work as expected
Location: index.js line ~42630 in the optInUsEast1RegionalEndpoint function