|
23 | 23 | use Spipu\Html2Pdf\Parsing\Node; |
24 | 24 | use Spipu\Html2Pdf\Parsing\TagParser; |
25 | 25 | use Spipu\Html2Pdf\Parsing\TextParser; |
| 26 | +use Spipu\Html2Pdf\Security\Security; |
| 27 | +use Spipu\Html2Pdf\Security\SecurityInterface; |
26 | 28 | use Spipu\Html2Pdf\Tag\TagInterface; |
27 | 29 | use Spipu\Html2Pdf\Debug\DebugInterface; |
28 | 30 | use Spipu\Html2Pdf\Debug\Debug; |
@@ -69,6 +71,11 @@ class Html2Pdf |
69 | 71 | */ |
70 | 72 | private $svgDrawer; |
71 | 73 |
|
| 74 | + /** |
| 75 | + * @var SecurityInterface |
| 76 | + */ |
| 77 | + private $security; |
| 78 | + |
72 | 79 | protected $_langue = 'fr'; // locale of the messages |
73 | 80 | protected $_orientation = 'P'; // page orientation : Portrait ou Landscape |
74 | 81 | protected $_format = 'A4'; // page format : A4, A3, ... |
@@ -199,13 +206,18 @@ public function __construct( |
199 | 206 | // load the Locale |
200 | 207 | Locale::load($this->_langue); |
201 | 208 |
|
202 | | - // create the myPdf object |
| 209 | + $this->security = new Security(); |
203 | 210 | $this->pdf = new MyPdf($orientation, 'mm', $format, $unicode, $encoding, false, $pdfa); |
204 | 211 |
|
205 | | - // init the CSS parsing object |
206 | 212 | $this->cssConverter = new CssConverter(); |
207 | 213 | $textParser = new TextParser($encoding); |
208 | | - $this->parsingCss = new Parsing\Css($this->pdf, new TagParser($textParser), $this->cssConverter); |
| 214 | + |
| 215 | + $this->parsingCss = new Parsing\Css( |
| 216 | + $this->pdf, |
| 217 | + new TagParser($textParser), |
| 218 | + $this->cssConverter, |
| 219 | + $this->security |
| 220 | + ); |
209 | 221 | $this->parsingCss->fontSet(); |
210 | 222 | $this->_defList = array(); |
211 | 223 |
|
@@ -247,7 +259,7 @@ public function getVersionAsArray() |
247 | 259 | return array( |
248 | 260 | 'major' => 5, |
249 | 261 | 'minor' => 3, |
250 | | - 'revision' => 0 |
| 262 | + 'revision' => 1, |
251 | 263 | ); |
252 | 264 | } |
253 | 265 |
|
@@ -275,6 +287,19 @@ public function __clone() |
275 | 287 | $this->parsingCss->setPdfParent($this->pdf); |
276 | 288 | } |
277 | 289 |
|
| 290 | + /** |
| 291 | + * Use a specific security interface |
| 292 | + * @param SecurityInterface $security |
| 293 | + * @return $this |
| 294 | + */ |
| 295 | + public function setSecurityService(SecurityInterface $security): self |
| 296 | + { |
| 297 | + $this->security = $security; |
| 298 | + $this->parsingCss->setSecurityService($security); |
| 299 | + |
| 300 | + return $this; |
| 301 | + } |
| 302 | + |
278 | 303 | /** |
279 | 304 | * Set the max number of lines for a sentence |
280 | 305 | * |
@@ -1509,14 +1534,14 @@ protected function _makeBreakLine($h, $curr = null) |
1509 | 1534 | protected function _drawImage($src, $subLi = false) |
1510 | 1535 | { |
1511 | 1536 | // get the size of the image |
1512 | | - // WARNING : if URL, "allow_url_fopen" must turned to "on" in php.ini |
| 1537 | + // WARNING : if URL, "allow_url_fopen" must turn to "on" in php.ini |
1513 | 1538 |
|
1514 | 1539 | if (strpos($src,'data:') === 0) { |
1515 | 1540 | $src = base64_decode( preg_replace('#^data:image/[^;]+;base64,#', '', $src) ); |
1516 | 1541 | $infos = @getimagesizefromstring($src); |
1517 | 1542 | $src = "@{$src}"; |
1518 | 1543 | } else { |
1519 | | - $this->parsingCss->checkValidPath($src); |
| 1544 | + $this->security->checkValidPath((string) $src); |
1520 | 1545 | $infos = @getimagesize($src); |
1521 | 1546 | } |
1522 | 1547 |
|
@@ -5806,13 +5831,15 @@ protected function _tag_open_CERT($param) |
5806 | 5831 | } |
5807 | 5832 |
|
5808 | 5833 | // set certificate file |
5809 | | - $certificate = $param['src']; |
| 5834 | + $certificate = (string) $param['src']; |
| 5835 | + $this->security->checkValidPath($certificate); |
5810 | 5836 | if(!file_exists($certificate)) { |
5811 | 5837 | return true; |
5812 | 5838 | } |
5813 | 5839 |
|
5814 | 5840 | // Set private key |
5815 | | - $privkey = $param['privkey']; |
| 5841 | + $privkey = (string) $param['privkey']; |
| 5842 | + $this->security->checkValidPath($privkey); |
5816 | 5843 | if(strlen($privkey)==0 || !file_exists($privkey)) { |
5817 | 5844 | $privkey = $certificate; |
5818 | 5845 | } |
|
0 commit comments