File tree 1 file changed +14
-11
lines changed
1 file changed +14
-11
lines changed Original file line number Diff line number Diff line change @@ -68,6 +68,15 @@ class Browsershot
68
68
69
69
protected ImageManipulations $ imageManipulations ;
70
70
71
+ protected array $ unsafeProtocols = [
72
+ 'file:, ' ,
73
+ 'file:/ ' ,
74
+ 'file:// ' ,
75
+ 'file: \\' ,
76
+ 'file: \\\\' ,
77
+ 'view-source ' ,
78
+ ];
79
+
71
80
public static function url (string $ url ): static
72
81
{
73
82
return (new static )->setUrl ($ url );
@@ -259,15 +268,7 @@ public function setUrl(string $url): static
259
268
{
260
269
$ url = trim ($ url );
261
270
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 ) {
271
272
if (str_starts_with (strtolower ($ url ), $ unsupportedProtocol )) {
272
273
throw FileUrlNotAllowed::make ();
273
274
}
@@ -301,8 +302,10 @@ public function setProxyServer(string $proxyServer): static
301
302
302
303
public function setHtml (string $ html ): static
303
304
{
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
+ }
306
309
}
307
310
308
311
$ this ->html = $ html ;
You can’t perform that action at this time.
0 commit comments