Skip to content

Commit

Permalink
fix(security): disallow file extensions end with html
Browse files Browse the repository at this point in the history
  • Loading branch information
streamtw committed Aug 9, 2024
1 parent ec483ed commit 6b3adbc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/LfmUploadValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ public function extensionIsNotExcutable($excutable_extensions)
throw new ExcutableFileException();
}

if (preg_match('/[a-z]html/', $extension) > 0) {
throw new ExcutableFileException();
}

return $this;
}

Expand Down
12 changes: 12 additions & 0 deletions tests/LfmUploadValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,18 @@ public function testFailsExtensionIsNotExcutableWithExtensionsStartsWithPhp()
$validator->extensionIsNotExcutable(['php', 'html']);
}

public function testFailsExtensionIsNotExcutableWithExtensionsEndsWithHtml()
{
$uploaded_file = m::mock(UploadedFile::class);
$uploaded_file->shouldReceive('getClientOriginalExtension')->andReturn('dhtml');

$validator = new LfmUploadValidator($uploaded_file);

$this->expectException(ExcutableFileException::class);

$validator->extensionIsNotExcutable();
}

public function testFailsExtensionIsValidWithSpecialCharacters()
{
$uploaded_file = m::mock(UploadedFile::class);
Expand Down

0 comments on commit 6b3adbc

Please sign in to comment.