Am I affected?
Description
Externally Controlled Reference to a Resource in Another Sphere vulnerability in ex-aws ex_aws_s3 allows an attacker who controls an S3 bucket name to make presigned URLs and presigned POST forms point at a host of their choice.
With virtual_host: true, s3_accelerate: true or bucket_as_host: true, ExAws.S3.presigned_url/5 and ExAws.S3.presigned_post/4 build the URL from the bucket name without checking it. A bucket such as attacker.example/x? turns the URL into https://attacker.example/x?.s3.amazonaws.com..., and the signature is computed for that host. Clients given the URL upload their files to, or download content from, the attacker's host, and every such URL discloses the access key id. With bucket_as_host: true any valid hostname works as the bucket name.
This issue affects ex_aws_s3: from 2.0.0 before 2.6.0.
Technical analysis
1. URL construction. The private url_to_sign/5 in lib/ex_aws/s3.ex builds the URL for presigned_url/5 and presigned_post/4 as "#{scheme}#{bucket}.#{host}#{port}#{object}" when virtual_host is set, or "#{scheme}#{bucket}#{port}#{object}" with bucket_as_host. s3_accelerate: true sets virtual_host and takes the same branch. The bucket name is not checked.
2. Signing for the attacker's host. The string goes to ExAws.Auth.presigned_url/9, which signs URI.parse(url).authority. For the bucket attacker.example/x? the signed host is attacker.example, and the ? pushes the object key into the query string.
3. Effect. Presigned URLs are built locally and never pass through ExAws.Operation.S3.add_bucket_to_path/2, so the fix in ex_aws for the request path does not cover them. A browser submitting the presigned POST sends its upload to the attacker, a client following a presigned GET receives attacker content, and X-Amz-Credential discloses the access key id. The secret key is not disclosed and the signature cannot be replayed against AWS.
Proof of concept
- An application presigns uploads for per-tenant buckets with
virtual_host: true. - A tenant sets its bucket name to
attacker.example/x?. ExAws.S3.presigned_url(config, :put, bucket, "key", virtual_host: true)returnshttps://attacker.example/x?.s3.amazonaws.com%2Fkey=&X-Amz-Credential=..., andpresigned_post/4returns the form actionhttps://attacker.example/x?.s3.amazonaws.com.URI.parse/1on either yields the hostattacker.example, so any client given the URL or form connects there.
Weaknesses & attack patterns
Weakness
CWE-610
·
Externally Controlled Reference to a Resource in Another Sphere
in catalog →
MITRE ↗
Attack patterns
CAPEC-154
·
Resource Location Spoofing
MITRE ↗
An attacker who can choose the bucket name makes the application hand out presigned URLs and POST forms that point at the attacker's host. Files other users upload through those forms go to the attacker, presigned downloads serve attacker-controlled content under the application's name, and every such URL discloses the access key id. Applications that presign for per-tenant or user-supplied buckets with virtual-host addressing are affected.
Affected — Hex / ex_aws_s3 Hex.pm ↗ Repository ↗
modules · source files · routines
Affected — GitHub / ex-aws/ex_aws_s3 Repository ↗
modules · source files · routines
Configurations
Reachable only when presigned URLs or POST forms are generated with virtual_host: true, s3_accelerate: true or bucket_as_host: true and the application passes a bucket name an attacker can influence, for example per-tenant or user-supplied buckets. Path-style presigning, the default, places the bucket in the path and is not affected.
Solutions
Upgrading rejects bucket names containing characters that can change the host of a presigned URL. With bucket_as_host: true, a syntactically valid hostname is still used as the host after upgrading: applications that presign with bucket_as_host: true and bucket names they do not fully control must also pass the bucket_as_host_allowlist option, or set it in the S3 config, with the list of trusted hostnames.
References
Credits
CVSS breakdown
CVSS:4.0/AV:L/AC:L/AT:P/PR:N/UI:P/VC:H/VI:L/VA:N/SC:N/SI:N/SA:N
Exploitability
- Attack Vector
- Local
- Attack Complexity
- Low
- Attack Requirements
- Present
- Privileges Required
- None
- User Interaction
- Passive
Vulnerable System
- Confidentiality
- High
- Integrity
- Low
- Availability
- None
Subsequent Systems
- Confidentiality
- None
- Integrity
- None
- Availability
- None