Skip to content

Commit 8a8a1eb

Browse files
committed
Add basic protection against PHAR deserialization
This also includes an option to disable external file references. This applies to images and fonts. External file references are allowed by default, but future version will disallow by default.
1 parent 08ce6a9 commit 8a8a1eb

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

src/Svg/Document.php

+2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ class Document extends AbstractTag
5353
/** @var \Sabberworm\CSS\CSSList\Document[] */
5454
protected $styleSheets = array();
5555

56+
public $allowExternalReferences = true;
57+
5658
public function loadFile($filename)
5759
{
5860
$this->filename = $filename;

src/Svg/Style.php

+10
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,16 @@ public function fromStyleSheets(AbstractTag $tag, $attributes) {
139139
break;
140140
}
141141
}
142+
143+
if (
144+
\array_key_exists("font-family", $styles)
145+
&& (
146+
\strtolower(\substr($this->href, 0, 7)) === "phar://"
147+
|| ($this->document->allowExternalReferences === false && \strtolower(\substr($this->href, 0, 5)) !== "data:")
148+
)
149+
) {
150+
unset($style["font-family"]);
151+
}
142152
}
143153
}
144154

src/Svg/Tag/Image.php

+4
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ public function start($attributes)
5858

5959
$this->document->getSurface()->transform(1, 0, 0, -1, 0, $height);
6060

61+
if (\strtolower(\substr($this->href, 0, 7)) === "phar://" || ($this->document->allowExternalReferences === false && \strtolower(\substr($this->href, 0, 5) !== "data:"))) {
62+
return;
63+
}
64+
6165
$this->document->getSurface()->drawImage($this->href, $this->x, $this->y, $this->width, $this->height);
6266
}
6367

0 commit comments

Comments
 (0)