Vulnerabilities in pkg:maven/com.amazonaws/aws-java-sdk-s3
PACKAGECVE-2022-31159 is a HIGH (CVSS 7.9) aws-java-sdk-s3 vulnerability (CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')) affecting Aws java sdk s3 libraries in the Maven ecosystem. The issue involves aws-java-sdk-s3. Remediation is available by upgrading affected packages to version 1.12.261.
pkg:maven/com.amazonaws/aws-java-sdk-s3
Vulnerability advisories affecting package pkg:maven/com.amazonaws/aws-java-sdk-s3. Select an advisory below to view technical details or fixes.
| Advisory ID | CVE / NVD | Severity | Summary |
|---|---|---|---|
| GHSA-c28r-hw5m-5gv3 | CVE-2022-31159 | HIGH | Partial Path Traversal in com.amazonaws:aws-java-sdk-s3 |
CVE-2022-31159 at a Glance
Security Impact
CVSS: 7.9
The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:H/PR:L/UI:R/S:C/C:H/I:H/A:L).
How to Fix CVE-2022-31159
To remediate this vulnerability, upgrade all affected Aws java sdk s3 dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>1.12.261</version>
</dependency>
Run the following command in your project directory to verify that all resolved dependencies use the patched release:
mvn dependency:tree -Dincludes=com.amazonaws
How to Check if You Are Affected
To determine whether your Java application is affected by CVE-2022-31159, inspect your build dependencies using the Maven Dependency Plugin:
mvn dependency:tree -Dincludes=com.amazonaws
Analyze the terminal output to locate any version of Aws java sdk s3 in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 1.12.261), your application is affected.
Note: The mvn dependency:tree -Dincludes=com.amazonaws command inspects the resolved dependency graph declared in your project's POM files; it does not perform automated security scanning or inspect runtime dynamic classpaths. Always verify runtime container classpaths and shaded JARs.
Technical Details
Vulnerability Mechanism & Technical Analysis
This vulnerability is classified under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal'), where the product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory. In Aws java sdk s3, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.
Source Advisory Statement
CVE-2022-31159 Affected Aws java sdk s3 Versions
1 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
com.amazonaws:aws-java-sdk-s3
|
Maven |
< 1.12.261
|
1.12.261
|
References
Frequently Asked Questions
What is CVE-2022-31159?
Which Aws java sdk s3 versions are affected?
What version fixes CVE-2022-31159?
Is aws-java-sdk-s3 affected?
What is the CVSS score of CVE-2022-31159?
What CWE is associated with CVE-2022-31159?
How can I check Maven dependencies for CVE-2022-31159?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"schema_version" : "1.4.0",
"id" : "GHSA-c28r-hw5m-5gv3",
"modified" : "2022-08-05T00:22:25Z",
"published" : "2022-07-15T20:44:55Z",
"aliases" : [ "CVE-2022-31159" ],
"summary" : "Partial Path Traversal in com.amazonaws:aws-java-sdk-s3 ",
"details" : "### Overview\n\nA partial-path traversal issue exists within the `downloadDirectory` method in the AWS S3 TransferManager component of the AWS SDK for Java v1. 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. \n\nThis 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`. \n\nVersions of the AWS Java SDK for S3 v1 before and including v1.12.260 are affected by this issue. \n\n### Impact\n\nIf `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.\n\n#### Root Cause\n\nThe `com.amazonaws.services.s3.transfer.TransferManager::downloadDirectory` contains a partial-path traversal vulnerability.\n\nThis is due to the guard logic in `leavesRoot` containing an insufficient protection against partial-path traversal.\n\nhttps://github.com/aws/aws-sdk-java/blob/5be0807af763b9fbf6b0a153c76dd305e407f035/aws-java-sdk-s3/src/main/java/com/amazonaws/services/s3/transfer/TransferManager.java#L1513-L1519\n\nThe application controls the `localBaseDirectory` argument, but the `key` comes from the AWS bucket entry (ie. can be attacker controlled). The above bit of logic can be bypassed with the following payloads:\n\n```java\n// The following will return 'false', although the attacker value will \"leave\" the `/usr/foo` directory\nleavesRoot(new File(\"/usr/foo\"), \"/../foo-bar/bar\")\n```\n\nThis guard is used here which should guard against path traversal, however `leavesRoot` is an insufficient guard:\n\nhttps://github.com/aws/aws-sdk-java/blob/ae88c8aa4b195047b94c154897475f85642d7eb3/aws-java-sdk-s3/src/main/java/com/amazonaws/services/s3/transfer/TransferManager.java#L1420-L1423\n\n#### True Root cause\n\n If the result of `parent.getCanonicalPath()` is not slash terminated it allows for partial path traversal.\n\n> Consider `\"/usr/outnot\".startsWith(\"/usr/out\")`. The check is bypassed although `outnot` is not under the `out` directory.\nThe terminating slash may be removed in various places. On Linux `println(new File(\"/var/\"))` returns `/var`, but `println(new File(\"/var\", \"/\"))` - `/var/`, however `println(new File(\"/var\", \"/\").getCanonicalPath())` - `/var`.\n \\- [@JarLob (Jaroslav Lobačevski)](https://github.com/JarLob)\n\n### Patches\n\nUpgrade to the AWS SDK for Java >= 1.12.261, if you are on a version < 1.12.261.\n\n### Workarounds\n\nWhen calling `com.amazonaws.services.s3.transfer.TransferManager::downloadDirectory` pass a `KeyFilter` that forbids `S3ObjectSummary` objects that `getKey` method return a string containing the substring `..` .\n\n### References\n\nSimilar vulnerabilities:\n - ESAPI (The OWASP Enterprise Security API) - https://nvd.nist.gov/vuln/detail/CVE-2022-23457\n\n### For more information\n\nIf you have any questions or comments about this advisory, please contact [AWS's Security team](mailto:aws-security@amazon.com).\n",
"severity" : [ {
"type" : "CVSS_V3",
"score" : "CVSS:3.1/AV:N/AC:H/PR:L/UI:R/S:C/C:H/I:H/A:L"
} ],
"affected" : [ {
"package" : {
"ecosystem" : "Maven",
"name" : "com.amazonaws:aws-java-sdk-s3"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "0"
}, {
"fixed" : "1.12.261"
} ]
} ]
} ],
"references" : [ {
"type" : "WEB",
"url" : "https://github.com/aws/aws-sdk-java/security/advisories/GHSA-c28r-hw5m-5gv3"
}, {
"type" : "ADVISORY",
"url" : "https://nvd.nist.gov/vuln/detail/CVE-2022-31159"
}, {
"type" : "WEB",
"url" : "https://github.com/aws/aws-sdk-java/commit/cb66c50c885566d9a7fce837a68dc48ddced8a9a"
}, {
"type" : "PACKAGE",
"url" : "https://github.com/aws/aws-sdk-java"
} ],
"database_specific" : {
"cwe_ids" : [ "CWE-22" ],
"severity" : "HIGH",
"github_reviewed" : true,
"github_reviewed_at" : "2022-07-15T20:44:55Z",
"nvd_published_at" : "2022-07-15T18:15:00Z"
}
}