Server-Side Request Forgery (SSRF) vulnerability in ex-aws exaws allows an attacker who controls an S3 bucket name to send the application's signed S3 requests to a host of their choice.
With virtualhost: true, ExAws.Operation.S3.addbuckettopath/2 in lib/exaws/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 bucketashost: true the bucket is the whole hostname, so any valid hostname redirects the request.
This issue affects exaws: from 2.1.7 before 2.8.0.
Summary
Relative path traversal in exaws allows an attacker who controls an S3 object key to escape the intended bucket or key prefix.
When exaws builds a path-style S3 request, ExAws.Operation.S3.addbuckettopath/2 in lib/exaws/operation/s3.ex joins the bucket name and the object key into a single path string and then normalizes it, collapsing . and .. segments the way a filesystem path would. Because the bucket is the first segment of the combined string, a leading ../ in the object key pops the bucket off the path. With bucket mybucket and a key of ../victim/secret.txt, the combined /mybucket/../victim/secret.txt normalizes to /victim/secret.txt, so the request (signed with the application's own credentials) is sent to bucket victim. The same mechanism collapses ../ within a key, defeating any isolation an application enforces by prepending a trusted prefix.
Only the default path-style configuration is affected; requests built with virtualhost: true do not run this normalization. Because S3 treats object keys as opaque and does not resolve .. itself, the client-side normalization introduces a traversal that would not otherwise exist. Any application that derives an S3 object key from untrusted input and relies on the bucket, or a key prefix, as a tenant or trust boundary is exposed to cross-bucket or cross-prefix read and write, depending on the operation and the credentials' permissions.
This issue affects exaws: from 2.1.7 before 2.8.0.
Details
1. Path assembly. In the default path-style clause of ExAws.Operation.S3.addbuckettopath/2 (taken whenever virtualhost: true is not set), the bucket and the operation path are concatenated and then normalized: "/#{operation.bucket}#{ensureabsolute(operation.path)}" |> expanddot().
2. Normalization across the bucket boundary. expanddot/1 and doexpanddot/2 resolve . and .. segments the way a filesystem path would. The bucket is just the first segment of the combined string, so a .. in the object key pops it: /mybucket/../victim/secret.txt becomes /victim/secret.txt. The only guard, the root clamp doexpanddot([".." | t], []), stops .. from climbing above / but does not protect the bucket segment. The same collapse lets ../ escape a trusted key prefix within a bucket.
3. Signed request. The normalized path is signed with the application's credentials and sent, so the request is authorized against the bucket or prefix the attacker chose. S3 treats object keys as opaque and does not resolve .. itself; the traversal exists only because the client normalizes the path. The virtualhost clauses do not normalize, so behavior differs between configurations.
Proof of concept
1. An application isolates data in its own bucket mybucket and builds the object key from user input, using the default path-style S3 configuration. 2. It issues the request through the public API: ExAws.S3.getobject("mybucket", key) |> ExAws.request(config). 3. The attacker supplies the key ../victim/secret.txt. 4. exaws joins and normalizes the path, so /mybucket/../victim/secret.txt becomes /victim/secret.txt. 5. The request is signed with the application's credentials and sent to /victim/secret.txt, addressing bucket victim instead of mybucket.
Workarounds
Configure the exaws S3 client with virtualhost: true, which builds the request without the client-side path normalization. Alternatively, reject or sanitize object keys that contain .. segments before passing them to exaws.
Configurations
The vulnerability is only exposed in the default path-style S3 configuration, where exaws normalizes the combined bucket and key path. Applications that configure the S3 client with virtualhost: true build the request without this client-side normalization and are not affected.
Summary
Server-Side Request Forgery (SSRF) vulnerability in exaws (instance metadata token provider).
This vulnerability is associated with program files lib/exaws/instancemetatokenprovider.ex and program routines ExAws.InstanceMetaTokenProvider.requesttoken/1 and ExAws.InstanceMetaTokenProvider.get/1.
exaws requests its IMDSv2 session token from the link-local metadata endpoint (http://169.254.169.254/latest/api/token) with HTTP redirect following enabled. Because the token request follows 3xx redirects and does not restrict the redirect target to the link-local range, an attacker who can influence the response to the metadata request (for example an on-segment neighbor spoofing the link-local address) can answer with a redirect to an arbitrary host. The library follows the redirect and accepts the arbitrary host's response body as the IMDSv2 session token, caching it and sending it as the x-aws-ec2-metadata-token header on every subsequent metadata and credential request.
This issue affects exaws: from 2.3.0 before 2.8.0.
Details
1. Token request. ExAws.InstanceMetaTokenProvider.requesttoken/1 sends the IMDSv2 PUT to the hard-coded link-local endpoint http://169.254.169.254/latest/api/token with followredirect: true in its HTTP options. AWS advises against following redirects on metadata requests, and IMDSv2's "PUT plus required header" design is itself an SSRF mitigation.
2. Redirect following. Any 3xx reply to the token request is followed by the HTTP client to whatever host its Location header names. Nothing restricts the redirect target to the link-local range, so the request can leave 169.254.169.254.
3. Token acceptance. The body returned by the final URL is accepted verbatim as the session token, cached in ETS, and sent as the x-aws-ec2-metadata-token header on every later metadata and credential request the library makes. Whoever answers the redirect therefore chooses both where the token request ends up and which value is used as the token.
Proof of concept
1. The attacker is positioned to answer requests the instance sends to 169.254.169.254, for example as an on-segment neighbor spoofing the link-local address. 2. The application obtains a metadata token through ExAws.InstanceMetaTokenProvider.get/1, which calls requesttoken/1 and sends PUT /latest/api/token to the link-local endpoint. 3. The attacker answers the PUT with 302 and a Location header pointing at a host they control. 4. The HTTP client follows the redirect because exaws passed followredirect: true, and the attacker's host replies 200 with a chosen body such as ATTACKER-CONTROLLED-SESSION-TOKEN. 5. get/1 returns that body as the IMDSv2 session token, and exaws caches it and sends it as x-aws-ec2-metadata-token on later metadata and credential requests.
Configurations
The application must obtain its AWS credentials from the EC2 Instance Metadata Service (IMDSv2) through the exaws instance metadata token provider. Applications that source credentials by other means (for example environment variables or explicit configuration) do not reach the vulnerable code path.
Summary
Improper Encoding or Escaping of Output vulnerability in exaws (S3 request URL construction).
This vulnerability is associated with program files lib/exaws/request/url.ex and program routines ExAws.Request.Url.build/2, ExAws.Request.Url.sanitize/2 and ExAws.Request.Url.getpath/2.
exaws does not percent-encode reserved characters in S3 object keys when it assembles the request URL. A literal ? in an object key survives unencoded: build/2 inserts the operation path verbatim and URI.tostring/1 emits it without encoding, and sanitize/2 then splits the flattened URL on the first ?, treating everything after it as the query string. Because the split runs before uriencode is applied to the path, the ? is never neutralized, and the recovered query is re-inserted without any encoding.
An attacker who controls part of an object key (for example a download or upload keyed by a user-supplied filename) can therefore truncate the key past application-appended suffixes, causing the request to address a different object than the application intended, and can inject live S3 sub-resource operations (such as ?acl, ?tagging or ?versions) into the request. The manipulated URL is signed and transmitted normally, so the tampering is authorized like any legitimate request.
This issue affects exaws: from 2.1.2 before 2.8.0.
Details
1. URL assembly. ExAws.Request.Url.build/2 inserts the operation path (bucket and object key) verbatim, and URI.tostring/1 emits it without percent-encoding. A literal ? in the object key passes straight into the flattened URL string.
2. Path/query split. For S3, sanitize/2 recovers the path and query by splitting that string on the first ?. getpath/2 keeps only the portion before the ? as the path and runs it through uriencode. Everything after the ? becomes the query string and is re-inserted without any encoding.
3. Signing and transmission. Because the split happens before uriencode runs, the path encoder never sees the ?. The resulting request is signed and sent as built:
- the key report.pdf?acl is sent as GET /report.pdf?acl, promoting ?acl from key bytes into a live S3 sub-resource parameter; - the key secret?<suffix> loses everything after the ? (for example an application-appended .json extension), so the request addresses a different object than the one the caller constructed.
Proof of concept
1. An application lets users download text exports and builds the object key from a user-supplied filename, appending the extension itself: key = filename <> ".txt". 2. It fetches the object through the public entry point: ExAws.S3.getobject(bucket, key) |> ExAws.request(config). 3. A benign filename export yields the key export.txt and the request GET /victim-bucket/export.txt. 4. The attacker supplies the filename export.dump?, producing the key export.dump?.txt. 5. exaws sends GET /victim-bucket/export.dump with the query string .txt: the application's .txt suffix is moved into the query and dropped from the key. 6. S3 returns the bytes of export.dump, an object of a different type the application never meant to expose.
Workarounds
Before constructing an S3 operation, percent-encode reserved characters in the object key (or reject keys that contain ? or #) so that no reserved character reaches the URL builder unencoded.
Configurations
The vulnerability is reachable only on the Amazon S3 request path (the code guarded by service "s3"), which applications typically issue through the exawss3 package. The application must construct S3 operations whose object keys derive from untrusted input (for example a download or upload keyed by a user-supplied filename or identifier). Requests to other AWS services, and S3 operations built entirely from trusted keys, do not reach the vulnerable behavior.