From 1454c516e6b2e90af79805da56f98511a7ec17e7 Mon Sep 17 00:00:00 2001 From: Thiago Date: Wed, 16 Aug 2023 11:25:20 -0300 Subject: [PATCH 1/4] fix: include insensitive case to get content-type in header filters --- src/Filter/WebFileExtensionFilter.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Filter/WebFileExtensionFilter.php b/src/Filter/WebFileExtensionFilter.php index 9253528..0f5ac2b 100644 --- a/src/Filter/WebFileExtensionFilter.php +++ b/src/Filter/WebFileExtensionFilter.php @@ -31,12 +31,12 @@ public function __construct($allowedExtensions) public function applyHeaderFilter(array $headers) { - if(!array_key_exists('Content-Type', $headers) && count($headers['Content-Type']) > 0){ + $contentType = $headers['Content-Type'][0] ?? $headers['content-type'][0] ?? null; + if($contentType == null) { throw new \Exception('Invalid headers for FileExtension applyHeaderFilter'); } - $headerType = $headers['Content-Type'][0]; - if(!ArrayTool::inArrayRecursive(strtolower($headerType), $this->formats)) { - throw new FileExtensionException('Invalid file extension file: '.$headerType); + if(!ArrayTool::inArrayRecursive(strtolower($contentType), $this->formats)) { + throw new FileExtensionException('Invalid file extension file: '.$contentType); } } From b3adf7476cb3d18b11d2321b9af5e0869b724b2c Mon Sep 17 00:00:00 2001 From: Thiago Date: Wed, 16 Aug 2023 12:18:27 -0300 Subject: [PATCH 2/4] fix: check if content-type has values before access it --- src/Filter/WebFileExtensionFilter.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Filter/WebFileExtensionFilter.php b/src/Filter/WebFileExtensionFilter.php index 0f5ac2b..4ef9560 100644 --- a/src/Filter/WebFileExtensionFilter.php +++ b/src/Filter/WebFileExtensionFilter.php @@ -30,13 +30,15 @@ public function __construct($allowedExtensions) } - public function applyHeaderFilter(array $headers) { - $contentType = $headers['Content-Type'][0] ?? $headers['content-type'][0] ?? null; - if($contentType == null) { + public function applyHeaderFilter(array $headers) { + $contentType = $headers['Content-Type'] ?? $headers['content-type'] ?? null; + + if ($contentType == null || count($contentType) == 0) { throw new \Exception('Invalid headers for FileExtension applyHeaderFilter'); } - if(!ArrayTool::inArrayRecursive(strtolower($contentType), $this->formats)) { - throw new FileExtensionException('Invalid file extension file: '.$contentType); + $fileExtension = $contentType[0]; + if(!ArrayTool::inArrayRecursive(strtolower($fileExtension), $this->formats)) { + throw new FileExtensionException('Invalid file extension file: '.$fileExtension); } } From 3ef392b3c18583dcf347465adb03cc74043cca7a Mon Sep 17 00:00:00 2001 From: Thiago Date: Wed, 16 Aug 2023 14:33:18 -0300 Subject: [PATCH 3/4] fix: check if content type is set before access --- src/Filter/WebFileExtensionFilter.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Filter/WebFileExtensionFilter.php b/src/Filter/WebFileExtensionFilter.php index 4ef9560..b79b7e6 100644 --- a/src/Filter/WebFileExtensionFilter.php +++ b/src/Filter/WebFileExtensionFilter.php @@ -31,10 +31,13 @@ public function __construct($allowedExtensions) public function applyHeaderFilter(array $headers) { + if (!array_key_exists('Content-Type', $headers) && !array_key_exists('content-type', $headers)) { + throw new \Exception('Invalid headers for FileExtension applyHeaderFilter'); + } $contentType = $headers['Content-Type'] ?? $headers['content-type'] ?? null; if ($contentType == null || count($contentType) == 0) { - throw new \Exception('Invalid headers for FileExtension applyHeaderFilter'); + throw new \Exception('Missing or empty Content-Type on response header'); } $fileExtension = $contentType[0]; if(!ArrayTool::inArrayRecursive(strtolower($fileExtension), $this->formats)) { From 2eabc5bff3af66e161bd64f8c85f707a47a76028 Mon Sep 17 00:00:00 2001 From: Thiago Date: Wed, 16 Aug 2023 14:34:50 -0300 Subject: [PATCH 4/4] fix psr --- src/Filter/WebFileExtensionFilter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Filter/WebFileExtensionFilter.php b/src/Filter/WebFileExtensionFilter.php index b79b7e6..d279d9a 100644 --- a/src/Filter/WebFileExtensionFilter.php +++ b/src/Filter/WebFileExtensionFilter.php @@ -40,7 +40,7 @@ public function applyHeaderFilter(array $headers) { throw new \Exception('Missing or empty Content-Type on response header'); } $fileExtension = $contentType[0]; - if(!ArrayTool::inArrayRecursive(strtolower($fileExtension), $this->formats)) { + if (!ArrayTool::inArrayRecursive(strtolower($fileExtension), $this->formats)) { throw new FileExtensionException('Invalid file extension file: '.$fileExtension); } }