Skip to content

Commit

Permalink
do not allow view-source
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Dec 16, 2024
1 parent 10a744d commit f791ce0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Browsershot.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,13 @@ public function setUrl(string $url): static
{
$url = trim($url);

$unsupportedProtocols = ['file://', 'file:/', 'file:\\', 'file:\\\\'];
$unsupportedProtocols = [
'file://',
'file:/',
'file:\\',
'file:\\\\',
'view-source',
];

foreach ($unsupportedProtocols as $unsupportedProtocol) {
if (str_starts_with(strtolower($url), $unsupportedProtocol)) {
Expand Down
3 changes: 3 additions & 0 deletions tests/BrowsershotTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@
Browsershot::url($url);
})->throws(FileUrlNotAllowed::class)->with([
'file://test',
'File://test',
'file:/test',
'file:\test',
'file:\\test',
'view-source',
'View-Source'
]);

it('will not allow a file url that has leading spaces', function () {
Expand Down

0 comments on commit f791ce0

Please sign in to comment.