/**
* Security audit 2026-12: one block per vulnerability class, each asking the plugin's own building blocks with the
* payloads that class is known for (docs/security.md → "Security suites"). The HTTP side of the same classes runs
* against a BUILT site in reference/e2e/attack-probes.spec.ts.
*
* A finding of the audit that is not fixed yet is an `it.fails` naming it (security-audit-2026-12-findings.md):
* the test states the SAFE behaviour, so the day the fix lands vitest says the test "passed unexpectedly" and the
* `.fails` goes. The same convention as `openFor` in the closed-doors spec. Every finding of the 2026-12 audit is
* fixed in 1.18.0: no `.fails` is left.
*/
import { Script } from 'node:vm'
import { createElement } from 'react'
import { renderToStaticMarkup } from 'react-dom/server'
import { describe, expect, it, vi } from 'vitest'
import { adminPathFromReferer } from '../src/modules/branding/signIn/languageEndpoint.js'
import { consentDecidedScript } from '../src/modules/consent/firstPaint.js'
import { parseConsent, readConsentRecord } from '../src/modules/consent/storage.js'
import { markdownResponse } from '../src/modules/content/createMarkdownRenderer.js'
import { MARKDOWN_NEGOTIATED_HEADER } from '../src/modules/content/markdownNegotiation.js'
import { createProxy } from '../src/modules/i18n/createProxy.js'
import { buildUrlField, isAllowedUrl } from '../src/modules/links/buildUrlField.js'
import { safeHref } from '../src/modules/links/resolveLinkHref.js'
import { createMcpRoute } from '../src/modules/mcp/createMcpRoute.js'
import { sanitizeRichTextLinks } from '../src/modules/richtext/sanitizeLinks.js'
import { createCspReportRoute, CSP_LOG_VALUE_MAX, cspLogLine } from '../src/modules/security/createCspReportRoute.js'
import { applyLockedDocumentsAccess, buildQueryGuardHook, capListLimit, isOperatorSort, LOCKED_DOCUMENTS_SLUG } from '../src/modules/security/queryGuard.js'
import { safeAdminBack } from '../src/modules/security/totp/safeBack.js'
import { buildSitemapXml } from '../src/modules/seo/buildSitemapXml.js'
import { JsonLdGraph } from '../src/modules/seo/JsonLdGraph.js'
import { themeScript } from '../src/modules/theme/theme.js'
/** Strings that end a script, open markup, or run as a URL — the XSS payloads used below. */
const XSS = ['', '', '">