Skip to content

Commit ec483ed

Browse files
committed
fix(security): disallow file extensions start with php
1 parent 8170760 commit ec483ed

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/LfmUploadValidator.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ public function extensionIsNotExcutable($excutable_extensions)
8181
throw new ExcutableFileException();
8282
}
8383

84+
if (strpos($extension, 'php') === 0) {
85+
throw new ExcutableFileException();
86+
}
87+
8488
return $this;
8589
}
8690

tests/LfmUploadValidatorTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,18 @@ public function testFailsExtensionIsNotExcutableWithExtensionNotLowerCase()
168168
$validator->extensionIsNotExcutable(['php', 'html']);
169169
}
170170

171+
public function testFailsExtensionIsNotExcutableWithExtensionsStartsWithPhp()
172+
{
173+
$uploaded_file = m::mock(UploadedFile::class);
174+
$uploaded_file->shouldReceive('getClientOriginalExtension')->andReturn('php8');
175+
176+
$validator = new LfmUploadValidator($uploaded_file);
177+
178+
$this->expectException(ExcutableFileException::class);
179+
180+
$validator->extensionIsNotExcutable(['php', 'html']);
181+
}
182+
171183
public function testFailsExtensionIsValidWithSpecialCharacters()
172184
{
173185
$uploaded_file = m::mock(UploadedFile::class);

0 commit comments

Comments
 (0)