- 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]>
31 lines
1.8 KiB
TypeScript
31 lines
1.8 KiB
TypeScript
/**
|
|
* Attack probes from outside — the requests attackers send to Payload / Next.js sites, asked on a PRODUCTION build
|
|
* (`pnpm build && pnpm start`) or a staging copy (IAPL docs/security.md "Security suites"). Copy to
|
|
* tests/attack-probes.spec.ts and run:
|
|
*
|
|
* BASE_URL=http://localhost:3000 PAGE=/pl pnpm exec playwright test tests/attack-probes.spec.ts
|
|
*
|
|
* The probes come from the plugin (ATTACK_PROBES, @intecion/ipal-kit/doctor), so an IAPL upgrade brings new ones.
|
|
* On a LIVE site use `pnpm exec iapl-doctor --url https://<domain> --only live-probes` instead: it runs only the
|
|
* probes that change nothing (no 8 MB bodies). This spec runs all of them — local or staging only.
|
|
* The bundle check looks for this site's own secret VALUES: they are read from the environment (.env of the local
|
|
* build) and never printed. Add the project's own probes to EXTRA.
|
|
*/
|
|
import { ATTACK_PROBES, type AttackProbe, createProbeContext } from '@intecion/ipal-kit/doctor'
|
|
import { expect, test } from '@playwright/test'
|
|
|
|
const BASE = (process.env.BASE_URL ?? 'http://localhost:3000').replace(/\/$/, '')
|
|
const PAGE = process.env.PAGE ?? '/'
|
|
const secrets = ['PAYLOAD_SECRET', 'CRON_SECRET', 'R2_SECRET_ACCESS_KEY', 'TURNSTILE_SECRET_KEY', 'IAPL_DOCTOR_TOKEN', 'IAPL_COOKIE_SCAN_TOKEN'].map((k) => process.env[k]).filter((v): v is string => !!v && v.length >= 8)
|
|
|
|
/** The project's own probes, e.g. a custom endpoint that must refuse an 8 MB body or an operator in its query. */
|
|
const EXTRA: AttackProbe[] = []
|
|
|
|
for (const probe of [...ATTACK_PROBES, ...EXTRA]) {
|
|
test(`${probe.class}: ${probe.title}`, async () => {
|
|
const result = await probe.run(createProbeContext(BASE, { page: PAGE, secrets }))
|
|
test.skip(!!result.skipped, result.skipped)
|
|
expect(result.ok, result.detail).toBe(true)
|
|
})
|
|
}
|