alert(1)\"'&\e[31m\x00\u{202E}\u{200B}"; $result = fn(string $id, string $status, string $severity, bool $incomplete = false, array $findings = []) => [ 'id' => $id, 'title' => "Titel $evil", 'category' => "Bereich $evil", 'severity' => $severity, 'status' => $status, 'incomplete' => $incomplete, 'notes' => ["Hinweis $evil"], 'findings' => $findings, 'checked_databases' => ['shop'], ]; $finding = ['database' => "db $evil", 'object' => "obj $evil", 'detail' => "detail $evil"]; $results = [ $result("hba.$evil", 'fail', 'high', true, [$finding, ['database' => null, 'object' => 'Zeile 1', 'detail' => '']]), $result('log.connections', 'fail', 'medium', false, [$finding]), $result('auth.auth_delay', 'fail', 'low', false, [$finding]), $result('x.info_fail', 'fail', 'info', false, [$finding]), $result('code.extensions', 'info', 'info'), $result('os.service_unit', 'pass', 'medium', true), $result('client.pgpass_acl', 'skip', 'low'), $result('os.umask', 'error', 'low'), $result('tls.ssl_enabled', 'pass', 'high'), ]; $counts = ['pass' => 2, 'fail' => 4, 'info' => 1, 'skip' => 1, 'error' => 1, 'incomplete' => 2]; $meta = [ 'tool' => 'pg-harden ' . PG_HARDEN_VERSION, 'mode' => 'server', 'created_at' => "2026-10-28T12:00:00+00:00", 'host' => "h $evil", 'server' => "srv $evil", 'ssl' => false, 'certificate_verified' => false, 'remote' => true, 'server_version' => "18 $evil", 'user' => "usr $evil", 'superuser' => true, 'local_server' => false, 'local_note' => "note $evil", 'databases' => ["shop $evil", 'postgres'], 'refused_databases' => ["geheim $evil" => "kein CONNECT $evil"], 'catalog' => "kat $evil", 'counts' => $counts, 'mapping_disclaimer' => MAPPING_DISCLAIMER, 'notice' => RESPONSIBILITY_NOTICE, 'legal_notice' => LEGAL_NOTICE, ]; $mappings = [ "k $evil" => ['framework' => "Rahmen $evil", 'verified' => false, 'note' => "Notiz $evil", 'controls' => [ ['control' => "A1 $evil", 'title' => "Thema $evil", 'state' => 'Befund', 'rules_clean' => '0 von 1', 'rules' => ["hba.$evil"]], ['control' => 'A2', 'title' => 'Thema', 'state' => "unbekannt $evil", 'rules_clean' => '1 von 1', 'rules' => ['tls.ssl_enabled']], ]], 'leer' => ['framework' => 'Ohne Treffer', 'verified' => true, 'note' => '', 'controls' => []], ]; $report = ['meta' => $meta, 'results' => $results, 'mappings' => $mappings]; // Vergleich (-f): the previous report is a file of unknown origin — unknown severities, hostile names; one finding fixed on a fully // checked rule, one on a rule this run no longer has (not comparable). $previous = $report; $previous['meta']['created_at'] = "gestern $evil"; $previous['results'][1]['severity'] = ['kein', 'Text']; $previous['results'][2]['severity'] = "evil\" class=\"x"; $previous['results'][] = $result("weg.$evil", 'fail', 'critical', false, [$finding]); $previous['results'][1]['findings'][] = ['database' => null, 'object' => "fort $evil"]; $compared = $report; $compared['comparison'] = Verifier::compare($previous, $report); $client = ['meta' => ['mode' => 'client', 'counts' => array_fill_keys(array_keys($counts), 0)] + $meta, 'results' => [], 'mappings' => []]; // Protocols of apply and rollback: plan, journal and server values are just as untrusted. $applyLog = [ 'started_at' => '2026-10-28T12:00:00+00:00', 'finished_at' => '2026-10-28T12:00:09+00:00', 'server' => "srv $evil", 'server_version' => "18 $evil", 'user' => "usr $evil", 'dir' => "/root/j $evil", 'outcome' => 'failed', 'plan' => [ 'conf' => [['rule' => "log.$evil", 'name' => "name $evil", 'value' => "wert $evil", 'restart' => true]], 'hba' => [['rule' => 'hba.trust', 'line' => 117, 'kind' => 'method', 'from' => ["trust $evil"], 'to' => "scram $evil"]], 'sql' => ["db $evil" => [ ['rule' => 'db.public_schema_create', 'object' => 'o', 'fix_sql' => "REVOKE $evil;"], ['rule' => 'code.secdef_search_path', 'object' => 'o', 'fix_sql' => "ALTER $evil;"], ]], 'notes' => ["Hinweis $evil"], ], 'skipped_confirm' => ["hba.$evil"], 'skipped_other' => [["x.$evil", "Grund $evil"]], 'steps' => [ ['at' => '2026-10-28T12:00:01+00:00', 'phase' => "Phase $evil", 'status' => 'OK', 'message' => "ok $evil"], ['at' => "zeit $evil", 'phase' => 'SQL', 'status' => "unbekannt $evil", 'message' => "fehler $evil"], ], 'files' => [['path' => "/etc/$evil", 'action' => 'modified', 'backup' => "backup/01-$evil"], ['path' => '/x', 'action' => 'created', 'backup' => null]], 'sql' => [['database' => "db $evil", 'rule' => 'db.public_schema_create', 'fix_sql' => "REVOKE $evil;", 'rollback_sql' => null, 'status' => 'committed']], 'before_counts' => $counts, 'after' => $compared, 'post_error' => null, ]; $aborted = ['outcome' => 'aborted', 'finished_at' => null, 'after' => null, 'post_error' => "kaputt $evil", 'steps' => [], 'files' => [], 'sql' => []] + $applyLog; $aborted['plan'] = ['conf' => [], 'hba' => [], 'sql' => [], 'notes' => []]; $rollbackLog = [ 'started_at' => '2026-10-28T13:00:00+00:00', 'finished_at' => '2026-10-28T13:00:02+00:00', 'server' => "srv $evil", 'server_version' => '18', 'user' => 'postgres', 'dir' => "/root/j $evil", 'apply_started_at' => "apply $evil", 'ok' => false, 'log_file' => 'rollback-attempt-1.json', 'steps' => [['status' => 'FEHLER', 'message' => "nicht $evil"], ['status' => 'WARNUNG', 'message' => 'w']], ]; $cases = ['check' => $report, 'check -f' => $compared, 'client' => $client]; $pages = []; foreach ($cases as $name => $r) { try { $pages[$name] = HtmlRenderer::render($r); $check("$name: Textbericht entsteht", TextRenderer::render($r) !== ''); } catch (Throwable $e) { $check("$name: rendert ohne Fehler ({$e->getMessage()})", false); } } foreach (['apply' => fn() => HtmlRenderer::applyLog($applyLog), 'apply-abgebrochen' => fn() => HtmlRenderer::applyLog($aborted), 'rollback' => fn() => HtmlRenderer::rollbackLog($rollbackLog), 'rollback-ok' => fn() => HtmlRenderer::rollbackLog(['ok' => true] + $rollbackLog)] as $name => $make) { try { $pages[$name] = $make(); } catch (Throwable $e) { $check("$name: rendert ohne Fehler ({$e->getMessage()})", false); } } foreach ($pages as $name => $html) { // One stylesheet, admitted by its hash; nothing else may load or run. $check("$name: genau ein style-Element", substr_count($html, '') === 1); preg_match('~~s', $html, $style); preg_match('~~', $html, $csp); $check("$name: CSP vorhanden", isset($csp[1])); $check("$name: CSP default-src 'none' und Hash des Stylesheets", isset($csp[1], $style[1]) && $csp[1] === "default-src 'none'; style-src 'sha256-" . base64_encode(hash('sha256', $style[1], true)) . "'; base-uri 'none'; form-action 'none'"); // Every tag outside the stylesheet: known element, known attribute, nothing else (escaped text holds no "<"). $markup = str_replace($style[0] ?? '', '', $html); $elements = ['!doctype', 'html', 'head', 'meta', 'title', 'body', 'header', 'nav', 'main', 'section', 'footer', 'h1', 'h2', 'h3', 'p', 'span', 'div', 'dl', 'dt', 'dd', 'ol', 'ul', 'li', 'a', 'code', 'strong', 'svg', 'rect', 'table', 'thead', 'tbody', 'tr', 'th', 'td']; $attributes = ['lang', 'charset', 'name', 'content', 'http-equiv', 'class', 'id', 'href', 'aria-label', 'aria-hidden', 'role', 'scope', 'data-label', 'width', 'height', 'x', 'y', 'html']; preg_match_all('~<(/?)([^\s>/]+)([^>]*)>~', $markup, $tags, PREG_SET_ORDER); $badTags = []; foreach ($tags as [$tag, , $element, $rest]) { preg_match_all('~\s([^\s=]+)(?:="[^"]*")?~', $rest, $attr); if (!in_array(strtolower($element), $elements, true) || array_diff($attr[1], $attributes, ['/']) !== []) { $badTags[] = $tag; } } $check("$name: nur bekannte Elemente und Attribute (" . implode(' ', array_slice($badTags, 0, 3)) . ')', $badTags === []); $check("$name: kein < im Text", substr_count($markup, '<') === count($tags)); $check("$name: Stylesheet ohne externe Bezüge", !preg_match('~url\(|@import|https?:|<~i', $style[1] ?? '')); preg_match_all('~href="([^"]*)"~', $html, $hrefs); $check("$name: nur Sprungmarken innerhalb der Datei", array_filter($hrefs[1], fn($h) => preg_match('~^#[a-z0-9-]+$~', $h) !== 1) === []); // Every value escaped: no raw markup, no control or format character survives. $check("$name: Werte maskiert", !str_contains($html, '