Security suites from the 2026-12 audit: static rules, attack probes, per-class tests, gate

- doctor: code-patterns (unescaped HTML/JSON-LD, eval, shell, NEXT_PUBLIC_ secrets,
  overrideAccess / Local API user, where from the request, redirects and fetches to a
  request address) and config-dangerous; live-probes runs the safe attack probes on --url
- ATTACK_PROBES / runAttackProbes / createProbeContext exported from /doctor; the reference
  site runs all of them in pnpm e2e:built (both bundlers) plus CSRF and cookie flags;
  project template iapl-audit/resources/attack-probes.spec.template.ts
- test/securityPatterns.test.ts gates every hit against test/security-patterns.allow.json;
  test/securityClasses.test.ts covers XSS, redirects, pollution, logs, DoS, cache poisoning
- pnpm security:gate (pnpm audit --prod, the two suites, optional offline ZAP) in prepublishOnly
- audit findings F1, F3, F4, F5 reproduced as expected-to-fail tests/probes; no fix built
- docs: security.md threat list + Security suites, doctor.md, AGENT.md, CHANGELOG, skills

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-12-01 16:46:42 +01:00
co-authored by Claude Opus 5.5
parent a416411f01
commit d2f19095dc
25 changed files with 1400 additions and 5 deletions
+5 -2
View File
@@ -19,7 +19,10 @@
* staff sign-in from another origin refused);
* e2e/sign-in-answers.spec.ts (1.17.2: a locked staff account answers like a wrong password; the panel actions refuse
* another origin), e2e/two-factor-enrolment.spec.ts (1.18.0: the first 2FA set-up waits for the e-mailed link,
* read from the mail sink; the password alone no longer enrols a factor).
* read from the mail sink; the password alone no longer enrols a factor), e2e/attack-probes.spec.ts (security audit
* 2026-12: the plugin's ATTACK_PROBES — secret files, bundle secrets, proxy bypass, open redirect, host-header and
* negotiation cache poisoning, NoSQL operators, where/draft/GraphQL access, error leaks, unbounded lists, the image
* optimizer, headers, methods, 8 MB bodies — plus CSRF and the session cookie's flags).
* 4. e2e/performance.spec.ts (1.18.0): the performance budgets — LCP, CLS, Total Blocking Time, the response to a tap,
* JS / CSS / font bytes, requests, render-blocking resources and third parties before consent for every page type,
* on a throttled phone and a desktop, and the MongoDB queries of one render (docs/performance.md).
@@ -100,7 +103,7 @@ for (const bundler of bundlers) {
process.exit(1)
}
console.log(`[e2e:built] ✓ ${bundler}: no package manifest among ${files.length} public files`)
run(`${bundler}: the built site — late-staff spec, the mail service, closed doors, the published-files check, the client hints, consent, the sign-in look, the sign-in answers, the own account and the unused-files notice`, 'pnpm', ['exec', 'playwright', 'test', 'late-staff', 'mail-relay', 'closed-doors', 'smoke', 'sign-in-look', 'sign-in-answers', 'own-account', 'two-factor-enrolment', 'unused-media', '--grep', 'unused-files notice|2FA enrolment|late staff collection|the mail service|closed doors|no package.json is published|client hints|consent|sign-in look|locked staff account|panel actions|own account|staff sign-in'], site, { ALLOW_LOCAL_MEDIA: process.env.ALLOW_LOCAL_MEDIA ?? '1', CRON_SECRET: cronSecret, E2E_LATE_STAFF: '1' })
run(`${bundler}: the built site — late-staff spec, the mail service, closed doors, the attack probes, the published-files check, the client hints, consent, the sign-in look, the sign-in answers, the own account and the unused-files notice`, 'pnpm', ['exec', 'playwright', 'test', 'late-staff', 'mail-relay', 'closed-doors', 'attack-probes', 'smoke', 'sign-in-look', 'sign-in-answers', 'own-account', 'two-factor-enrolment', 'unused-media', '--grep', 'unused-files notice|2FA enrolment|late staff collection|the mail service|closed doors|attack probes|no package.json is published|client hints|consent|sign-in look|locked staff account|panel actions|own account|staff sign-in'], site, { ALLOW_LOCAL_MEDIA: process.env.ALLOW_LOCAL_MEDIA ?? '1', CRON_SECRET: cronSecret, E2E_LATE_STAFF: '1' })
// the budgets are the built site's own numbers: they hold for each bundler (docs/performance.md, docs/dev/perf/)
run(`${bundler}: performance budgets — every page type on a phone and a desktop, queries per render`, 'pnpm', ['exec', 'playwright', 'test', 'e2e/performance.spec'] /* a regex on the file path: a checkout path may hold "performance" */, site, { ALLOW_LOCAL_MEDIA: process.env.ALLOW_LOCAL_MEDIA ?? '1', E2E_LATE_STAFF: '1' })
passed.push(bundler)
+1
View File
@@ -63,6 +63,7 @@ export const DESCRIPTIONS = {
'e2e/late-staff-fixture.ts': 'test fixture, on only with E2E_LATE_STAFF=1: one plugin before iapl (staff collections of the config: roles with one more value, the plugin\'s roles, roles of the project\'s own) and one after it (a staff collection without rules, one whose roles field is text, copies of staff collections under new slugs — plain, with rules of their own, one rule used for another operation, other role values, the opt-out, not staff — and a visitor collection with open sign-up)',
'e2e/enrolment.ts': 'reads the two-step verification confirmation link (twoFactor.confirmByEmail, 1.18.0) from the mail sink: quoted-printable undone, the latest message to an address, waited for',
'e2e/two-factor-enrolment.spec.ts': 'the first 2FA set-up confirmed by e-mail on the built site (run by `pnpm e2e:built` in both bundlers): the password alone no longer enrols an attacker\'s factor (the link goes to the owner and is refused in another browser), and the panel flow — code, notice, link from the mail sink, sign in again',
'e2e/attack-probes.spec.ts': 'attack probes on the built site (run by `pnpm e2e:built` in both bundlers): every probe of the plugin\'s ATTACK_PROBES (security.md "Security suites") with this site\'s secret values for the bundle check, plus CSRF with the editor\'s cookie from another origin and the session cookie\'s flags; probes tied to an open audit finding are expected to fail (`test.fail`)',
'e2e/closed-doors.spec.ts': 'closed doors from outside (run by `pnpm e2e:built` in both bundlers): every door of e2e/closed-doors.ts asked on the production build as an anonymous visitor, a customer (the fixture\'s `e2e-visitors`) and an editor; doors still open while the owner decides are asserted open (`test.fail`)',
'e2e/closed-doors.ts': 'the doors that must stay closed, who each is closed for and how a closed answer looks; a project adds its own (security.md "Closed doors from outside")',
'e2e/late-staff.spec.ts': 'the account rules on a BUILT site (run by `pnpm e2e:built` after a webpack and a Turbopack build): a staff collection a later plugin adds, staff collections whose accounts can hold `admin`, and copies of staff collections — a visitor account gets nothing, nobody raises its own role or makes an admin, a copy is never wider than the plugin\'s rule',
+73
View File
@@ -0,0 +1,73 @@
#!/usr/bin/env node
/**
* pnpm security:gate — the security suites that need no built site (docs/security.md → "Security suites"):
* 1. dependency audit: `pnpm audit --prod` must show no high or critical advisory (the plugin's own production
* dependency tree; dev tooling is reported, not failed);
* 2. static rules over the plugin, its scripts and the reference site, every hit judged in
* test/security-patterns.allow.json (test/securityPatterns.test.ts), and the per-class tests
* (test/securityClasses.test.ts);
* 3. optional, `--zap <url>`: an OWASP ZAP baseline scan (passive, spiders 1 minute) of a running site, ONLY when
* the image `ghcr.io/zaproxy/zaproxy:stable` is already on this machine — the scan runs offline (`-I` keeps
* warnings from failing; failures fail). Pull the image once yourself: `docker pull ghcr.io/zaproxy/zaproxy:stable`.
* The built-site part (attack probes, closed doors) is `pnpm e2e:built`.
* Options: --offline (skip the audit, it needs the registry), --zap <url>.
*/
import { spawnSync } from 'node:child_process'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
const args = process.argv.slice(2)
const zapAt = args.indexOf('--zap')
const zapUrl = zapAt >= 0 ? args[zapAt + 1] : null
const results = []
const step = (label, command, commandArgs, { allowFail = false } = {}) => {
console.log(`\n[security:gate] ${label}`)
const r = spawnSync(command, commandArgs, { cwd: root, encoding: 'utf8', maxBuffer: 64 * 1024 * 1024 })
results.push({ label, ok: r.status === 0 || allowFail })
return r
}
if (!args.includes('--offline')) {
const audit = step('dependency audit (pnpm audit --prod)', 'pnpm', ['audit', '--prod', '--json', '--ignore-workspace'], { allowFail: true })
let v = null
try {
v = JSON.parse(audit.stdout).metadata?.vulnerabilities ?? null
} catch {
// no JSON: the registry did not answer
}
if (!v) {
console.error(` pnpm audit gave no result: ${(audit.stderr || audit.stdout).trim().split('\n')[0]}`)
results.at(-1).ok = false
} else {
console.log(` production tree: ${v.critical ?? 0} critical, ${v.high ?? 0} high, ${v.moderate ?? 0} moderate, ${v.low ?? 0} low`)
results.at(-1).ok = !(v.critical || v.high)
const dev = spawnSync('pnpm', ['audit', '--json', '--ignore-workspace'], { cwd: root, encoding: 'utf8', maxBuffer: 64 * 1024 * 1024 })
try {
const d = JSON.parse(dev.stdout).metadata?.vulnerabilities
console.log(` with dev tooling (reported, not failed): ${d.critical ?? 0} critical, ${d.high ?? 0} high, ${d.moderate ?? 0} moderate, ${d.low ?? 0} low`)
} catch {
// ignore
}
}
}
const tests = step('static rules + per-class tests (vitest)', 'pnpm', ['exec', 'vitest', 'run', 'test/securityPatterns.test.ts', 'test/securityClasses.test.ts'])
process.stdout.write(tests.stdout.split('\n').filter((l) => /Tests |✓|×|FAIL|NOT JUDGED|MORE THAN/.test(l)).join('\n') + '\n')
if (tests.status !== 0) {process.stdout.write(tests.stdout.slice(-4000))}
if (zapUrl) {
const image = 'ghcr.io/zaproxy/zaproxy:stable'
const has = spawnSync('docker', ['image', 'inspect', image], { encoding: 'utf8' })
if (has.status !== 0) {
console.log(`\n[security:gate] ZAP baseline skipped: ${image} is not on this machine (docker pull it once)`)
} else {
const target = zapUrl.replace('localhost', 'host.docker.internal').replace('127.0.0.1', 'host.docker.internal')
const zap = step(`OWASP ZAP baseline of ${zapUrl}`, 'docker', ['run', '--rm', '--add-host=host.docker.internal:host-gateway', image, 'zap-baseline.py', '-t', target, '-m', '1', '-I', '--autooff'])
process.stdout.write(zap.stdout.split('\n').filter((l) => /^(?:FAIL|WARN|PASS):|FAIL-NEW|WARN-NEW/.test(l)).slice(0, 80).join('\n') + '\n')
}
}
console.log('\n[security:gate] ' + results.map((r) => `${r.ok ? '✓' : '✗'} ${r.label}`).join('\n[security:gate] '))
process.exit(results.every((r) => r.ok) ? 0 : 1)