'\nLIMIT 1"; } } } namespace { $root = isset($argv[1]) ? rtrim($argv[1], '/') : __DIR__.'/../..'; function canEdit($a) { return true; } function canView($a) { return true; } function validInt($i) { return (int)$i; } function validHtmlStr($s) { return htmlspecialchars((string)$s, ENT_QUOTES); } function translate($s) { return $s; } function ajaxError($m) { throw new RuntimeException($m); } function getCSRFinputHTML() { return ''; } function dbFetchAll($sql) { return array(); } function htmlSelect($name, $options, $selected) { return ''; } $tests = 0; $failures = 0; function check($label, $cond) { global $tests, $failures; $tests++; if ($cond) { echo " ok - $label\n"; } else { $failures++; echo " FAIL - $label\n"; } } $tmpDir = sys_get_temp_dir().'/zm_modal_esc_'.getmypid(); $includesDir = $tmpDir.'/includes'; if (!is_dir($includesDir)) mkdir($includesDir, 0777, true); file_put_contents($includesDir.'/Server.php', "alert(1)' : ''; } } PHP ); $oldIncludePath = get_include_path(); set_include_path($tmpDir.PATH_SEPARATOR.$oldIncludePath); function zm_modal_esc_rmdir($dir) { if (!is_dir($dir)) return; foreach (scandir($dir) as $entry) { if ($entry === '.' || $entry === '..') continue; $path = $dir.'/'.$entry; if (is_dir($path)) zm_modal_esc_rmdir($path); else @unlink($path); } @rmdir($dir); } register_shutdown_function(function() use ($tmpDir, $oldIncludePath) { set_include_path($oldIncludePath); zm_modal_esc_rmdir($tmpDir); }); // (a) Storage modal: the storage area name must be escaped in the header. $_REQUEST = array('id' => '3'); $Servers = array(); ob_start(); try { include $root.'/web/ajax/modals/storage.php'; } catch (Throwable $e) { // Later parts of the modal may call helpers that are not stubbed here. } $html = ob_get_clean(); check('storage name is escaped', strpos($html, '<script>alert(1)</script>') !== false); check('storage name is not emitted raw', strpos($html, '') === false); // (b) Filter debug modal: the SQL text must be escaped, newlines still become //
. $_REQUEST = array('fid' => '4'); ob_start(); try { include $root.'/web/ajax/modals/filterdebug.php'; } catch (Throwable $e) { // Same rationale as above. } $html = ob_get_clean(); check('debug SQL markup is not emitted raw', strpos($html, '', strpos($html, '
') !== false); echo "\n$tests tests, $failures failures\n"; exit($failures ? 1 : 0); }