Potential URI resolution path traversal in the AWS SDK for PHP
Description
AWS SDK for PHP is the Amazon Web Services software development kit for PHP. Within the scope of requests to S3 object keys and/or prefixes containing a Unix double-dot, a URI path traversal is possible. The issue exists in the buildEndpoint method in the RestSerializer component of the AWS SDK for PHP v3 prior to 3.288.1. The buildEndpoint method relies on the Guzzle Psr7 UriResolver utility, which strips dot segments from the request path in accordance with RFC 3986. Under certain conditions, this could lead to an arbitrary object being accessed. This issue has been patched in version 3.288.1.
Affected packages
Versions sourced from the GitHub Security Advisory.
| Package | Affected versions | Patched versions |
|---|---|---|
aws/aws-sdk-phpPackagist | < 3.288.1 | 3.288.1 |
Affected products
1- Range: >= 3.0.0, < 3.288.1
Patches
1aebc9f801438bugfix: dot segment handling (#2835)
3 files changed · +69 −2
.changes/nextrelease/s3-dot-segment.json+7 −0 added@@ -0,0 +1,7 @@ +[ + { + "type": "bugfix", + "category": "s3", + "description": "Disables transformation of request URI paths with dot segments" + } +]
src/Api/Serializer/RestSerializer.php+9 −2 modified@@ -242,14 +242,21 @@ function (array $matches) use ($varDefinitions) { $path = rtrim($path, '/'); } $relative = $path . $relative; + + if (strpos($relative, '../') !== false) { + if ($relative[0] !== '/') { + $relative = '/' . $relative; + } + return new Uri($this->endpoint . $relative); + } } // If endpoint has path, remove leading '/' to preserve URI resolution. if ($path && $relative[0] === '/') { $relative = substr($relative, 1); } - //Append path to endpoint when leading '//...' present - // as uri cannot be properly resolved + //Append path to endpoint when leading '//...' + // present as uri cannot be properly resolved if ($this->api->isModifiedModel() && strpos($relative, '//') === 0 ) {
tests/S3/S3ClientTest.php+53 −0 modified@@ -2321,4 +2321,57 @@ public function testDoesNotComputeMD5($options, $operation) ); $s3->execute($command); } + + /** + * @dataProvider dotSegmentProvider + */ + public function testHandlesDotSegmentsInKey($key, $expectedUri) + { + $s3 = $this->getTestClient('s3'); + $this->addMockResults($s3, [[]]); + $command = $s3->getCommand('getObject', ['Bucket' => 'foo', 'Key' => $key]); + $command->getHandlerList()->appendSign( + Middleware::tap(function ($cmd, $req) use ($expectedUri) { + $this->assertSame($expectedUri, (string) $req->getUri()); + }) + ); + $s3->execute($command); + } + + public function dotSegmentProvider() + { + return [ + ['../foo' , 'https://foo.s3.amazonaws.com/../foo'], + ['bar/../../foo', 'https://foo.s3.amazonaws.com/bar/../../foo'], + ['/../foo', 'https://foo.s3.amazonaws.com//../foo'], + ['foo/bar/../baz', 'https://foo.s3.amazonaws.com/foo/bar/../baz'] + ]; + } + + /** + * @dataProvider dotSegmentPathStyleProvider + */ + public function testHandlesDotSegmentsInKeyWithPathStyle($key, $expectedUri) + { + $s3 = $this->getTestClient('s3', ['use_path_style_endpoint' => true]); + $this->addMockResults($s3, [[]]); + $command = $s3->getCommand('getObject', ['Bucket' => 'foo', 'Key' => $key]); + $command->getHandlerList()->appendSign( + Middleware::tap(function ($cmd, $req) use ($expectedUri) { + $this->assertSame($expectedUri, (string) $req->getUri()); + }) + ); + $s3->execute($command); + } + + public function dotSegmentPathStyleProvider() + { + return [ + ['../foo' , 'https://s3.amazonaws.com/foo/foo/../foo'], + ['bar/../../foo', 'https://s3.amazonaws.com/foo/foo/bar/../../foo'], + ['/../foo', 'https://s3.amazonaws.com/foo/foo//../foo'], + ['foo/bar/../baz', 'https://s3.amazonaws.com/foo/foo/foo/bar/../baz'], + ]; + } + }
Vulnerability mechanics
Generated by null/stub on May 9, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.
References
6- github.com/advisories/GHSA-557v-xcg6-rm5mghsaADVISORY
- nvd.nist.gov/vuln/detail/CVE-2023-51651ghsaADVISORY
- github.com/FriendsOfPHP/security-advisories/blob/master/aws/aws-sdk-php/CVE-2023-51651.yamlghsaWEB
- github.com/aws/aws-sdk-php/commit/aebc9f801438746ac4ade327551576cb75f635f2ghsax_refsource_MISCWEB
- github.com/aws/aws-sdk-php/releases/tag/3.288.1ghsax_refsource_MISCWEB
- github.com/aws/aws-sdk-php/security/advisories/GHSA-557v-xcg6-rm5mghsax_refsource_CONFIRMWEB
News mentions
0No linked articles in our index yet.