// The following will return 'false', although the attacker value will "leave" the `/usr/foo` directory
leavesRoot(new File("/usr/foo"), "/../foo-bar/bar")
This guard is used here which should guard against path traversal, however leavesRoot is an insufficient guard:
https://github.com/aws/aws-sdk-java/blob/ae88c8aa4b195047b94c154897475f85642d7eb3/aws-java-sdk-s3/src/main/java/com/amazonaws/services/s3/transfer/TransferManager.java#L1420-L1423
If the result of parent.getCanonicalPath() is not slash terminated it allows for partial path traversal.
Consider
"/usr/outnot".startsWith("/usr/out"). The check is bypassed althoughoutnotis not under theoutdirectory. The terminating slash may be removed in various places. On Linuxprintln(new File("/var/"))returns/var, butprintln(new File("/var", "/"))-/var/, howeverprintln(new File("/var", "/").getCanonicalPath())-/var. - @JarLob (Jaroslav Lobačevski)
Upgrade to the AWS SDK for Java >= 1.12.261, if you are on a version < 1.12.261.
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 .. .
Similar vulnerabilities:
If you have any questions or comments about this advisory, please contact AWS's Security team.
| Package Name | Ecosystem | Vulnerable Versions | First Patched Version |
|---|---|---|---|
| com.amazonaws:aws-java-sdk-s3 | maven | < 1.12.261 | 1.12.261 |
The patches provided show that the leavesRoot method in TransferManager.java was modified to fix a partial-path traversal vulnerability. The downloadDirectory method, which uses leavesRoot, was also implicitly patched as a result. The vulnerable functions are leavesRoot and downloadDirectory in TransferManager.java.
KEV Misses 88% of Exploited CVEs- Get the report