1<?php
2
3namespace Mpdf\File;
4
5use Mpdf\Mpdf;
6
7final class StreamWrapperChecker
8{
9
10	private $mpdf;
11
12	public function __construct(Mpdf $mpdf)
13	{
14		$this->mpdf = $mpdf;
15	}
16
17	/**
18	 * @param string $filename
19	 * @return bool
20	 * @since 7.1.8
21	 */
22	public function hasBlacklistedStreamWrapper($filename)
23	{
24		if (strpos($filename, '://') > 0) {
25			$wrappers = stream_get_wrappers();
26			$whitelistStreamWrappers = $this->getWhitelistedStreamWrappers();
27			foreach ($wrappers as $wrapper) {
28				if (in_array($wrapper, $whitelistStreamWrappers)) {
29					continue;
30				}
31
32				if (stripos($filename, $wrapper . '://') === 0) {
33					return true;
34				}
35			}
36		}
37
38		return false;
39	}
40
41	public function getWhitelistedStreamWrappers()
42	{
43		return array_diff($this->mpdf->whitelistStreamWrappers, ['phar']); // remove 'phar' (security issue)
44	}
45
46}
47