Audit clean with dev tooling: overrides for esbuild (<0.25, via drizzle-kit), eslint (<9.39.4, @eslint/plugin-kit) and minimatch (7–11.0.7, via typescript-eslint); security:gate fails on moderate and above in the production tree and the dev tooling (--audit-level, --prod-only to loosen); doctor transitive-min warns on esbuild for Postgres sites; AGENT.md §4 item 12, skills, security.md, changelog
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
f38a8cc677
commit
b9bcd55ac4
@@ -1,8 +1,9 @@
|
||||
#!/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);
|
||||
* 1. dependency audit: `pnpm audit` must show no moderate, high or critical advisory, in the production tree AND
|
||||
* the dev tooling (since 1.18.0; lows are reported). `--audit-level high` fails only on high and critical again
|
||||
* (`low` fails on lows too); `--prod-only` judges the production tree and only reports the dev tooling;
|
||||
* 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);
|
||||
@@ -10,7 +11,8 @@
|
||||
* 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>.
|
||||
* Options: --offline (skip the audit, it needs the registry), --audit-level <low|moderate|high|critical> (default
|
||||
* moderate), --prod-only, --zap <url>.
|
||||
*/
|
||||
import { spawnSync } from 'node:child_process'
|
||||
import path from 'node:path'
|
||||
@@ -21,6 +23,18 @@ const args = process.argv.slice(2)
|
||||
const zapAt = args.indexOf('--zap')
|
||||
const zapUrl = zapAt >= 0 ? args[zapAt + 1] : null
|
||||
const results = []
|
||||
const levelAt = args.indexOf('--audit-level')
|
||||
const LEVELS = ['low', 'moderate', 'high', 'critical']
|
||||
const level = levelAt >= 0 ? args[levelAt + 1] : 'moderate'
|
||||
if (!LEVELS.includes(level)) {
|
||||
console.error(`[security:gate] --audit-level must be one of ${LEVELS.join(', ')}, got ${JSON.stringify(level)}`)
|
||||
process.exit(2)
|
||||
}
|
||||
const prodOnly = args.includes('--prod-only')
|
||||
/** The severities that fail the gate: the chosen level and everything above it. */
|
||||
const failing = LEVELS.slice(LEVELS.indexOf(level))
|
||||
const fails = (v) => failing.some((s) => (v?.[s] ?? 0) > 0)
|
||||
const counts = (v) => `${v.critical ?? 0} critical, ${v.high ?? 0} high, ${v.moderate ?? 0} moderate, ${v.low ?? 0} low`
|
||||
|
||||
const step = (label, command, commandArgs, { allowFail = false } = {}) => {
|
||||
console.log(`\n[security:gate] ${label}`)
|
||||
@@ -30,7 +44,7 @@ const step = (label, command, commandArgs, { allowFail = false } = {}) => {
|
||||
}
|
||||
|
||||
if (!args.includes('--offline')) {
|
||||
const audit = step('dependency audit (pnpm audit --prod)', 'pnpm', ['audit', '--prod', '--json', '--ignore-workspace'], { allowFail: true })
|
||||
const audit = step(`dependency audit (pnpm audit, fails on ${failing.join(' / ')}${prodOnly ? ', production tree only' : ''})`, 'pnpm', ['audit', '--prod', '--json', '--ignore-workspace'], { allowFail: true })
|
||||
let v = null
|
||||
try {
|
||||
v = JSON.parse(audit.stdout).metadata?.vulnerabilities ?? null
|
||||
@@ -41,14 +55,21 @@ if (!args.includes('--offline')) {
|
||||
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)
|
||||
console.log(` production tree: ${counts(v)}`)
|
||||
results.at(-1).ok = !fails(v)
|
||||
const dev = spawnSync('pnpm', ['audit', '--json', '--ignore-workspace'], { cwd: root, encoding: 'utf8', maxBuffer: 64 * 1024 * 1024 })
|
||||
let d = null
|
||||
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`)
|
||||
d = JSON.parse(dev.stdout).metadata?.vulnerabilities ?? null
|
||||
} catch {
|
||||
// ignore
|
||||
// no JSON: the registry did not answer
|
||||
}
|
||||
if (!d) {
|
||||
console.error(' pnpm audit (with dev tooling) gave no result')
|
||||
if (!prodOnly) {results.at(-1).ok = false}
|
||||
} else {
|
||||
console.log(` with dev tooling${prodOnly ? ' (reported, not failed: --prod-only)' : ''}: ${counts(d)}`)
|
||||
if (!prodOnly && fails(d)) {results.at(-1).ok = false}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user