Skip to content

Commit dfc3635

Browse files
committed
improve detection of file urls
1 parent fae8396 commit dfc3635

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

Diff for: src/Browsershot.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,12 @@ public function setUrl(string $url): static
259259
{
260260
$url = trim($url);
261261

262-
if (str_starts_with(strtolower($url), 'file://') || str_starts_with(strtolower($url), 'file:/')) {
263-
throw FileUrlNotAllowed::make();
262+
$unsupportedProtocols = ['file://', 'file:/', 'file:\\', 'file:\\\\'];
263+
264+
foreach($unsupportedProtocols as $unsupportedProtocol) {
265+
if (str_starts_with(strtolower($url), $unsupportedProtocol)) {
266+
throw FileUrlNotAllowed::make();
267+
}
264268
}
265269

266270
$this->url = $url;

Diff for: tests/BrowsershotTest.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,12 @@
5454

5555
it('will not allow a file url', function () {
5656
Browsershot::url('file://test');
57-
})->throws(FileUrlNotAllowed::class);
57+
})->throws(FileUrlNotAllowed::class)->with([
58+
'file://test',
59+
'file:/test',
60+
'file:\test',
61+
'file:\\test',
62+
]);
5863

5964
it('will not allow a file url that has leading spaces', function () {
6065
Browsershot::url(' file://test');

0 commit comments

Comments
 (0)