Am I affected?
Description
ExAws.S3.Utils.build_lifecycle_rule/1 in ex_aws_s3 interpolates caller-supplied lifecycle rule fields (the rule id, filter prefix, tag key and value, storage class, and noncurrent-version count) directly into the PutBucketLifecycleConfiguration XML body without escaping XML metacharacters. An application that populates any of these fields from untrusted input (for example a tenant-supplied object tag) lets an attacker break out of the surrounding element and inject arbitrary XML into the request, including an entirely new lifecycle action such as a delete-after-one-day expiration that destroys the bucket's objects. The public entry point ExAws.S3.put_bucket_lifecycle/2 flows directly into this builder.
This issue affects ex_aws_s3: from 2.3.0 before 2.6.0.
Technical analysis
1. Unescaped interpolation. build_lifecycle_rule/1 in lib/ex_aws/s3/utils.ex builds each text node of the PutBucketLifecycleConfiguration body by raw string interpolation: the rule id, the filter prefix, tag key and value, the storage class and newer_noncurrent_versions. None is XML-escaped or validated before IO.iodata_to_binary/1 flattens the body.
2. Element break-out. A value containing XML metacharacters is emitted verbatim. A tag value such as frontend</Value></Tag></Filter><Expiration><Days>1</Days></Expiration><Filter><Tag><Key>team</Key><Value>frontend closes the <Value>, injects an <Expiration> action and reopens a <Filter>, so the rest of the document stays well-formed. The same technique can close and reopen <Rule> to append a separate rule.
3. Delivery. The public entry point ExAws.S3.put_bucket_lifecycle/2 flows directly into this builder, so S3 receives and applies the injected lifecycle configuration as soon as the request is sent with ExAws.request/2.
Proof of concept
- A multi-tenant application mirrors tenant-supplied object tags into an S3 lifecycle rule:
ExAws.S3.put_bucket_lifecycle("tenant-bucket", [rule]) |> ExAws.request(config)withfilter: %{tags: [{"team", value}]}. - The tenant sets the tag value to
frontend</Value></Tag></Filter><Expiration><Days>1</Days></Expiration><Filter><Tag><Key>team</Key><Value>frontend. build_lifecycle_rule/1interpolates it unescaped into the request body.- The body S3 receives contains
//Rule/Expiration/Daysequal to1: an injected action that expires the bucket's objects after one day.
Weaknesses & attack patterns
Weakness
CWE-91
·
XML Injection
in catalog →
MITRE ↗
Attack patterns
CAPEC-250
·
XML Injection
MITRE ↗
This is an XML/document injection vulnerability in the construction of the PutBucketLifecycleConfiguration request. Any application that uses ex_aws_s3 and populates a lifecycle rule's id, prefix, tag key/value, storage class, or noncurrent-version count from data it does not fully control is affected. An attacker who controls one of those fields can inject arbitrary lifecycle actions or rules into the request, most damagingly an expiration that deletes the bucket's objects, leading to data loss or unintended retention/transition policies. Multi-tenant services that map tenant-supplied tags or identifiers into bucket lifecycle configuration are the most exposed.
Affected — Hex / ex_aws_s3 Hex.pm ↗ Repository ↗
modules · source files · routines
Affected — GitHub / ex-aws/ex_aws_s3 Repository ↗
modules · source files · routines
Workarounds
Applications can escape or strictly validate any untrusted value before passing it into a lifecycle rule field (the rule id, filter prefix, tag key or value, storage class, or noncurrent-version count) so that XML metacharacters cannot alter the request structure.
References
Credits
CVSS breakdown
CVSS:4.0/AV:L/AC:L/AT:P/PR:N/UI:N/VC:N/VI:H/VA:N/SC:N/SI:H/SA:H
Exploitability
- Attack Vector
- Local
- Attack Complexity
- Low
- Attack Requirements
- Present
- Privileges Required
- None
- User Interaction
- None
Vulnerable System
- Confidentiality
- None
- Integrity
- High
- Availability
- None
Subsequent Systems
- Confidentiality
- None
- Integrity
- High
- Availability
- High