Skip to content

Commit

Permalink
add security on scheme of css and image paths
Browse files Browse the repository at this point in the history
  • Loading branch information
spipu committed Dec 16, 2021
1 parent 100a4d5 commit 2e6bab9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
## [5.2.4](https://github.com/spipu/html2pdf/compare/v5.2.3...master) - unreleased

* revert fix multibyte aware substr when setting newline position - it causes pbs on some specific cases
* add security on scheme of css and image paths
* add security on scheme of css and image paths - thanks to Clément Amic and Antoine Gicquel from [Synacktiv](https://www.synacktiv.com/)

## [5.2.3](https://github.com/spipu/html2pdf/compare/v5.2.2...v5.2.3) - 2021-10-19

Expand Down
9 changes: 4 additions & 5 deletions src/Parsing/Css.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Css
public $cssKeys = array(); // css key, for the execution order
public $table = array(); // level history

protected $unauthorizedSchemes = ['php://', 'zlib://', 'data://', 'glob://', 'phar://'];
protected $authorizedSchemes = ['file', 'http', 'https'];

This comment has been minimized.

Copy link
@textrixx

textrixx Dec 30, 2021

This leads to an exception on windows based development systems, because the drive label (e.g. c) will be used as scheme. I'm running laravel for windows on my mobile device.


/**
* Constructor
Expand Down Expand Up @@ -1763,10 +1763,9 @@ private function removeStyleTag(array $match)
public function checkValidPath($path)
{
$path = trim(strtolower($path));
foreach ($this->unauthorizedSchemes as $unauthorizedScheme) {
if (substr($path, 0, strlen($unauthorizedScheme)) === $unauthorizedScheme) {
throw new HtmlParsingException('Unauthorized path scheme');
}
$scheme = parse_url($path, PHP_URL_SCHEME);
if ($scheme !== null && !in_array($scheme, $this->authorizedSchemes)) {
throw new HtmlParsingException('Unauthorized path scheme');
}
}
}

0 comments on commit 2e6bab9

Please sign in to comment.