Skip to content

Commit bcfd608

Browse files
committed
disallow file:
1 parent 445f6c8 commit bcfd608

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/Browsershot.php

+14-11
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ class Browsershot
6868

6969
protected ImageManipulations $imageManipulations;
7070

71+
protected array $unsafeProtocols = [
72+
'file:,',
73+
'file:/',
74+
'file://',
75+
'file:\\',
76+
'file:\\\\',
77+
'view-source',
78+
];
79+
7180
public static function url(string $url): static
7281
{
7382
return (new static)->setUrl($url);
@@ -259,15 +268,7 @@ public function setUrl(string $url): static
259268
{
260269
$url = trim($url);
261270

262-
$unsupportedProtocols = [
263-
'file://',
264-
'file:/',
265-
'file:\\',
266-
'file:\\\\',
267-
'view-source',
268-
];
269-
270-
foreach ($unsupportedProtocols as $unsupportedProtocol) {
271+
foreach ($this->unsafeProtocols as $unsupportedProtocol) {
271272
if (str_starts_with(strtolower($url), $unsupportedProtocol)) {
272273
throw FileUrlNotAllowed::make();
273274
}
@@ -301,8 +302,10 @@ public function setProxyServer(string $proxyServer): static
301302

302303
public function setHtml(string $html): static
303304
{
304-
if (str_contains(strtolower($html), 'file://') || str_contains(strtolower($html), 'file:/')) {
305-
throw HtmlIsNotAllowedToContainFile::make();
305+
foreach ($this->unsafeProtocols as $protocol) {
306+
if (str_contains(strtolower($html), $protocol)) {
307+
throw HtmlIsNotAllowedToContainFile::make();
308+
}
306309
}
307310

308311
$this->html = $html;

0 commit comments

Comments
 (0)