Skip to content

Commit 8930600

Browse files
fix: validates custom policy and resourceURL (#3255)
* fix: validates custom provided policies Validates any customer provided json policy document for CloudFront\Signer.php to avoid any non allowed symbols. * chore: add changelog entry * fix: validate also resourceURL * chore: normalize url path parts.
1 parent f6ef7cd commit 8930600

3 files changed

Lines changed: 14 additions & 1 deletion

File tree

src/CloudFront/Signer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public function getSignature($resource = null, $expires = null, $policy = null)
8484
self::validatePolicy($policy);
8585
$signatureHash['Policy'] = $this->encode($policy);
8686
} elseif ($resource && $expires) {
87+
self::validateResourceUrl($resource);
8788
$expires = (int) $expires; // Handle epoch passed as string
8889
$policy = $this->createCannedPolicy($resource, $expires);
8990
$signatureHash['Expires'] = $expires;

src/CloudFront/UrlSigner.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ private function createResource($scheme, $url)
101101
$parts = parse_url($url);
102102
$pathParts = pathinfo($parts['path']);
103103
$resource = ltrim(
104-
$pathParts['dirname'] . '/' . $pathParts['basename'],
104+
str_replace('\\', '/', $pathParts['dirname']) . '/' . $pathParts['basename'],
105105
'/'
106106
);
107107

tests/CloudFront/SignerTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,18 @@ public function testValidatesCustomPolicy(string $resourceUrl)
188188
$this->instance->getSignature(null, null, $policy);
189189
}
190190

191+
/**
192+
* @dataProvider invalidResourceUrlProvider
193+
*/
194+
public function testValidatesInvalidURLs(string $resourceUrl)
195+
{
196+
$this->expectException(\InvalidArgumentException::class);
197+
$this->expectExceptionMessage('URL contains invalid characters: ", \\, or control characters');
198+
199+
$expires = time() + 3600;
200+
$this->instance->getSignature($resourceUrl, $expires);
201+
}
202+
191203
public static function invalidResourceUrlProvider(): array
192204
{
193205
return [

0 commit comments

Comments
 (0)