@kirrosh/zond 0.22.0 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +648 -0
- package/README.md +58 -6
- package/package.json +9 -6
- package/src/cli/argv.ts +122 -0
- package/src/cli/commands/add-api.ts +134 -0
- package/src/cli/commands/api/annotate/idempotency.ts +59 -0
- package/src/cli/commands/api/annotate/index.ts +525 -0
- package/src/cli/commands/api/annotate/lifecycle.ts +74 -0
- package/src/cli/commands/api/annotate/overlay.ts +206 -0
- package/src/cli/commands/api/annotate/pagination.ts +60 -0
- package/src/cli/commands/api/annotate/prompts.ts +183 -0
- package/src/cli/commands/api/annotate/readback.ts +58 -0
- package/src/cli/commands/api/annotate/resources.ts +91 -0
- package/src/cli/commands/api/annotate/seed-bodies.ts +61 -0
- package/src/cli/commands/audit.ts +480 -0
- package/src/cli/commands/bootstrap.ts +710 -0
- package/src/cli/commands/catalog.ts +35 -0
- package/src/cli/commands/check.ts +348 -0
- package/src/cli/commands/checks.ts +756 -0
- package/src/cli/commands/ci-init.ts +43 -0
- package/src/cli/commands/clean.ts +212 -0
- package/src/cli/commands/cleanup.ts +262 -0
- package/src/cli/commands/completions.ts +16 -0
- package/src/cli/commands/coverage.ts +605 -132
- package/src/cli/commands/db.ts +178 -7
- package/src/cli/commands/describe.ts +37 -2
- package/src/cli/commands/discover.ts +1236 -0
- package/src/cli/commands/doctor.ts +607 -0
- package/src/cli/commands/fixtures.ts +402 -0
- package/src/cli/commands/generate.ts +420 -46
- package/src/cli/commands/init/bootstrap.ts +30 -1
- package/src/cli/commands/{init.ts → init/index.ts} +99 -5
- package/src/cli/commands/init/skills.ts +56 -3
- package/src/cli/commands/init/templates/agents.md +65 -61
- package/src/cli/commands/init/templates/skills/zond-checks.md +397 -0
- package/src/cli/commands/init/templates/skills/zond-triage.md +210 -0
- package/src/cli/commands/init/templates/skills/zond.md +592 -125
- package/src/cli/commands/init/templates/zond-config.yml +8 -9
- package/src/cli/commands/prepare-fixtures.ts +135 -0
- package/src/cli/commands/probe/mass-assignment.ts +503 -0
- package/src/cli/commands/probe/security.ts +454 -0
- package/src/cli/commands/probe/static.ts +255 -0
- package/src/cli/commands/probe/webhooks.ts +161 -0
- package/src/cli/commands/probe.ts +459 -0
- package/src/cli/commands/reference.ts +87 -0
- package/src/cli/commands/refresh-api.ts +169 -0
- package/src/cli/commands/remove-api.ts +150 -0
- package/src/cli/commands/report-bundle.ts +318 -0
- package/src/cli/commands/report.ts +241 -0
- package/src/cli/commands/request.ts +379 -4
- package/src/cli/commands/run.ts +842 -53
- package/src/cli/commands/session.ts +244 -0
- package/src/cli/commands/use.ts +18 -1
- package/src/cli/index.ts +20 -3
- package/src/cli/json-envelope.ts +112 -3
- package/src/cli/json-schemas.ts +263 -0
- package/src/cli/program.ts +198 -635
- package/src/cli/resolve.ts +105 -0
- package/src/cli/status-filter.ts +124 -0
- package/src/cli/util/api-context.ts +85 -0
- package/src/cli/version.ts +5 -0
- package/src/core/anti-fp/bootstrap.ts +34 -0
- package/src/core/anti-fp/index.ts +33 -0
- package/src/core/anti-fp/registry.ts +44 -0
- package/src/core/anti-fp/rules/baseline-echo.ts +74 -0
- package/src/core/anti-fp/rules/schemathesis/body_negation_becomes_valid.ts +52 -0
- package/src/core/anti-fp/rules/schemathesis/coverage_phase_boundary_positive.ts +38 -0
- package/src/core/anti-fp/rules/schemathesis/has_unverifiable_mutations.ts +35 -0
- package/src/core/anti-fp/rules/schemathesis/index.ts +24 -0
- package/src/core/anti-fp/rules/schemathesis/string_type_mutation_becomes_valid.ts +53 -0
- package/src/core/anti-fp/rules/subscription-gated/index.ts +11 -0
- package/src/core/anti-fp/rules/subscription-gated/paid-plan-403.ts +75 -0
- package/src/core/anti-fp/types.ts +68 -0
- package/src/core/checks/checks/_crud-helpers.ts +133 -0
- package/src/core/checks/checks/_negative_mutator.ts +133 -0
- package/src/core/checks/checks/_readback-helpers.ts +133 -0
- package/src/core/checks/checks/content_type_conformance.ts +39 -0
- package/src/core/checks/checks/cross_call_references.ts +134 -0
- package/src/core/checks/checks/ensure_resource_availability.ts +62 -0
- package/src/core/checks/checks/idempotency_replay.ts +246 -0
- package/src/core/checks/checks/ignored_auth.ts +211 -0
- package/src/core/checks/checks/index.ts +65 -0
- package/src/core/checks/checks/lifecycle_transitions.ts +273 -0
- package/src/core/checks/checks/missing_required_header.ts +40 -0
- package/src/core/checks/checks/negative_data_rejection.ts +45 -0
- package/src/core/checks/checks/not_a_server_error.ts +27 -0
- package/src/core/checks/checks/open_cors_on_sensitive.ts +131 -0
- package/src/core/checks/checks/pagination_invariants.ts +238 -0
- package/src/core/checks/checks/positive_data_acceptance.ts +36 -0
- package/src/core/checks/checks/rate_limit_headers_absent.ts +77 -0
- package/src/core/checks/checks/response_headers_conformance.ts +74 -0
- package/src/core/checks/checks/response_schema_conformance.ts +30 -0
- package/src/core/checks/checks/status_code_conformance.ts +61 -0
- package/src/core/checks/checks/unsupported_method.ts +63 -0
- package/src/core/checks/checks/use_after_free.ts +78 -0
- package/src/core/checks/index.ts +30 -0
- package/src/core/checks/mode.ts +79 -0
- package/src/core/checks/recommended-action.ts +64 -0
- package/src/core/checks/registry.ts +78 -0
- package/src/core/checks/runner.ts +874 -0
- package/src/core/checks/sarif.ts +230 -0
- package/src/core/checks/stateful.ts +121 -0
- package/src/core/checks/types.ts +189 -0
- package/src/core/classifier/recommended-action.ts +222 -0
- package/src/core/context/current.ts +22 -6
- package/src/core/context/session.ts +78 -0
- package/src/core/coverage/loader.ts +185 -0
- package/src/core/coverage/reasons.ts +300 -0
- package/src/core/diagnostics/db-analysis.ts +151 -11
- package/src/core/diagnostics/failure-class.ts +120 -0
- package/src/core/diagnostics/failure-hints.ts +212 -9
- package/src/core/diagnostics/spec-pointer.ts +99 -0
- package/src/core/diagnostics/suggested-fixes.ts +156 -0
- package/src/core/exporter/case-study/index.ts +270 -0
- package/src/core/exporter/curl.ts +40 -0
- package/src/core/exporter/exporter.ts +48 -0
- package/src/core/exporter/html-report/escape.ts +24 -0
- package/src/core/exporter/html-report/index.ts +479 -0
- package/src/core/exporter/html-report/script.ts +100 -0
- package/src/core/exporter/html-report/styles.ts +408 -0
- package/src/core/generator/chunker.ts +42 -16
- package/src/core/generator/coverage-phase.ts +0 -0
- package/src/core/generator/create-body.ts +89 -0
- package/src/core/generator/data-factory.ts +445 -19
- package/src/core/generator/describe.ts +1 -1
- package/src/core/generator/fixtures-builder.ts +325 -0
- package/src/core/generator/index.ts +7 -5
- package/src/core/generator/openapi-reader.ts +37 -3
- package/src/core/generator/path-param-disambig.ts +114 -0
- package/src/core/generator/resources-builder.ts +648 -0
- package/src/core/generator/schema-utils.ts +11 -3
- package/src/core/generator/serializer.ts +103 -13
- package/src/core/generator/suite-generator.ts +419 -111
- package/src/core/generator/types.ts +8 -0
- package/src/core/identity/identity-file.ts +129 -0
- package/src/core/lint/affects.ts +28 -0
- package/src/core/lint/config.ts +96 -0
- package/src/core/lint/format.ts +42 -0
- package/src/core/lint/index.ts +94 -0
- package/src/core/lint/reporter.ts +128 -0
- package/src/core/lint/rules/consistency.ts +158 -0
- package/src/core/lint/rules/heuristics.ts +97 -0
- package/src/core/lint/rules/strictness.ts +109 -0
- package/src/core/lint/types.ts +96 -0
- package/src/core/lint/walker.ts +248 -0
- package/src/core/meta/meta-store.ts +6 -73
- package/src/core/output/README.md +91 -0
- package/src/core/output/index.ts +13 -0
- package/src/core/output/run.ts +126 -0
- package/src/core/output/types.ts +129 -0
- package/src/core/parser/env-interpolation.ts +104 -0
- package/src/core/parser/filter.ts +57 -0
- package/src/core/parser/schema.ts +129 -4
- package/src/core/parser/types.ts +19 -1
- package/src/core/parser/variables.ts +0 -0
- package/src/core/parser/yaml-parser.ts +58 -12
- package/src/core/probe/bootstrap.ts +34 -0
- package/src/core/probe/dry-run-envelope.ts +57 -0
- package/src/core/probe/mass-assignment-probe-class.ts +198 -0
- package/src/core/probe/mass-assignment-probe.ts +1122 -0
- package/src/core/probe/mass-assignment-template.ts +212 -0
- package/src/core/probe/method-probe.ts +43 -76
- package/src/core/probe/method-shared.ts +69 -0
- package/src/core/probe/negative-probe.ts +183 -149
- package/src/core/probe/orphan-tracker.ts +188 -0
- package/src/core/probe/path-discovery.ts +440 -0
- package/src/core/probe/probe-harness.ts +120 -0
- package/src/core/probe/registry.ts +89 -0
- package/src/core/probe/runner.ts +136 -0
- package/src/core/probe/security-probe-class.ts +201 -0
- package/src/core/probe/security-probe.ts +1453 -0
- package/src/core/probe/shared.ts +505 -0
- package/src/core/probe/static-probe-class.ts +125 -0
- package/src/core/probe/types.ts +165 -0
- package/src/core/probe/verdict-aggregator.ts +33 -0
- package/src/core/probe/webhooks-probe.ts +284 -0
- package/src/core/reporter/console.ts +41 -2
- package/src/core/reporter/index.ts +2 -3
- package/src/core/reporter/json.ts +11 -1
- package/src/core/reporter/junit.ts +27 -12
- package/src/core/reporter/ndjson.ts +37 -0
- package/src/core/reporter/types.ts +3 -0
- package/src/core/runner/assertions.ts +58 -1
- package/src/core/runner/async-pool.ts +108 -0
- package/src/core/runner/auth-path.ts +8 -0
- package/src/core/runner/ci-context.ts +72 -0
- package/src/core/runner/executor.ts +264 -20
- package/src/core/runner/form-encode.ts +51 -0
- package/src/core/runner/http-client.ts +75 -2
- package/src/core/runner/learn-drift.ts +293 -0
- package/src/core/runner/preflight-vars.ts +149 -0
- package/src/core/runner/progress-tracker.ts +73 -0
- package/src/core/runner/rate-limiter.ts +89 -17
- package/src/core/runner/run-kind.ts +39 -0
- package/src/core/runner/schema-validator.ts +312 -0
- package/src/core/runner/send-request.ts +153 -20
- package/src/core/runner/types.ts +38 -0
- package/src/core/secrets/registry.ts +164 -0
- package/src/core/secrets/secrets-file.ts +115 -0
- package/src/core/selectors/operation-filter.ts +144 -0
- package/src/core/setup-api.ts +415 -16
- package/src/core/severity/category.ts +94 -0
- package/src/core/severity/index.ts +121 -0
- package/src/core/spec/layers.ts +154 -0
- package/src/core/util/format-eta.ts +21 -0
- package/src/core/utils.ts +5 -1
- package/src/core/workspace/config.ts +129 -0
- package/src/core/workspace/manifest.ts +283 -0
- package/src/core/workspace/output-rotation.ts +62 -0
- package/src/core/workspace/triage-path.ts +87 -0
- package/src/db/lint-runs.ts +47 -0
- package/src/db/migrate.ts +126 -0
- package/src/db/migrations/0001_run_kind.sql +25 -0
- package/src/db/migrations/sql.d.ts +4 -0
- package/src/db/queries/collections.ts +133 -0
- package/src/db/queries/coverage.ts +9 -0
- package/src/db/queries/dashboard.ts +59 -0
- package/src/db/queries/results.ts +128 -0
- package/src/db/queries/runs.ts +235 -0
- package/src/db/queries/sessions.ts +42 -0
- package/src/db/queries/settings.ts +28 -0
- package/src/db/queries/types.ts +172 -0
- package/src/db/queries.ts +72 -802
- package/src/db/schema.ts +178 -50
- package/src/cli/commands/export.ts +0 -144
- package/src/cli/commands/guide.ts +0 -127
- package/src/cli/commands/init/templates/skills/scenarios.md +0 -97
- package/src/cli/commands/probe-methods.ts +0 -108
- package/src/cli/commands/probe-validation.ts +0 -124
- package/src/cli/commands/serve.ts +0 -114
- package/src/cli/commands/sync.ts +0 -268
- package/src/cli/commands/update.ts +0 -189
- package/src/cli/commands/validate.ts +0 -34
- package/src/core/diagnostics/render-md.ts +0 -112
- package/src/core/exporter/postman.ts +0 -963
- package/src/core/generator/guide-builder.ts +0 -253
- package/src/core/meta/types.ts +0 -19
- package/src/core/parser/index.ts +0 -21
- package/src/core/runner/execute-run.ts +0 -132
- package/src/core/runner/index.ts +0 -12
- package/src/core/sync/spec-differ.ts +0 -38
- package/src/web/data/collection-state.ts +0 -362
- package/src/web/routes/api.ts +0 -314
- package/src/web/routes/dashboard.ts +0 -350
- package/src/web/routes/runs.ts +0 -64
- package/src/web/schemas.ts +0 -121
- package/src/web/server.ts +0 -134
- package/src/web/static/htmx.min.cjs +0 -1
- package/src/web/static/style.css +0 -1148
- package/src/web/views/endpoints-tab.ts +0 -174
- package/src/web/views/explorer-tab.ts +0 -402
- package/src/web/views/health-strip.ts +0 -92
- package/src/web/views/layout.ts +0 -48
- package/src/web/views/results.ts +0 -210
- package/src/web/views/runs-tab.ts +0 -126
- package/src/web/views/suites-tab.ts +0 -181
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
import { join } from "path";
|
|
2
|
+
import { mkdir, writeFile } from "fs/promises";
|
|
3
|
+
import { loadEnvironment, loadEnvFile } from "../../../core/parser/variables.ts";
|
|
4
|
+
import {
|
|
5
|
+
runSecurityProbes,
|
|
6
|
+
formatSecurityDigest,
|
|
7
|
+
emitSecurityRegressionSuites,
|
|
8
|
+
SECURITY_CLASSES,
|
|
9
|
+
type SecurityClass,
|
|
10
|
+
} from "../../../core/probe/security-probe.ts";
|
|
11
|
+
import { loadSpecForProbe, writeProbeSuites } from "../../../core/probe/runner.ts";
|
|
12
|
+
import { printError, printSuccess, printWarning } from "../../output.ts";
|
|
13
|
+
import { jsonOk, jsonError, printJson } from "../../json-envelope.ts";
|
|
14
|
+
import { getSecretRegistry } from "../../../core/secrets/registry.ts";
|
|
15
|
+
import { applySanitizer } from "../../../core/exporter/exporter.ts";
|
|
16
|
+
import { rotateOutputTarget } from "../../../core/workspace/output-rotation.ts";
|
|
17
|
+
import { tallyBySeverity, formatSummaryLine } from "../../../core/probe/verdict-aggregator.ts";
|
|
18
|
+
import { printMutationBanner, countCleanupFailures } from "../../../core/probe/shared.ts";
|
|
19
|
+
import { persistVerdictsAsOrphans } from "../../../core/probe/orphan-tracker.ts";
|
|
20
|
+
import { SecurityProbe } from "../../../core/probe/security-probe-class.ts";
|
|
21
|
+
import { summarizeDryRun } from "../../../core/probe/dry-run-envelope.ts";
|
|
22
|
+
import { compileOperationFilter } from "../../../core/selectors/operation-filter.ts";
|
|
23
|
+
|
|
24
|
+
interface Buckets {
|
|
25
|
+
high: number;
|
|
26
|
+
medium: number;
|
|
27
|
+
low: number;
|
|
28
|
+
info: number;
|
|
29
|
+
inconclusive: number;
|
|
30
|
+
inconclusiveBaseline: number;
|
|
31
|
+
ok: number;
|
|
32
|
+
skipped: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const SEC_BUCKETS: ReadonlyArray<readonly [string, keyof Buckets & string]> = [
|
|
36
|
+
["high", "high"],
|
|
37
|
+
["medium", "medium"],
|
|
38
|
+
["low", "low"],
|
|
39
|
+
["info", "info"],
|
|
40
|
+
["inconclusive", "inconclusive"],
|
|
41
|
+
["inconclusive-baseline", "inconclusiveBaseline"],
|
|
42
|
+
["ok", "ok"],
|
|
43
|
+
["skipped", "skipped"],
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
const SEC_SUMMARY: ReadonlyArray<readonly [string, keyof Buckets & string]> = [
|
|
47
|
+
["HIGH", "high"],
|
|
48
|
+
["INCONCLUSIVE", "inconclusive"],
|
|
49
|
+
["INCONCLUSIVE-BASE", "inconclusiveBaseline"],
|
|
50
|
+
["MED", "medium"],
|
|
51
|
+
["LOW", "low"],
|
|
52
|
+
["INFO", "info"],
|
|
53
|
+
["OK", "ok"],
|
|
54
|
+
["SKIPPED", "skipped"],
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
const SEC_ZERO: Buckets = {
|
|
58
|
+
high: 0, medium: 0, low: 0, info: 0, inconclusive: 0, inconclusiveBaseline: 0, ok: 0, skipped: 0,
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export interface ProbeSecurityOptions {
|
|
62
|
+
specPath: string;
|
|
63
|
+
classes: string;
|
|
64
|
+
env?: string;
|
|
65
|
+
output?: string;
|
|
66
|
+
emitTests?: string;
|
|
67
|
+
tag?: string;
|
|
68
|
+
noCleanup?: boolean;
|
|
69
|
+
timeoutMs?: number;
|
|
70
|
+
dryRun?: boolean;
|
|
71
|
+
json?: boolean;
|
|
72
|
+
listTags?: boolean;
|
|
73
|
+
overwrite?: boolean;
|
|
74
|
+
/** TASK-278: API name for orphan-tracker file path
|
|
75
|
+
* (`~/.zond/orphans/<api>/<run-id>.jsonl`). Defaults to "default" when
|
|
76
|
+
* the probe is invoked without --api. */
|
|
77
|
+
apiName?: string;
|
|
78
|
+
/** TASK-264: refuse to attack PUT/PATCH endpoints whose path-params come
|
|
79
|
+
* from `.env.yaml` (seeded fixtures). Trade coverage for guaranteed
|
|
80
|
+
* fixture safety. */
|
|
81
|
+
isolated?: boolean;
|
|
82
|
+
/** ARV-140: opt-in to POST attacks on endpoints with no DELETE counterpart
|
|
83
|
+
* in the spec. Defaults to off so probes can't leak resources the CLI
|
|
84
|
+
* has no way to clean up afterwards. */
|
|
85
|
+
allowLeaks?: boolean;
|
|
86
|
+
/** m-17 / ARV-51: structured report format for `--output` and the
|
|
87
|
+
* non-`--json` stdout path. `--json` envelope is always structured
|
|
88
|
+
* (no markdown blob) regardless of this flag. Default: "markdown" so
|
|
89
|
+
* human invocations keep the existing behaviour. */
|
|
90
|
+
report?: "markdown" | "json";
|
|
91
|
+
/** m-15 ARV-9 / m-17 ARV-J: unified operation selectors. */
|
|
92
|
+
include?: string[];
|
|
93
|
+
exclude?: string[];
|
|
94
|
+
/** ARV-253: surface INFO-severity findings (CRLF accepted, no
|
|
95
|
+
* reflection — sanitization signal only). Hidden by default since
|
|
96
|
+
* they carry single_signal proof with no exploit pathway. */
|
|
97
|
+
verbose?: boolean;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function parseClasses(input: string): SecurityClass[] | string {
|
|
101
|
+
const parts = input.split(",").map(s => s.trim()).filter(Boolean);
|
|
102
|
+
const out: SecurityClass[] = [];
|
|
103
|
+
for (const p of parts) {
|
|
104
|
+
if (!(SECURITY_CLASSES as readonly string[]).includes(p)) {
|
|
105
|
+
return `Unknown class: ${p}. Available: ${SECURITY_CLASSES.join(", ")}`;
|
|
106
|
+
}
|
|
107
|
+
out.push(p as SecurityClass);
|
|
108
|
+
}
|
|
109
|
+
if (out.length === 0) return `At least one class required (${SECURITY_CLASSES.join(", ")})`;
|
|
110
|
+
return out;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export async function probeSecurityCommand(
|
|
114
|
+
options: ProbeSecurityOptions,
|
|
115
|
+
): Promise<number> {
|
|
116
|
+
try {
|
|
117
|
+
const classes = parseClasses(options.classes);
|
|
118
|
+
if (typeof classes === "string") {
|
|
119
|
+
if (options.json) printJson(jsonError("probe-security", [classes]));
|
|
120
|
+
else printError(classes);
|
|
121
|
+
return 2;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const loaded = await loadSpecForProbe({
|
|
125
|
+
specPath: options.specPath,
|
|
126
|
+
tag: options.tag,
|
|
127
|
+
listTags: options.listTags,
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
if (loaded.kind === "tags") {
|
|
131
|
+
if (options.json) printJson(jsonOk("probe-security", { tags: loaded.tags }));
|
|
132
|
+
else if (loaded.tags.length === 0) console.log("No tags found in spec.");
|
|
133
|
+
else {
|
|
134
|
+
console.log("Available tags:");
|
|
135
|
+
for (const t of loaded.tags) console.log(` - ${t}`);
|
|
136
|
+
}
|
|
137
|
+
return 0;
|
|
138
|
+
}
|
|
139
|
+
if (loaded.kind === "tag-not-found") {
|
|
140
|
+
const msg = `No endpoints tagged "${loaded.tag}". Available tags: ${loaded.available.length ? loaded.available.join(", ") : "(none)"}`;
|
|
141
|
+
if (options.json) printJson(jsonError("probe-security", [msg]));
|
|
142
|
+
else printWarning(msg);
|
|
143
|
+
return 2;
|
|
144
|
+
}
|
|
145
|
+
const { endpoints: rawEndpoints, securitySchemes } = loaded;
|
|
146
|
+
|
|
147
|
+
// m-17 / ARV-J: unified --include/--exclude (m-15 ARV-9). Closes
|
|
148
|
+
// ARV-9 AC#3 for probe-family.
|
|
149
|
+
let endpoints = rawEndpoints;
|
|
150
|
+
if (options.include?.length || options.exclude?.length) {
|
|
151
|
+
const compiled = compileOperationFilter({ includes: options.include, excludes: options.exclude });
|
|
152
|
+
if (compiled.errors.length > 0) {
|
|
153
|
+
const message = compiled.errors.join("\n");
|
|
154
|
+
if (options.json) printJson(jsonError("probe-security", [message]));
|
|
155
|
+
else printError(message);
|
|
156
|
+
return 2;
|
|
157
|
+
}
|
|
158
|
+
endpoints = endpoints.filter(compiled.filter);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
let vars: Record<string, string> = {};
|
|
162
|
+
if (options.env) {
|
|
163
|
+
const fromFile = await loadEnvFile(options.env);
|
|
164
|
+
if (!fromFile) {
|
|
165
|
+
const msg = `Environment file not found: ${options.env}`;
|
|
166
|
+
if (options.json) printJson(jsonError("probe-security", [msg]));
|
|
167
|
+
else printError(msg);
|
|
168
|
+
return 2;
|
|
169
|
+
}
|
|
170
|
+
vars = fromFile;
|
|
171
|
+
} else {
|
|
172
|
+
vars = await loadEnvironment();
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (!options.dryRun && !vars["base_url"]) {
|
|
176
|
+
const msg = "base_url is required (set in .env.yaml or via --env file). Probing requires a live API.";
|
|
177
|
+
if (options.json) printJson(jsonError("probe-security", [msg]));
|
|
178
|
+
else printError(msg);
|
|
179
|
+
return 2;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// m-17 / ARV-50: dry-run answers "what would I attack" — severity is
|
|
183
|
+
// undefined here, so we use a separate `data.endpoints[]` shape with
|
|
184
|
+
// explicit `planned: boolean` and `skip_reason` enum. The previous
|
|
185
|
+
// conflation (severity.skipped == 32, which silently included 14
|
|
186
|
+
// planned attacks) is what made `severity.skipped == totalEndpoints`
|
|
187
|
+
// a misleading CI gate (F1-15).
|
|
188
|
+
if (options.dryRun) {
|
|
189
|
+
const probe = new SecurityProbe();
|
|
190
|
+
const plan = await probe.dryRun({
|
|
191
|
+
specPath: options.specPath,
|
|
192
|
+
endpoints,
|
|
193
|
+
securitySchemes,
|
|
194
|
+
vars,
|
|
195
|
+
classes,
|
|
196
|
+
options: { isolated: options.isolated === true },
|
|
197
|
+
});
|
|
198
|
+
const data = summarizeDryRun(plan);
|
|
199
|
+
if (options.json) {
|
|
200
|
+
printJson(jsonOk("probe-security", data));
|
|
201
|
+
} else {
|
|
202
|
+
const { formatDryRunDigest } = await import("../../../core/probe/dry-run-envelope.ts");
|
|
203
|
+
console.log(formatDryRunDigest(plan));
|
|
204
|
+
}
|
|
205
|
+
return 0;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// TASK-259: live security probes mutate via PUT/PATCH/POST + cleanup
|
|
209
|
+
// DELETE. Skip the banner in --dry-run (no live calls) and --json (warnings
|
|
210
|
+
// travel in the envelope instead).
|
|
211
|
+
printMutationBanner("probe-security", vars, { quiet: options.json === true });
|
|
212
|
+
|
|
213
|
+
const result = await runSecurityProbes({
|
|
214
|
+
endpoints,
|
|
215
|
+
securitySchemes,
|
|
216
|
+
vars,
|
|
217
|
+
classes,
|
|
218
|
+
noCleanup: options.noCleanup,
|
|
219
|
+
timeoutMs: options.timeoutMs,
|
|
220
|
+
dryRun: options.dryRun,
|
|
221
|
+
isolated: options.isolated === true,
|
|
222
|
+
allowLeaks: options.allowLeaks === true,
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
// ARV-253: filter verdicts for display under the evidence-chain
|
|
226
|
+
// principle. INFO-severity findings (CRLF accepted, no reflection
|
|
227
|
+
// — sanitization signal only) are hidden by default; surfaced under
|
|
228
|
+
// --verbose for hygiene auditors. JSON envelope keeps the unfiltered
|
|
229
|
+
// list so agents can opt in explicitly.
|
|
230
|
+
const displayResult = options.verbose === true
|
|
231
|
+
? result
|
|
232
|
+
: { ...result, verdicts: result.verdicts.map((v) => ({
|
|
233
|
+
...v,
|
|
234
|
+
findings: v.findings.filter((f) => f.severity !== "info"),
|
|
235
|
+
})) };
|
|
236
|
+
|
|
237
|
+
// TASK-168 (m-10): register env vars + redact the digest before
|
|
238
|
+
// either writing to disk or echoing to stdout.
|
|
239
|
+
getSecretRegistry().registerAll(vars);
|
|
240
|
+
const md = applySanitizer(formatSecurityDigest(displayResult, options.specPath));
|
|
241
|
+
|
|
242
|
+
// m-17 / ARV-51: --output writes whichever format `--report` selected
|
|
243
|
+
// (default markdown). `--json` envelope is always structured —
|
|
244
|
+
// never carries `data.digest.stdout` (F3-15).
|
|
245
|
+
const reportFmt: "markdown" | "json" = options.report ?? "markdown";
|
|
246
|
+
const structuredEndpoints = buildStructuredEndpoints(result);
|
|
247
|
+
if (options.output) {
|
|
248
|
+
await mkdir(join(options.output, "..").replace(/\/\.$/, ""), { recursive: true }).catch(() => {});
|
|
249
|
+
rotateOutputTarget(options.output, { overwrite: options.overwrite });
|
|
250
|
+
const payload = reportFmt === "json"
|
|
251
|
+
? JSON.stringify(structuredReport(result, structuredEndpoints), null, 2) + "\n"
|
|
252
|
+
: md;
|
|
253
|
+
await writeFile(options.output, payload, "utf-8");
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
let emittedSuites: Array<{ file: string; suite: string; tests: number }> = [];
|
|
257
|
+
if (options.emitTests && !options.dryRun) {
|
|
258
|
+
const suites = emitSecurityRegressionSuites(result, endpoints, securitySchemes);
|
|
259
|
+
const written = await writeProbeSuites({
|
|
260
|
+
output: options.emitTests,
|
|
261
|
+
suites,
|
|
262
|
+
command: "zond probe-security --emit-tests",
|
|
263
|
+
headerExample: `zond probe-security --api <name> --emit-tests ${options.emitTests}`,
|
|
264
|
+
});
|
|
265
|
+
emittedSuites = written.files;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
const counts = tallyBySeverity(result.verdicts, SEC_BUCKETS, SEC_ZERO);
|
|
269
|
+
// TASK-259: shared cleanup-failure counter (404 treated as success — the
|
|
270
|
+
// resource is already gone, which is the cleanup goal). Replaces the
|
|
271
|
+
// previous local filter that flagged any `cleanup.error` regardless of
|
|
272
|
+
// the underlying status.
|
|
273
|
+
const orphans = countCleanupFailures(result.verdicts);
|
|
274
|
+
|
|
275
|
+
// TASK-278: persist created-resource records to ~/.zond/orphans/<api>/<run-id>.jsonl
|
|
276
|
+
// even when cleanup succeeded — successful entries become tombstones that
|
|
277
|
+
// suppress the leak; failed ones are picked up by `zond cleanup --orphans`.
|
|
278
|
+
const orphanRunId = `${Date.now()}`;
|
|
279
|
+
const orphanApi = options.apiName ?? "default";
|
|
280
|
+
if (!options.dryRun) {
|
|
281
|
+
try {
|
|
282
|
+
await persistVerdictsAsOrphans(orphanApi, orphanRunId, result.verdicts);
|
|
283
|
+
} catch (err) {
|
|
284
|
+
// Non-fatal — orphan tracking is a hygiene aid, not a probe blocker.
|
|
285
|
+
if (!options.json) {
|
|
286
|
+
process.stderr.write(`zond: failed to persist orphan tracker: ${(err as Error).message}\n`);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
const orphanList = result.verdicts
|
|
291
|
+
.filter(v => {
|
|
292
|
+
const c = v.cleanup;
|
|
293
|
+
if (!c?.attempted || c.id === undefined) return false;
|
|
294
|
+
if (c.error) return true;
|
|
295
|
+
return c.status != null && c.status >= 400 && c.status !== 404;
|
|
296
|
+
})
|
|
297
|
+
.map(v => ({
|
|
298
|
+
method: v.method.toUpperCase(),
|
|
299
|
+
path: v.path,
|
|
300
|
+
id: String(v.cleanup!.id),
|
|
301
|
+
deletePath: v.cleanup!.deletePath ?? "",
|
|
302
|
+
lastStatus: v.cleanup!.status ?? null,
|
|
303
|
+
error: v.cleanup!.error ?? null,
|
|
304
|
+
}));
|
|
305
|
+
|
|
306
|
+
if (options.json) {
|
|
307
|
+
// m-17 / ARV-51: structured envelope. `data.digest.stdout` is gone
|
|
308
|
+
// (F3-15) — markdown lives in `--output <file>` or `--report markdown`
|
|
309
|
+
// on the non-json path. Severity becomes summary.by_status.
|
|
310
|
+
printJson(
|
|
311
|
+
jsonOk("probe-security", {
|
|
312
|
+
endpoints: structuredEndpoints,
|
|
313
|
+
summary: {
|
|
314
|
+
totalEndpoints: result.totalEndpoints,
|
|
315
|
+
probed: result.specProbed,
|
|
316
|
+
by_status: byStatus(structuredEndpoints),
|
|
317
|
+
// ARV-140: pre-flight cleanup-feasibility counts. Lets CI gate on
|
|
318
|
+
// "no leak-prone POSTs slipped in" independently of HIGH findings.
|
|
319
|
+
...(result.cleanupFeasibility ? {
|
|
320
|
+
cleanup_feasibility: {
|
|
321
|
+
skipped_no_cleanup: result.cleanupFeasibility.skippedNoCleanup,
|
|
322
|
+
forced_no_cleanup: result.cleanupFeasibility.forcedNoCleanup,
|
|
323
|
+
// ARV-153: action POSTs attacked even without a DELETE
|
|
324
|
+
// counterpart (e.g. /capture, /verify, /cancel).
|
|
325
|
+
action_no_cleanup_needed: result.cleanupFeasibility.actionNoCleanupNeeded,
|
|
326
|
+
},
|
|
327
|
+
} : {}),
|
|
328
|
+
},
|
|
329
|
+
orphans,
|
|
330
|
+
emittedTests: emittedSuites,
|
|
331
|
+
}),
|
|
332
|
+
);
|
|
333
|
+
} else {
|
|
334
|
+
if (!options.output) {
|
|
335
|
+
if (reportFmt === "json") {
|
|
336
|
+
process.stdout.write(JSON.stringify(structuredReport(result, structuredEndpoints), null, 2) + "\n");
|
|
337
|
+
} else {
|
|
338
|
+
console.log(md);
|
|
339
|
+
}
|
|
340
|
+
} else printSuccess(`${reportFmt === "json" ? "Structured report" : "Digest"} written to ${options.output}`);
|
|
341
|
+
console.log("");
|
|
342
|
+
console.log(formatSummaryLine(counts, SEC_SUMMARY));
|
|
343
|
+
if (emittedSuites.length > 0) {
|
|
344
|
+
printSuccess(`Emitted ${emittedSuites.length} regression suite(s) in ${options.emitTests}`);
|
|
345
|
+
// TASK-154 §M: print one ready-to-paste command that re-runs the
|
|
346
|
+
// emitted suites against the same API. Keeps the CI handoff short
|
|
347
|
+
// (issue body / runbook entry: copy this line, not three).
|
|
348
|
+
const envFlag = options.apiName ? ` --env apis/${options.apiName}/.env.yaml` : "";
|
|
349
|
+
console.log(`Run regression suite on CI: zond run ${options.emitTests}${envFlag}`);
|
|
350
|
+
} else if (options.emitTests && !options.dryRun) {
|
|
351
|
+
console.log(`No 2xx findings to emit. Directory ${options.emitTests} not created.`);
|
|
352
|
+
}
|
|
353
|
+
if (counts.high > 0) {
|
|
354
|
+
printWarning(`${counts.high} HIGH-severity finding(s) — review the digest before deploy.`);
|
|
355
|
+
}
|
|
356
|
+
if (orphans > 0) {
|
|
357
|
+
printWarning(
|
|
358
|
+
`${orphans} orphan resource(s): cleanup DELETE failed (non-404). Manual remediation may be needed.`,
|
|
359
|
+
);
|
|
360
|
+
// TASK-278: list each orphan with id + deletePath so the operator can
|
|
361
|
+
// see what's leaked without grep'ing the digest.
|
|
362
|
+
if (orphanList.length > 0) {
|
|
363
|
+
for (const o of orphanList) {
|
|
364
|
+
const tail = o.lastStatus != null ? `→ ${o.lastStatus}` : (o.error ? `→ err: ${o.error.split(" | ")[0]}` : "");
|
|
365
|
+
process.stderr.write(` ${o.method} ${o.path} (id=${o.id}); DELETE ${o.deletePath} ${tail}\n`);
|
|
366
|
+
}
|
|
367
|
+
process.stderr.write(`Run \`zond cleanup --orphans --api ${orphanApi}\` to retry.\n`);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
const cleanedCount = result.verdicts.filter(v => v.cleanup?.attempted && v.cleanup.status != null && v.cleanup.status < 400).length;
|
|
371
|
+
if (cleanedCount > 0) {
|
|
372
|
+
printWarning(
|
|
373
|
+
`${cleanedCount} resource(s) created and deleted by probes. FK fixtures in .env.yaml may be stale — re-run \`zond prepare-fixtures --api <name>\` before next CRUD run.`,
|
|
374
|
+
);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// Exit non-zero on HIGH (CI gate) or cleanup failures (data
|
|
379
|
+
// integrity). Cleanup failure means probe-security mutated state
|
|
380
|
+
// it couldn't restore — the operator needs to act.
|
|
381
|
+
return counts.high > 0 || orphans > 0 ? 1 : 0;
|
|
382
|
+
} catch (err) {
|
|
383
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
384
|
+
if (options.json) printJson(jsonError("probe-security", [message]));
|
|
385
|
+
else printError(message);
|
|
386
|
+
return 2;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// m-17 / ARV-51: structured per-endpoint shape used by both the `--json`
|
|
391
|
+
// envelope and the non-json `--report json` path. Mirrors the Probe
|
|
392
|
+
// contract result (src/core/probe/types.ts), but built from the legacy
|
|
393
|
+
// SecurityVerdict[] so the live runner keeps emitting its richer
|
|
394
|
+
// internal structure.
|
|
395
|
+
|
|
396
|
+
import type { SecurityProbeResult, SecurityVerdict } from "../../../core/probe/security-probe.ts";
|
|
397
|
+
import type { ProbeEndpointResult, ProbeEndpointStatus, ProbeFindingSeverity } from "../../../core/probe/types.ts";
|
|
398
|
+
|
|
399
|
+
function statusFromSeverity(s: SecurityVerdict["severity"]): ProbeEndpointStatus {
|
|
400
|
+
if (s === "high") return "high";
|
|
401
|
+
if (s === "low") return "low";
|
|
402
|
+
if (s === "ok") return "ok";
|
|
403
|
+
if (s === "skipped") return "skipped";
|
|
404
|
+
return "inconclusive";
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
function findingSeverity(s: string): ProbeFindingSeverity {
|
|
408
|
+
if (s === "high") return "high";
|
|
409
|
+
if (s === "low") return "low";
|
|
410
|
+
if (s === "ok") return "ok";
|
|
411
|
+
return "inconclusive";
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
function buildStructuredEndpoints(result: SecurityProbeResult): ProbeEndpointResult[] {
|
|
415
|
+
return result.verdicts.map((v) => ({
|
|
416
|
+
path: v.path,
|
|
417
|
+
method: v.method,
|
|
418
|
+
classes_run: Array.from(new Set(v.detectedFields.map((d) => d.class))),
|
|
419
|
+
findings: v.findings.map((f) => ({
|
|
420
|
+
class: f.class,
|
|
421
|
+
severity: findingSeverity(f.severity),
|
|
422
|
+
evidence: {
|
|
423
|
+
field: f.field,
|
|
424
|
+
payload: f.payload,
|
|
425
|
+
status: f.status,
|
|
426
|
+
echoed: f.echoed,
|
|
427
|
+
reason: f.reason,
|
|
428
|
+
...(f.recommended_action ? { recommended_action: f.recommended_action } : {}),
|
|
429
|
+
},
|
|
430
|
+
})),
|
|
431
|
+
status: statusFromSeverity(v.severity),
|
|
432
|
+
...(v.skipReason ? { skip_reason: v.skipReason } : {}),
|
|
433
|
+
}));
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
function byStatus(endpoints: ProbeEndpointResult[]): Record<ProbeEndpointStatus, number> {
|
|
437
|
+
const out: Record<ProbeEndpointStatus, number> = {
|
|
438
|
+
ok: 0, high: 0, low: 0, inconclusive: 0, skipped: 0,
|
|
439
|
+
};
|
|
440
|
+
for (const e of endpoints) out[e.status]++;
|
|
441
|
+
return out;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
function structuredReport(result: SecurityProbeResult, endpoints: ProbeEndpointResult[]): object {
|
|
445
|
+
return {
|
|
446
|
+
endpoints,
|
|
447
|
+
summary: {
|
|
448
|
+
totalEndpoints: result.totalEndpoints,
|
|
449
|
+
probed: result.specProbed,
|
|
450
|
+
by_status: byStatus(endpoints),
|
|
451
|
+
},
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
|