# CVE-2022-31159: Partial Path Traversal in com.amazonaws:aws-java-sdk-s3

> Attackers can write files outside the intended directory via path traversal in the AWS S3 TransferManager downloadDirectory method.

- **Severity:** High 7.9 (`CVSS:3.1/AV:N/AC:H/PR:L/UI:R/S:C/C:H/I:H/A:L`)
- **Exploited in the wild:** Not known
- **Login needed:** Any signed-in user
- **Attackable:** Over the internet
- **Victim action needed:** A user has to click or open something
- **Fix available:** Yes
- **Published:** 15 Jul 2022
- **Updated:** 22 Apr 2025
- **Also known as:** CVE-2022-31171, GHSA-c28r-hw5m-5gv3, ROOT-APP-MAVEN-CVE-2022-31159

## What is CVE-2022-31159?

CVE-2022-31159 is a high-severity path traversal vulnerability in aws-sdk-java, published on 15 Jul 2022. Any signed-in user can exploit it over the network, and only if a user opens a file or follows a link.

### Official description

The AWS SDK for Java enables Java developers to work with Amazon Web Services. A partial-path traversal issue exists within the `downloadDirectory` method in the AWS S3 TransferManager component of the AWS SDK for Java v1 prior to version 1.12.261. Applications using the SDK control the `destinationDirectory` argument, but S3 object keys are determined by the application that uploaded the objects. The `downloadDirectory` method allows the caller to pass a filesystem object in the object key but contained an issue in the validation logic for the key name. A knowledgeable actor could bypass the validation logic by including a UNIX double-dot in the bucket key. Under certain conditions, this could permit them to retrieve a directory from their S3 bucket that is one level up in the filesystem from their working directory. This issue’s scope is limited to directories whose name prefix matches the destinationDirectory. E.g. for destination directory`/tmp/foo`, the actor can cause a download to `/tmp/foo-bar`, but not `/tmp/bar`. If `com.amazonaws.services.s3.transfer.TransferManager::downloadDirectory` is used to download an untrusted buckets contents, the contents of that bucket can be written outside of the intended destination directory. Version 1.12.261 contains a patch for this issue. As a workaround, when calling `com.amazonaws.services.s3.transfer.TransferManager::downloadDirectory`, pass a `KeyFilter` that forbids `S3ObjectSummary` objects that `getKey` method return a string containing the substring `..` .

Weakness: CWE-22 (Improper Limitation of a Pathname to a Restricted Directory)

## Which versions are affected by CVE-2022-31159?

2 open source packages ship an affected version, including com.amazonaws:aws-java-sdk-s3. It affects 1 product.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `com.amazonaws:aws-java-sdk-s3` | Maven | All versions | 1.12.261 |
| `com.amazonaws:aws-java-sdk-s3` | Maven | All versions | 1.12.261 |

Products: Amazon Aws-Sdk-Java.

## How do I fix CVE-2022-31159?

Upgrade com.amazonaws:aws-java-sdk-s3 to 1.12.261 or later.

## Is CVE-2022-31159 being exploited?

It is not confirmed as exploited in the wild, but public exploit code for CVE-2022-31159 exists.

Public exploit code:

- https://github.com/shoucheng3/aws__aws-sdk-java_CVE-2022-31159_1-12-2600 (github_poc): https://github.com/shoucheng3/aws__aws-sdk-java_CVE-2022-31159_1-12-2600

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2022-31159 and fix it if it is affected.

What it is: CVE-2022-31159 is a high-severity path traversal vulnerability in aws-sdk-java, published on 15 Jul 2022. Any signed-in user can exploit it over the network, and only if a user opens a file or follows a link.
Exploitation: It is not confirmed as exploited in the wild, but public exploit code for CVE-2022-31159 exists.

Affected packages and fixed versions:
- com.amazonaws:aws-java-sdk-s3 (Maven): affected all versions; fixed in 1.12.261
- com.amazonaws:aws-java-sdk-s3 (Maven): affected all versions; fixed in 1.12.261

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/CVE-2022-31159/ (Markdown: https://insights.sbomify.com/CVE-2022-31159/index.md)
```

## Sources

- CVE record: https://www.cve.org/CVERecord?id=CVE-2022-31159
- NVD: https://nvd.nist.gov/vuln/detail/CVE-2022-31159
- OSV: https://osv.dev/vulnerability/CVE-2022-31159

---
From sbomify Insights: https://insights.sbomify.com/CVE-2022-31159/
Summaries are generated and may contain mistakes; the official description above is the record.
