IAPL rename: the old names keep working, and a second cookie name and counter key for new sites

- exports: ipalKit, IpalOptions, ipalEnvRules, IpalEnvFeatures, ipalT, ipalVar, IPAL_TOKENS,
  IPAL_BREAKPOINTS, IpalTokenName, IpalGlobalSlug are aliases of the iapl names
- env: IAPL_* is read first, IPAL_* as fallback (readEnv; EnvRule.aliases for assertEnv);
  the crawler service reads IPAL_CRAWLER_SITES too
- doctor: reads ipal-doctor.json when it is the only one, the old pointer block, ipal-audit-skip
  and old skill folders; new rule legacy-names (info) and storage-names (warning)
- iapl-skills: installs iapl-*, removes the 16 old folders by exact name, rewrites the old
  pointer block in place; a project's own ipal-* skill stays
- storageNames: 'ipal' (default) | 'iapl': the cookie the scanner declares and the 2FA counter's
  kv prefix; <PageStats visitorCookie>, IAPL_VISITOR_COOKIE, verifyLimit.keyPrefix
- test/legacyNames.test.ts: 24 tests for all of the above

Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-11-25 17:31:13 +01:00
co-authored by Claude Fable 5.2
parent 0a4f001797
commit 425fac14fb
43 changed files with 683 additions and 82 deletions
+10 -7
View File
@@ -4,11 +4,13 @@ import { pathToFileURL } from 'node:url'
import type { DoctorConfig, DoctorFinding, DoctorReport, DoctorRule, DoctorSeverity, DoctorStatus, RuleFinding } from './types.js'
import { createDoctorContext, type DoctorContext, loadDoctorConfig } from './project.js'
import { readEnv } from '../shared/envName.js'
import { createDoctorContext, doctorConfigFile, type DoctorContext, loadDoctorConfig } from './project.js'
import { agentRules } from './rules/agents.js'
import { blockRules } from './rules/blocks.js'
import { envRules } from './rules/env.js'
import { layoutRules } from './rules/layout.js'
import { legacyRules } from './rules/legacy.js'
import { createLiveFetcher, liveRules } from './rules/live.js'
import { securityRules } from './rules/security.js'
import { seedRules } from './rules/seeds.js'
@@ -32,6 +34,7 @@ export const doctorRules: DoctorRule[] = [
...envRules,
...securityRules,
...agentRules,
...legacyRules,
...seedRules,
...blockRules,
...toolingRules,
@@ -111,9 +114,9 @@ export function applySettings(findings: DoctorFinding[], ctx: DoctorContext): Do
const out: DoctorFinding[] = []
for (const [id, s] of Object.entries(settings)) {
if (!s || typeof s !== 'object') {continue}
if (!s.reason?.trim()) {out.push({ fix: 'add "reason": "<why>" — an entry without one is ignored', message: `iapl-doctor.json: rule "${id}" has no reason, so it is ignored`, rule: 'doctor-config', severity: 'error', source: 'static' })}
else if (s.severity && !SEVERITIES.includes(s.severity)) {out.push({ message: `iapl-doctor.json: rule "${id}" has an unknown severity "${s.severity}"`, rule: 'doctor-config', severity: 'error', source: 'static' })}
else if (s.until && ctx.today > s.until) {out.push({ fix: 'fix the finding, or extend "until" with a new reason', message: `iapl-doctor.json: the setting for "${id}" expired on ${s.until}`, rule: 'doctor-config', severity: 'warning', source: 'static' })}
if (!s.reason?.trim()) {out.push({ fix: 'add "reason": "<why>" — an entry without one is ignored', message: `${doctorConfigFile(ctx.root)}: rule "${id}" has no reason, so it is ignored`, rule: 'doctor-config', severity: 'error', source: 'static' })}
else if (s.severity && !SEVERITIES.includes(s.severity)) {out.push({ message: `${doctorConfigFile(ctx.root)}: rule "${id}" has an unknown severity "${s.severity}"`, rule: 'doctor-config', severity: 'error', source: 'static' })}
else if (s.until && ctx.today > s.until) {out.push({ fix: 'fix the finding, or extend "until" with a new reason', message: `${doctorConfigFile(ctx.root)}: the setting for "${id}" expired on ${s.until}`, rule: 'doctor-config', severity: 'warning', source: 'static' })}
}
const skips = new Map<string, string>()
for (const [key, reason] of ctx.auditSkips) {
@@ -153,7 +156,7 @@ export async function runDoctor(options: RunDoctorOptions): Promise<DoctorReport
const ctx = createDoctorContext({ config: options.config, envFile: options.envFile, live, offline: options.offline, packageRoot: options.packageRoot, root, today: options.today })
// Deep status: the probe (--deep), the endpoint (--url + IAPL_DOCTOR_TOKEN), or none.
const token = process.env.IAPL_DOCTOR_TOKEN?.trim()
const token = readEnv('IAPL_DOCTOR_TOKEN')?.trim()
if (options.deepStatus !== undefined) {ctx.deep = options.deepStatus}
else if (options.deep) {ctx.deep = runDeepProbe({ ...ctx, root })}
else if (options.url && token && token.length >= 32) {ctx.deep = await fetchDeepStatus(options.url, token)}
@@ -182,9 +185,9 @@ export async function runDoctor(options: RunDoctorOptions): Promise<DoctorReport
// First-seen dates (CSP report-only → warning after 4 weeks): stored outside CI when the file exists.
const writeSeen = options.writeSeen ?? !process.env.CI
if (writeSeen && findings.some((f) => f.rule === 'csp' && /report-only/.test(f.message)) && !ctx.config.seen?.['csp-report-only'] && existsSync(join(root, 'iapl-doctor.json'))) {
if (writeSeen && findings.some((f) => f.rule === 'csp' && /report-only/.test(f.message)) && !ctx.config.seen?.['csp-report-only'] && existsSync(join(root, doctorConfigFile(root)))) {
const current = loadDoctorConfig(root).config
writeFileSync(join(root, 'iapl-doctor.json'), `${JSON.stringify({ ...current, seen: { ...current.seen, 'csp-report-only': ctx.today } }, null, 2)}\n`)
writeFileSync(join(root, doctorConfigFile(root)), `${JSON.stringify({ ...current, seen: { ...current.seen, 'csp-report-only': ctx.today } }, null, 2)}\n`)
}
const final = applySettings(findings, ctx).sort((a, b) => Number(!!a.silenced) - Number(!!b.silenced) || RANK[a.severity] - RANK[b.severity])