Skip to content

Commit 6b3adbc

Browse files
committed
fix(security): disallow file extensions end with html
1 parent ec483ed commit 6b3adbc

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
@@ -85,6 +85,10 @@ public function extensionIsNotExcutable($excutable_extensions)
8585
throw new ExcutableFileException();
8686
}
8787

88+
if (preg_match('/[a-z]html/', $extension) > 0) {
89+
throw new ExcutableFileException();
90+
}
91+
8892
return $this;
8993
}
9094

tests/LfmUploadValidatorTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,18 @@ public function testFailsExtensionIsNotExcutableWithExtensionsStartsWithPhp()
180180
$validator->extensionIsNotExcutable(['php', 'html']);
181181
}
182182

183+
public function testFailsExtensionIsNotExcutableWithExtensionsEndsWithHtml()
184+
{
185+
$uploaded_file = m::mock(UploadedFile::class);
186+
$uploaded_file->shouldReceive('getClientOriginalExtension')->andReturn('dhtml');
187+
188+
$validator = new LfmUploadValidator($uploaded_file);
189+
190+
$this->expectException(ExcutableFileException::class);
191+
192+
$validator->extensionIsNotExcutable();
193+
}
194+
183195
public function testFailsExtensionIsValidWithSpecialCharacters()
184196
{
185197
$uploaded_file = m::mock(UploadedFile::class);

0 commit comments

Comments
 (0)