Am I affected?

type your ex_aws_s3 version to check

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

  1. An application presigns uploads for per-tenant buckets with virtual_host: true.
  2. A tenant sets its bucket name to attacker.example/x?.
  3. ExAws.S3.presigned_url(config, :put, bucket, "key", virtual_host: true) returns https://attacker.example/x?.s3.amazonaws.com%2Fkey=&X-Amz-Credential=..., and presigned_post/4 returns the form action https://attacker.example/x?.s3.amazonaws.com.
  4. URI.parse/1 on either yields the host attacker.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 ↗

≥ 2.0.0 < 2.6.0 affected
every other version: unaffected
cpe cpe:2.3:a:ex-aws:ex_aws_s3:*:*:*:*:*:*:*:*
version type semver
modules · source files · routines
modules 'Elixir.ExAws.S3'
source files lib/ex_aws/s3.ex
routines 'Elixir.ExAws.S3':presigned_url/5 · 'Elixir.ExAws.S3':presigned_post/4 · 'Elixir.ExAws.S3':url_to_sign/5

Affected — GitHub / ex-aws/ex_aws_s3 Repository ↗

≥ 4ce4d72 < ea26e8b affected
every other version: unaffected
cpe cpe:2.3:a:ex-aws:ex_aws_s3:*:*:*:*:*:*:*:*
version type git
modules · source files · routines
modules 'Elixir.ExAws.S3'
source files lib/ex_aws/s3.ex
routines 'Elixir.ExAws.S3':presigned_url/5 · 'Elixir.ExAws.S3':presigned_post/4 · 'Elixir.ExAws.S3':url_to_sign/5

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

Peter Ullrich Finder Reporter Coordinator
Jonatan Männchen / EEF Analyst
Bernard Duggan Remediation developer

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
« All CVEs