File tree Expand file tree Collapse file tree 1 file changed +14
-11
lines changed
Expand file tree Collapse file tree 1 file changed +14
-11
lines changed Original file line number Diff line number Diff 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 ;
You can’t perform that action at this time.
0 commit comments