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
+68
View File
@@ -0,0 +1,68 @@
import { ATTACK_PROBES, createProbeContext } from '@intecion/ipal-kit/doctor'
import { expect, test } from '@playwright/test'
import { editorTestAccount, totp } from './totp'
/**
* Attack probes on the BUILT site (security audit 2026-12; docs/security.md → "Security suites"): every probe of
* the plugin's ATTACK_PROBES, the live-safe ones and those only for a local build (8 MB bodies), then what needs a
* signed-in session: CSRF on the API and the session cookie's flags. `pnpm e2e:built` runs it after a webpack and a
* Turbopack build. A probe tied to an open audit finding is expected to fail (test.fail) until the fix lands.
*
* The secrets the bundle check looks for are this site's own values from reference/.env.
*/
const env = process.env
const dbPassword = (() => {
try {
return decodeURIComponent(new URL(env.DATABASE_URI ?? '').password)
} catch {
return ''
}
})()
const secrets = [env.PAYLOAD_SECRET, env.CRON_SECRET, env.IAPL_COOKIE_SCAN_TOKEN, env.IAPL_DOCTOR_TOKEN, env.R2_SECRET_ACCESS_KEY, env.E2E_ADMIN_PASSWORD, env.E2E_TOTP_SECRET, dbPassword].filter((s): s is string => !!s && s.length >= 8)
test.describe('attack probes', () => {
for (const probe of ATTACK_PROBES) {
test(`${probe.class}: ${probe.title}`, async ({ baseURL }) => {
if (probe.finding) {test.fail(true, `audit finding ${probe.finding} is open (security-audit-2026-12-findings.md)`)}
const { result } = { result: await probe.run(createProbeContext(baseURL!, { page: '/pl', secrets })) }
test.skip(!!result.skipped, result.skipped)
expect(result.ok, result.detail).toBe(true)
})
}
})
test.describe('attack probes with a session', () => {
test('CSRF: the editor\'s cookie does not work from another origin (REST write, GraphQL mutation)', async ({ baseURL, playwright }) => {
const { E2E_ADMIN_EMAIL: adminEmail, E2E_ADMIN_PASSWORD: password, E2E_TOTP_SECRET: secret } = env
test.skip(!adminEmail || !password || !secret, 'E2E_* test admin not configured')
const api = await playwright.request.newContext({ baseURL, extraHTTPHeaders: { origin: baseURL! } })
expect((await api.post('/api/users/login', { data: { email: editorTestAccount(adminEmail!), password } })).status()).toBe(200)
expect((await (await api.post('/api/verify-totp', { data: { token: totp(secret!) } })).json()).ok).toBe(true)
// the same session, same origin: the write is allowed (proves the cookie works), with a body that changes nothing
const own = await api.get('/api/users/me')
expect(((await own.json()) as { user?: unknown }).user).toBeTruthy()
const foreign = { origin: 'https://evil.example', referer: 'https://evil.example/', 'sec-fetch-site': 'cross-site' }
const me = await api.get('/api/users/me', { headers: foreign })
expect([me.status(), ((await me.json()) as { user?: unknown }).user ?? null], 'a cross-site request must not be signed in').toEqual([200, null])
const write = await api.post('/api/globals/header', { data: {}, headers: foreign })
expect([401, 403]).toContain(write.status())
const gql = await api.post('/api/graphql', { data: { query: 'mutation { updateHeader(data: {}) { id } }' }, headers: foreign })
expect(gql.status()).toBeLessThan(500)
expect(await gql.text()).not.toMatch(/"updateHeader"\s*:\s*\{/)
await api.dispose()
})
test('session cookie: HttpOnly and SameSite, never readable by script', async ({ baseURL, playwright }) => {
const { E2E_ADMIN_EMAIL: adminEmail, E2E_ADMIN_PASSWORD: password } = env
test.skip(!adminEmail || !password, 'E2E_* test admin not configured')
const api = await playwright.request.newContext({ baseURL, extraHTTPHeaders: { origin: baseURL! } })
const res = await api.post('/api/users/login', { data: { email: editorTestAccount(adminEmail!), password } })
expect(res.status()).toBe(200)
const cookie = res.headersArray().filter((h) => h.name.toLowerCase() === 'set-cookie').map((h) => h.value).find((v) => /-token=/.test(v))
expect(cookie, 'the login sets the session cookie').toBeTruthy()
expect(cookie).toMatch(/;\s*HttpOnly/i)
expect(cookie).toMatch(/;\s*SameSite=(?:Lax|Strict)/i)
await api.dispose()
})
})