mirror of
https://github.com/ZoneMinder/zoneminder.git
synced 2026-11-30 12:14:36 -05:00
* fix: html_input and filter terms escape their values and attributes refs #7458 * fix: filter bar also escapes a term's id, placeholder and Date data-cookie refs #7458
60 lines
1.6 KiB
PHP
60 lines
1.6 KiB
PHP
<?php
|
|
|
|
$repoRoot = $argv[1] ?? realpath(__DIR__.'/../..');
|
|
|
|
$functionsFile = $repoRoot.'/web/includes/functions.php';
|
|
$source = file_get_contents($functionsFile);
|
|
if ($source === false) {
|
|
fwrite(STDERR, "Could not read $functionsFile\n");
|
|
exit(1);
|
|
}
|
|
|
|
foreach (['validHtmlStr', 'html_input'] as $functionName) {
|
|
$pattern = '/function\s+'.preg_quote($functionName, '/').'\b.*?\n}\n/s';
|
|
if (!preg_match($pattern, $source, $matches)) {
|
|
fwrite(STDERR, "Could not extract $functionName from $functionsFile\n");
|
|
exit(1);
|
|
}
|
|
eval($matches[0]);
|
|
}
|
|
|
|
$failures = 0;
|
|
|
|
function check($label, $cond) {
|
|
global $failures;
|
|
if ($cond) {
|
|
echo " ok - $label\n";
|
|
} else {
|
|
echo " NOT OK - $label\n";
|
|
$failures++;
|
|
}
|
|
}
|
|
|
|
$html = html_input('filter[Query][terms][0][op]', 'hidden', '"><script>alert(1)</script>');
|
|
check(
|
|
'script tag in value is escaped',
|
|
strpos($html, '<script>') === false
|
|
&& strpos($html, '"><script>') !== false
|
|
);
|
|
|
|
$html = html_input('a', 'hidden', 'x" onfocus="alert(1)');
|
|
check(
|
|
'double quote breakout in value is escaped',
|
|
strpos($html, 'onfocus="') === false && substr_count($html, '"') === 6
|
|
);
|
|
|
|
$html = html_input('a"b', 'hidden', 'v');
|
|
check('name is escaped', strpos($html, 'name="a"b"') !== false);
|
|
|
|
$html = html_input('a', 'text', 'v', ['class' => 'x"y']);
|
|
check('option values are escaped', strpos($html, 'class="x"y"') !== false);
|
|
|
|
$html = html_input('n', 'hidden', 'v');
|
|
check(
|
|
'normal output is unchanged',
|
|
$html === '<input name="n" value="v" type="hidden"/>'
|
|
);
|
|
|
|
echo "5 tests, $failures failures\n";
|
|
exit($failures === 0 ? 0 : 1);
|