jso-protector 0.2.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 +960 -0
- package/LICENSE +90 -0
- package/MIGRATION.md +207 -0
- package/README.md +1477 -0
- package/RELEASE.md +82 -0
- package/SECURITY.md +71 -0
- package/ai-cli.js +392 -0
- package/ai.js +176 -0
- package/bin/jso-protector.js +12066 -0
- package/browserify.d.ts +10 -0
- package/browserify.js +88 -0
- package/bun.d.ts +10 -0
- package/bun.js +41 -0
- package/ci/Jenkinsfile +82 -0
- package/ci/argo-workflows.yaml +121 -0
- package/ci/azure-pipelines.yml +56 -0
- package/ci/bitbucket-pipelines.yml +43 -0
- package/ci/buildkite.yml +50 -0
- package/ci/circleci.yml +60 -0
- package/ci/drone.yml +67 -0
- package/ci/github-actions.yml +51 -0
- package/ci/gitlab-ci.yml +39 -0
- package/ci/gocd.yaml +79 -0
- package/ci/teamcity.kts +79 -0
- package/ci/tekton.yaml +106 -0
- package/ci/verify-package.js +748 -0
- package/ci/verify-publish-metadata.js +147 -0
- package/ci/verify-templates.js +195 -0
- package/ci/woodpecker.yml +53 -0
- package/compliance/cli.js +204 -0
- package/compliance/evidence-forwarder.js +209 -0
- package/compliance/pci-dss-v4/controls.json +75 -0
- package/compliance/pci-dss-v4/index.js +2613 -0
- package/config/named-sets.js +185 -0
- package/esbuild.d.ts +16 -0
- package/esbuild.js +190 -0
- package/examples/README.md +78 -0
- package/examples/browserify/build.js +20 -0
- package/examples/bun/package.json +13 -0
- package/examples/bun/scripts/protect-release.js +28 -0
- package/examples/cli-basic/jso.config.cjs +23 -0
- package/examples/cli-basic/jso.config.json +15 -0
- package/examples/cli-basic/package.json +14 -0
- package/examples/cli-basic/scripts/build.js +10 -0
- package/examples/curl/README.md +55 -0
- package/examples/curl/protect.sh +106 -0
- package/examples/esbuild/build.js +19 -0
- package/examples/grunt/Gruntfile.js +29 -0
- package/examples/gulp/gulpfile.js +19 -0
- package/examples/helm/Chart.yaml +27 -0
- package/examples/helm/README.md +69 -0
- package/examples/helm/templates/_helpers.tpl +23 -0
- package/examples/helm/templates/_podtemplate.tpl +64 -0
- package/examples/helm/templates/job.yaml +39 -0
- package/examples/helm/templates/secret.yaml +17 -0
- package/examples/helm/values.yaml +54 -0
- package/examples/kubernetes/job.yaml +123 -0
- package/examples/metro.config.js +11 -0
- package/examples/nextjs/next.config.js +11 -0
- package/examples/node-api/protect-release.js +28 -0
- package/examples/node-api/release-summary.js +59 -0
- package/examples/parcel/package.json +13 -0
- package/examples/parcel/scripts/protect-release.js +28 -0
- package/examples/payment-page-script-inventory.json +62 -0
- package/examples/payment-page-security-headers.json +46 -0
- package/examples/pre-commit/.pre-commit-config.yaml +33 -0
- package/examples/pre-commit/README.md +45 -0
- package/examples/react-native/README.md +208 -0
- package/examples/react-native/metro.config.js +11 -0
- package/examples/rollup/rollup.config.js +20 -0
- package/examples/rspack/rspack.config.js +28 -0
- package/examples/turbopack/package.json +13 -0
- package/examples/turbopack/scripts/protect-release.js +28 -0
- package/examples/vite/vite.config.js +18 -0
- package/examples/webpack/webpack.config.js +21 -0
- package/examples/webpack-loader/webpack.config.js +22 -0
- package/governance/index.d.ts +18 -0
- package/governance/index.js +309 -0
- package/grunt.d.ts +4 -0
- package/grunt.js +111 -0
- package/gulp.d.ts +10 -0
- package/gulp.js +106 -0
- package/index.d.ts +879 -0
- package/index.js +607 -0
- package/jso.config.example.json +29 -0
- package/jso.config.schema.json +548 -0
- package/metro.d.ts +43 -0
- package/metro.js +117 -0
- package/next.d.ts +24 -0
- package/next.js +64 -0
- package/package.json +241 -0
- package/parcel.d.ts +10 -0
- package/parcel.js +40 -0
- package/react-native.d.ts +2 -0
- package/react-native.js +3 -0
- package/release-signer.js +245 -0
- package/rollup.d.ts +13 -0
- package/rollup.js +71 -0
- package/rspack-loader.d.ts +13 -0
- package/rspack-loader.js +11 -0
- package/rspack.d.ts +11 -0
- package/rspack.js +9 -0
- package/runtime/ai-script-governance.js +379 -0
- package/runtime/countermeasures.js +0 -0
- package/runtime/data-exfiltration-guard.d.ts +7 -0
- package/runtime/data-exfiltration-guard.js +161 -0
- package/runtime/environment-integrity.js +389 -0
- package/runtime/managed-integrity.d.ts +4 -0
- package/runtime/managed-integrity.js +108 -0
- package/runtime/third-party-inventory.js +437 -0
- package/turbopack.d.ts +10 -0
- package/turbopack.js +41 -0
- package/vite.d.ts +16 -0
- package/vite.js +78 -0
- package/watermark.js +126 -0
- package/webpack-loader.d.ts +15 -0
- package/webpack-loader.js +97 -0
- package/webpack.d.ts +13 -0
- package/webpack.js +143 -0
|
@@ -0,0 +1,2613 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// PCI DSS v4.0.1 compliance reporter.
|
|
4
|
+
//
|
|
5
|
+
// Consumes the manifest + signed envelope produced by --sign-release and
|
|
6
|
+
// maps the JSO protection primitives onto the PCI DSS v4 controls JSO
|
|
7
|
+
// helps evidence (6.4.3 and 11.6.1). Emits a Markdown report an auditor
|
|
8
|
+
// or QSA can read directly, and a parallel JSON envelope for tooling.
|
|
9
|
+
//
|
|
10
|
+
// The reporter is pure data-shaping: it does NOT call the JSO HTTP API
|
|
11
|
+
// and it does NOT phone home. All evidence comes from artefacts already
|
|
12
|
+
// on disk (the manifest.json + manifest.json.sig + optional --root dir).
|
|
13
|
+
//
|
|
14
|
+
// Public API
|
|
15
|
+
// ----------
|
|
16
|
+
// generateReport(opts) -> { markdown, json, summary, exitCode }
|
|
17
|
+
//
|
|
18
|
+
// opts:
|
|
19
|
+
// manifestPath string (required) -- path to .manifest.json.sig
|
|
20
|
+
// or to a bare manifest.json (less evidence)
|
|
21
|
+
// rootDir string (optional) -- if set, re-hash files on
|
|
22
|
+
// disk and confirm they still match the manifest
|
|
23
|
+
// organizationName string (optional) -- shown in the report header
|
|
24
|
+
// buildLabel string (optional) -- override the manifest label
|
|
25
|
+
// watermarkKey string (optional) -- if set, validate per-file
|
|
26
|
+
// watermark HMACs against this key (treated as the
|
|
27
|
+
// same shared secret the customer used at build)
|
|
28
|
+
// beaconUrl string (optional) -- URL of the configured beacon
|
|
29
|
+
// callback. If present, the 11.6.1.c evidence row
|
|
30
|
+
// gets "Wired" status; if absent, "Not configured".
|
|
31
|
+
// siemAdapter string (optional) -- one of "splunk-hec",
|
|
32
|
+
// "elasticsearch", "webhook". If set, the report
|
|
33
|
+
// names the forwarder.
|
|
34
|
+
// scriptInventoryPath string (optional) -- CSV or JSON payment-page script
|
|
35
|
+
// inventory. The report summarizes authorization,
|
|
36
|
+
// justification, owner, review-date, and integrity
|
|
37
|
+
// coverage without embedding every raw script URL.
|
|
38
|
+
// scriptInventoryAuditPath string (optional) -- JSON output from
|
|
39
|
+
// `jso-protector --script-inventory-audit --json`.
|
|
40
|
+
// The report summarizes approved-vs-observed drift
|
|
41
|
+
// without embedding every raw finding row in controls.
|
|
42
|
+
// securityHeadersPath string (optional) -- CSV or JSON payment-page
|
|
43
|
+
// security-header snapshot. The report summarizes CSP,
|
|
44
|
+
// frame/HSTS/referrer-policy, baseline hash, monitor,
|
|
45
|
+
// and alert-route evidence without embedding every URL.
|
|
46
|
+
// runtimeIncidentsPath string (optional) -- CSV or JSON exported from
|
|
47
|
+
// Dashboard Monitoring. The report summarizes incident
|
|
48
|
+
// counts, triage status, severity, date range, and
|
|
49
|
+
// Build IDs without embedding each row's URL/user-agent
|
|
50
|
+
// data in Markdown.
|
|
51
|
+
// includeUnsignedManifest bool -- accept bare manifest.json (no .sig).
|
|
52
|
+
// Default false. When false, a bare manifest
|
|
53
|
+
// triggers exitCode=2 (incomplete evidence) and the
|
|
54
|
+
// 6.4.3.b row reads "Not signed".
|
|
55
|
+
|
|
56
|
+
const fs = require("node:fs");
|
|
57
|
+
const path = require("node:path");
|
|
58
|
+
const crypto = require("node:crypto");
|
|
59
|
+
const releaseSigner = require("../../release-signer.js");
|
|
60
|
+
const watermark = require("../../watermark.js");
|
|
61
|
+
const controlsRef = require("./controls.json");
|
|
62
|
+
|
|
63
|
+
const REPORT_SCHEMA_VERSION = 1;
|
|
64
|
+
|
|
65
|
+
function generateReport(opts) {
|
|
66
|
+
if (!opts || typeof opts !== "object") {
|
|
67
|
+
throw new Error("generateReport: opts is required");
|
|
68
|
+
}
|
|
69
|
+
if (!opts.manifestPath || typeof opts.manifestPath !== "string") {
|
|
70
|
+
throw new Error("generateReport: opts.manifestPath is required");
|
|
71
|
+
}
|
|
72
|
+
if (!fs.existsSync(opts.manifestPath)) {
|
|
73
|
+
throw new Error("generateReport: manifest not found: " + opts.manifestPath);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const evidence = collectEvidence(opts);
|
|
77
|
+
const controls = mapControls(evidence, controlsRef);
|
|
78
|
+
const summary = buildSummary(controls, evidence);
|
|
79
|
+
const reviewAssistant = buildPciDssReviewAssistant(summary, controls, evidence);
|
|
80
|
+
const markdown = renderMarkdown({
|
|
81
|
+
organizationName: opts.organizationName || "",
|
|
82
|
+
buildLabel: opts.buildLabel || evidence.manifest.label || "",
|
|
83
|
+
generatedAt: opts.now || new Date().toISOString(),
|
|
84
|
+
evidence: evidence,
|
|
85
|
+
controls: controls,
|
|
86
|
+
summary: summary,
|
|
87
|
+
reviewAssistant: reviewAssistant,
|
|
88
|
+
});
|
|
89
|
+
return {
|
|
90
|
+
markdown: markdown,
|
|
91
|
+
json: {
|
|
92
|
+
v: REPORT_SCHEMA_VERSION,
|
|
93
|
+
standard: controlsRef._meta.standard,
|
|
94
|
+
version: controlsRef._meta.version,
|
|
95
|
+
generatedAt: opts.now || new Date().toISOString(),
|
|
96
|
+
organizationName: opts.organizationName || null,
|
|
97
|
+
buildLabel: opts.buildLabel || evidence.manifest.label || null,
|
|
98
|
+
buildId: evidence.manifest.buildId || null,
|
|
99
|
+
polymorphismFingerprint: evidence.manifest.polymorphismFingerprint || null,
|
|
100
|
+
files: evidence.files,
|
|
101
|
+
scriptInventory: evidence.scriptInventory,
|
|
102
|
+
scriptInventoryAudit: evidence.scriptInventoryAudit,
|
|
103
|
+
securityHeaders: evidence.securityHeaders,
|
|
104
|
+
runtimeIncidents: evidence.runtimeIncidents,
|
|
105
|
+
controls: controls,
|
|
106
|
+
summary: summary,
|
|
107
|
+
reviewAssistant: reviewAssistant,
|
|
108
|
+
},
|
|
109
|
+
summary: summary,
|
|
110
|
+
// exitCode: 0=fully evidenced, 1=evidence gaps that need
|
|
111
|
+
// operator action, 2=manifest is unsigned or unreadable.
|
|
112
|
+
exitCode: summary.exitCode,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function collectEvidence(opts) {
|
|
117
|
+
const raw = JSON.parse(fs.readFileSync(opts.manifestPath, "utf8"));
|
|
118
|
+
|
|
119
|
+
// Distinguish a signed envelope from a bare manifest.json. The
|
|
120
|
+
// signed envelope has top-level .manifest + .signature + .publicKey.
|
|
121
|
+
const isSignedEnvelope = !!(raw && raw.manifest && raw.signature && raw.publicKey);
|
|
122
|
+
|
|
123
|
+
let manifest;
|
|
124
|
+
let signatureStatus;
|
|
125
|
+
let publicKeyDigest = null;
|
|
126
|
+
|
|
127
|
+
if (isSignedEnvelope) {
|
|
128
|
+
manifest = raw.manifest;
|
|
129
|
+
// Verify the embedded signature. release-signer.verifyRelease
|
|
130
|
+
// returns { valid, stage1, stage2, mismatches, error }. Stage 2
|
|
131
|
+
// only fires when we pass verifyRoot.
|
|
132
|
+
try {
|
|
133
|
+
// release-signer.verifyRelease() reads opts.fileRoot (not
|
|
134
|
+
// verifyRoot) for the stage-2 on-disk re-hash pass.
|
|
135
|
+
const verifyResult = releaseSigner.verifyRelease(raw, {
|
|
136
|
+
fileRoot: opts.rootDir || null,
|
|
137
|
+
});
|
|
138
|
+
signatureStatus = {
|
|
139
|
+
kind: "ed25519",
|
|
140
|
+
verified: !!verifyResult.valid,
|
|
141
|
+
stage1: !!verifyResult.stage1,
|
|
142
|
+
stage2: !!verifyResult.stage2,
|
|
143
|
+
detail: verifyResult.valid
|
|
144
|
+
? "Signature valid; manifest is genuine."
|
|
145
|
+
: ("Signature INVALID: " + (verifyResult.error || "unknown")),
|
|
146
|
+
mismatches: Array.isArray(verifyResult.mismatches) ? verifyResult.mismatches : [],
|
|
147
|
+
};
|
|
148
|
+
} catch (x) {
|
|
149
|
+
signatureStatus = {
|
|
150
|
+
kind: "ed25519",
|
|
151
|
+
verified: false,
|
|
152
|
+
stage1: false,
|
|
153
|
+
stage2: false,
|
|
154
|
+
detail: "Signature verification threw: " + x.message,
|
|
155
|
+
mismatches: [],
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
// Compute a stable identifier for the signing key so the auditor
|
|
159
|
+
// can confirm two reports were signed by the same release key.
|
|
160
|
+
try {
|
|
161
|
+
const pubDer = Buffer.from(raw.publicKey, "base64");
|
|
162
|
+
publicKeyDigest = crypto.createHash("sha256").update(pubDer).digest("hex");
|
|
163
|
+
} catch (x) { publicKeyDigest = null; }
|
|
164
|
+
} else if (opts.includeUnsignedManifest) {
|
|
165
|
+
manifest = raw;
|
|
166
|
+
signatureStatus = {
|
|
167
|
+
kind: "none",
|
|
168
|
+
verified: false,
|
|
169
|
+
stage1: false,
|
|
170
|
+
stage2: false,
|
|
171
|
+
detail: "Manifest is unsigned. PCI DSS v4 req 6.4.3.b cannot be evidenced without --sign-release.",
|
|
172
|
+
mismatches: [],
|
|
173
|
+
};
|
|
174
|
+
} else {
|
|
175
|
+
throw new Error(
|
|
176
|
+
"generateReport: manifest at " + opts.manifestPath + " is not a signed envelope. " +
|
|
177
|
+
"Re-run with --sign-release to produce a .manifest.json.sig, or pass " +
|
|
178
|
+
"{includeUnsignedManifest:true} to allow a partial report."
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (!manifest || !Array.isArray(manifest.files)) {
|
|
183
|
+
throw new Error("generateReport: manifest is missing files[]");
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Per-file watermark coverage. If --watermark-key was supplied, we
|
|
187
|
+
// attempt to validate every file's watermark; otherwise we only
|
|
188
|
+
// attempt to detect presence (no signature check). When --root is
|
|
189
|
+
// provided we read the actual file bytes; otherwise the row stays
|
|
190
|
+
// "not inspected".
|
|
191
|
+
const files = manifest.files.map(function (f) {
|
|
192
|
+
const row = {
|
|
193
|
+
name: f.name,
|
|
194
|
+
sha256: f.sha256,
|
|
195
|
+
watermark: { inspected: false, present: false, valid: null, tag: null },
|
|
196
|
+
ondiskSha256: null,
|
|
197
|
+
ondiskMatches: null,
|
|
198
|
+
};
|
|
199
|
+
if (opts.rootDir) {
|
|
200
|
+
const fullPath = path.join(opts.rootDir, f.name);
|
|
201
|
+
if (fs.existsSync(fullPath)) {
|
|
202
|
+
// Read raw bytes (Buffer), not utf8 — otherwise any
|
|
203
|
+
// non-UTF-8 byte in a protected file (BOM, binary
|
|
204
|
+
// asset, lone surrogate) makes the locally computed
|
|
205
|
+
// sha256 disagree with release-signer.sha256OfFile
|
|
206
|
+
// (which hashes raw bytes) and the row would
|
|
207
|
+
// mis-report ondiskMatches=false even when stage-2
|
|
208
|
+
// signature verification passed.
|
|
209
|
+
let buf;
|
|
210
|
+
try { buf = fs.readFileSync(fullPath); } catch (x) { buf = null; }
|
|
211
|
+
if (buf != null) {
|
|
212
|
+
row.ondiskSha256 = crypto.createHash("sha256").update(buf).digest("hex");
|
|
213
|
+
row.ondiskMatches = (row.ondiskSha256 === f.sha256);
|
|
214
|
+
row.watermark.inspected = true;
|
|
215
|
+
try {
|
|
216
|
+
// watermark.verify accepts strings; coerce
|
|
217
|
+
// only here so the hash above stays byte-exact.
|
|
218
|
+
const r = watermark.verify(buf.toString("utf8"), opts.watermarkKey || undefined);
|
|
219
|
+
if (r && r.present) {
|
|
220
|
+
row.watermark.present = true;
|
|
221
|
+
row.watermark.tag = r.tag || null;
|
|
222
|
+
row.watermark.valid = opts.watermarkKey ? !!r.valid : null;
|
|
223
|
+
}
|
|
224
|
+
} catch (x) { /* swallow; row reports absence */ }
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return row;
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
const runtimeIncidents = opts.runtimeIncidentsPath
|
|
232
|
+
? collectRuntimeIncidentEvidence(opts.runtimeIncidentsPath)
|
|
233
|
+
: null;
|
|
234
|
+
const scriptInventory = opts.scriptInventoryPath
|
|
235
|
+
? collectScriptInventoryEvidence(opts.scriptInventoryPath)
|
|
236
|
+
: null;
|
|
237
|
+
const scriptInventoryAudit = opts.scriptInventoryAuditPath
|
|
238
|
+
? collectScriptInventoryAuditEvidence(opts.scriptInventoryAuditPath)
|
|
239
|
+
: null;
|
|
240
|
+
const securityHeaders = opts.securityHeadersPath
|
|
241
|
+
? collectSecurityHeaderEvidence(opts.securityHeadersPath)
|
|
242
|
+
: null;
|
|
243
|
+
|
|
244
|
+
return {
|
|
245
|
+
manifest: manifest,
|
|
246
|
+
signatureStatus: signatureStatus,
|
|
247
|
+
publicKeyDigest: publicKeyDigest,
|
|
248
|
+
files: files,
|
|
249
|
+
beaconUrl: opts.beaconUrl || null,
|
|
250
|
+
siemAdapter: opts.siemAdapter || null,
|
|
251
|
+
scriptInventory: scriptInventory,
|
|
252
|
+
scriptInventoryAudit: scriptInventoryAudit,
|
|
253
|
+
securityHeaders: securityHeaders,
|
|
254
|
+
runtimeIncidents: runtimeIncidents,
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function mapControls(evidence, ref) {
|
|
259
|
+
const watermarkCoverage = computeWatermarkCoverage(evidence.files);
|
|
260
|
+
return ref.controls.map(function (control) {
|
|
261
|
+
const subRows = control.subRequirements.map(function (sub) {
|
|
262
|
+
const status = evaluateSubRequirement(sub, evidence, watermarkCoverage);
|
|
263
|
+
return Object.assign({}, sub, status);
|
|
264
|
+
});
|
|
265
|
+
const allPass = subRows.every(function (r) { return r.status === "pass"; });
|
|
266
|
+
const anyFail = subRows.some(function (r) { return r.status === "fail"; });
|
|
267
|
+
return {
|
|
268
|
+
id: control.id,
|
|
269
|
+
title: control.title,
|
|
270
|
+
status: anyFail ? "fail" : (allPass ? "pass" : "partial"),
|
|
271
|
+
subRequirements: subRows,
|
|
272
|
+
};
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function evaluateSubRequirement(sub, evidence, watermarkCoverage) {
|
|
277
|
+
// Pure data lookup; no side effects, no I/O.
|
|
278
|
+
const evidenceRows = [];
|
|
279
|
+
let status = "fail";
|
|
280
|
+
let detail = "";
|
|
281
|
+
switch (sub.id) {
|
|
282
|
+
case "6.4.3.a":
|
|
283
|
+
if (watermarkCoverage.allValid) {
|
|
284
|
+
status = "pass";
|
|
285
|
+
detail = "All " + watermarkCoverage.total + " files carry a watermark with a valid signature under the supplied key.";
|
|
286
|
+
} else if (watermarkCoverage.allPresent) {
|
|
287
|
+
status = "partial";
|
|
288
|
+
detail = "All " + watermarkCoverage.total + " files carry a watermark, but signatures are not validated (pass --watermark-key to verify).";
|
|
289
|
+
} else if (watermarkCoverage.anyPresent) {
|
|
290
|
+
status = "partial";
|
|
291
|
+
detail = watermarkCoverage.withWatermark + "/" + watermarkCoverage.total + " files carry a watermark.";
|
|
292
|
+
} else if (!watermarkCoverage.inspected) {
|
|
293
|
+
status = "not_inspected";
|
|
294
|
+
detail = "Pass --root <dir> to walk the protected files on disk and report watermark coverage.";
|
|
295
|
+
} else {
|
|
296
|
+
status = "fail";
|
|
297
|
+
detail = "No watermarks detected. Re-run jso-protector with --watermark <tag> --watermark-key <secret>.";
|
|
298
|
+
}
|
|
299
|
+
if (hasScriptInventoryRows(evidence)) {
|
|
300
|
+
const si = evidence.scriptInventory;
|
|
301
|
+
if (si.unauthorizedCount > 0 || si.unknownAuthorizationCount > 0) {
|
|
302
|
+
if (status === "pass") status = "partial";
|
|
303
|
+
detail += " " + si.unauthorizedCount + " script(s) are marked unauthorized and " + si.unknownAuthorizationCount + " have unknown authorization in the supplied script inventory.";
|
|
304
|
+
} else {
|
|
305
|
+
detail += " Script inventory marks all " + si.count + " payment-page script(s) as authorized.";
|
|
306
|
+
}
|
|
307
|
+
pushScriptInventoryEvidence(evidenceRows, evidence);
|
|
308
|
+
}
|
|
309
|
+
if (hasScriptInventoryAudit(evidence)) {
|
|
310
|
+
const audit = evidence.scriptInventoryAudit;
|
|
311
|
+
if (audit.unknownObserved > 0 || audit.unauthorizedObserved > 0) {
|
|
312
|
+
if (status === "pass") status = "partial";
|
|
313
|
+
detail += " Script inventory audit found " + audit.unknownObserved + " unknown observed script(s) and " + audit.unauthorizedObserved + " unauthorized observed script(s).";
|
|
314
|
+
} else {
|
|
315
|
+
detail += " Script inventory audit found no unknown or unauthorized observed scripts.";
|
|
316
|
+
}
|
|
317
|
+
pushScriptInventoryAuditEvidence(evidenceRows, evidence);
|
|
318
|
+
}
|
|
319
|
+
evidenceRows.push({
|
|
320
|
+
artefact: "HMAC-SHA256 watermark per file",
|
|
321
|
+
location: "Protected file header comment",
|
|
322
|
+
citation: "jso-protector --watermark / watermark.js",
|
|
323
|
+
});
|
|
324
|
+
break;
|
|
325
|
+
case "6.4.3.b":
|
|
326
|
+
if (evidence.signatureStatus.kind === "ed25519" && evidence.signatureStatus.verified) {
|
|
327
|
+
status = "pass";
|
|
328
|
+
detail = evidence.signatureStatus.detail;
|
|
329
|
+
evidenceRows.push({
|
|
330
|
+
artefact: "Ed25519 release attestation",
|
|
331
|
+
location: ".manifest.json.sig (publicKeyDigest=" + (evidence.publicKeyDigest || "n/a").slice(0, 16) + "...)",
|
|
332
|
+
citation: "jso-protector --sign-release / release-signer.js",
|
|
333
|
+
});
|
|
334
|
+
if (evidence.signatureStatus.stage2) {
|
|
335
|
+
evidenceRows.push({
|
|
336
|
+
artefact: "Stage-2 on-disk re-hash (all files match manifest sha256)",
|
|
337
|
+
location: "--root <dir> verification pass",
|
|
338
|
+
citation: "release-signer.verifyRelease() stage 2",
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
} else if (evidence.signatureStatus.kind === "ed25519") {
|
|
342
|
+
status = "fail";
|
|
343
|
+
detail = evidence.signatureStatus.detail;
|
|
344
|
+
} else {
|
|
345
|
+
status = "fail";
|
|
346
|
+
detail = evidence.signatureStatus.detail;
|
|
347
|
+
}
|
|
348
|
+
break;
|
|
349
|
+
case "6.4.3.c":
|
|
350
|
+
if (hasScriptInventoryRows(evidence)) {
|
|
351
|
+
const si = evidence.scriptInventory;
|
|
352
|
+
if (si.missingJustificationCount === 0) {
|
|
353
|
+
status = "pass";
|
|
354
|
+
detail = "Script inventory export records " + si.count + " payment-page script(s) with authorization and written justification. Manifest files[] still provides the protected first-party file inventory (" + evidence.files.length + " files).";
|
|
355
|
+
} else {
|
|
356
|
+
status = "partial";
|
|
357
|
+
detail = "Script inventory export records " + si.count + " payment-page script(s), but " + si.missingJustificationCount + " lack written justification. Fill justification before audit handoff.";
|
|
358
|
+
}
|
|
359
|
+
detail += scriptInventoryReviewContextDetail(si);
|
|
360
|
+
pushScriptInventoryEvidence(evidenceRows, evidence);
|
|
361
|
+
evidenceRows.push({
|
|
362
|
+
artefact: "manifest.json files[] array",
|
|
363
|
+
location: "Path supplied to --manifest",
|
|
364
|
+
citation: "release-signer.signRelease().manifest.files",
|
|
365
|
+
});
|
|
366
|
+
} else if (Array.isArray(evidence.files) && evidence.files.length > 0) {
|
|
367
|
+
status = "pass";
|
|
368
|
+
detail = "Manifest files[] is the technical inventory (" + evidence.files.length + " files). buildId + polymorphismFingerprint trace each entry back to a JSO build run. Pass --script-inventory <csv|json> when a reviewer needs written business justification for every payment-page script.";
|
|
369
|
+
evidenceRows.push({
|
|
370
|
+
artefact: "manifest.json files[] array",
|
|
371
|
+
location: "Path supplied to --manifest",
|
|
372
|
+
citation: "release-signer.signRelease().manifest.files",
|
|
373
|
+
});
|
|
374
|
+
} else {
|
|
375
|
+
status = "fail";
|
|
376
|
+
detail = "Manifest contains no files.";
|
|
377
|
+
}
|
|
378
|
+
if (hasScriptInventoryAudit(evidence)) {
|
|
379
|
+
const audit = evidence.scriptInventoryAudit;
|
|
380
|
+
if (!audit.ok) {
|
|
381
|
+
if (status === "pass") status = "partial";
|
|
382
|
+
detail += scriptInventoryAuditDetail(evidence);
|
|
383
|
+
} else {
|
|
384
|
+
detail += " Script inventory audit reconciles the approved inventory against the observed runtime snapshot with no blocking issues.";
|
|
385
|
+
}
|
|
386
|
+
pushScriptInventoryAuditEvidence(evidenceRows, evidence);
|
|
387
|
+
}
|
|
388
|
+
break;
|
|
389
|
+
case "11.6.1.a":
|
|
390
|
+
// We can't, from a static manifest, prove the protected files
|
|
391
|
+
// actually enable the runtime-defense modules. But we can flag
|
|
392
|
+
// whether SelfDefending / integrity-heartbeat are evidenced by
|
|
393
|
+
// the build options if the customer ran with the recommended
|
|
394
|
+
// config. For now we report "needs_attestation" unless the
|
|
395
|
+
// beacon URL is wired (a strong proxy for the defense suite).
|
|
396
|
+
if (evidence.beaconUrl) {
|
|
397
|
+
status = "pass";
|
|
398
|
+
detail = "Runtime Defense beacon is configured (" + redactUrl(evidence.beaconUrl) + "). Tamper events fire on integrity heartbeat or self-defending checks." + runtimeIncidentDetail(evidence);
|
|
399
|
+
evidenceRows.push({
|
|
400
|
+
artefact: "BeaconUrl + Runtime Defense suite",
|
|
401
|
+
location: "Build option BeaconUrl + runtime/defense.ts",
|
|
402
|
+
citation: "Docs/RuntimeDefense.aspx",
|
|
403
|
+
});
|
|
404
|
+
pushRuntimeIncidentEvidence(evidenceRows, evidence);
|
|
405
|
+
} else if (hasRuntimeIncidentRows(evidence)) {
|
|
406
|
+
status = "partial";
|
|
407
|
+
detail = "Dashboard Monitoring incident evidence was supplied, but no BeaconUrl was supplied to the reporter. Re-run with --beacon-url <url> to tie this build report to the runtime-defense endpoint." + runtimeIncidentDetail(evidence);
|
|
408
|
+
pushRuntimeIncidentEvidence(evidenceRows, evidence);
|
|
409
|
+
} else {
|
|
410
|
+
status = "partial";
|
|
411
|
+
detail = "Runtime Defense modules can be enabled (SelfDefending, integrity heartbeat) but no BeaconUrl was supplied to the reporter. Re-run with --beacon-url <url> to evidence this row.";
|
|
412
|
+
}
|
|
413
|
+
if (hasScriptInventoryAudit(evidence)) {
|
|
414
|
+
detail += scriptInventoryAuditDetail(evidence);
|
|
415
|
+
pushScriptInventoryAuditEvidence(evidenceRows, evidence);
|
|
416
|
+
}
|
|
417
|
+
if (hasSecurityHeaderEvidence(evidence)) {
|
|
418
|
+
detail += securityHeaderDetail(evidence);
|
|
419
|
+
pushSecurityHeaderEvidence(evidenceRows, evidence);
|
|
420
|
+
}
|
|
421
|
+
break;
|
|
422
|
+
case "11.6.1.b":
|
|
423
|
+
if (evidence.beaconUrl) {
|
|
424
|
+
status = "pass";
|
|
425
|
+
detail = "Beacon callback fires per-tamper-event in addition to heartbeat, which is more frequent than the seven-day floor." + runtimeIncidentDetail(evidence);
|
|
426
|
+
pushRuntimeIncidentEvidence(evidenceRows, evidence);
|
|
427
|
+
} else if (hasRuntimeIncidentRows(evidence)) {
|
|
428
|
+
status = "partial";
|
|
429
|
+
detail = "Runtime incident export shows Dashboard Monitoring received browser-side events, but no BeaconUrl was supplied to evidence the configured heartbeat destination." + runtimeIncidentDetail(evidence);
|
|
430
|
+
pushRuntimeIncidentEvidence(evidenceRows, evidence);
|
|
431
|
+
} else {
|
|
432
|
+
status = "partial";
|
|
433
|
+
detail = "Without a BeaconUrl this control is not actively evidenced. Cadence is implementation-defined when the beacon is wired.";
|
|
434
|
+
}
|
|
435
|
+
if (hasSecurityHeaderEvidence(evidence)) {
|
|
436
|
+
detail += securityHeaderDetail(evidence);
|
|
437
|
+
pushSecurityHeaderEvidence(evidenceRows, evidence);
|
|
438
|
+
}
|
|
439
|
+
break;
|
|
440
|
+
case "11.6.1.c":
|
|
441
|
+
if (evidence.siemAdapter) {
|
|
442
|
+
status = "pass";
|
|
443
|
+
detail = "SIEM adapter '" + evidence.siemAdapter + "' is configured. Beacon events route to on-call surface via jso-beacon-slack adapters/" + evidence.siemAdapter + ".js." + runtimeIncidentDetail(evidence);
|
|
444
|
+
evidenceRows.push({
|
|
445
|
+
artefact: "jso-beacon-slack SIEM adapter",
|
|
446
|
+
location: "packages/jso-beacon-slack/adapters/" + evidence.siemAdapter + ".js",
|
|
447
|
+
citation: "Docs/RuntimeDefense.aspx (SIEM forwarding)",
|
|
448
|
+
});
|
|
449
|
+
pushRuntimeIncidentEvidence(evidenceRows, evidence);
|
|
450
|
+
} else if (evidence.beaconUrl) {
|
|
451
|
+
status = "partial";
|
|
452
|
+
detail = "Beacon is wired but no SIEM forwarder is named. Pass --siem splunk-hec | elasticsearch | webhook to evidence personnel alerts." + runtimeIncidentDetail(evidence);
|
|
453
|
+
pushRuntimeIncidentEvidence(evidenceRows, evidence);
|
|
454
|
+
} else if (hasRuntimeIncidentRows(evidence)) {
|
|
455
|
+
status = "partial";
|
|
456
|
+
detail = "Dashboard Monitoring incident evidence was supplied, but no SIEM or on-call forwarder is named. Pass --beacon-url and --siem to evidence personnel alerts end to end." + runtimeIncidentDetail(evidence);
|
|
457
|
+
pushRuntimeIncidentEvidence(evidenceRows, evidence);
|
|
458
|
+
} else if (hasSecurityHeaderEvidence(evidence)) {
|
|
459
|
+
status = "partial";
|
|
460
|
+
detail = "Payment-page security-header evidence was supplied, but no Runtime Defense beacon or SIEM/on-call forwarder is named. Use this as source-free header-monitoring evidence and pass --beacon-url plus --siem when runtime alerts are wired." + securityHeaderDetail(evidence);
|
|
461
|
+
pushSecurityHeaderEvidence(evidenceRows, evidence);
|
|
462
|
+
} else {
|
|
463
|
+
status = "fail";
|
|
464
|
+
detail = "Neither beacon nor SIEM adapter is configured. Personnel alerts are not evidenced.";
|
|
465
|
+
}
|
|
466
|
+
if (hasSecurityHeaderEvidence(evidence) && (evidence.siemAdapter || evidence.beaconUrl || hasRuntimeIncidentRows(evidence))) {
|
|
467
|
+
detail += securityHeaderDetail(evidence);
|
|
468
|
+
pushSecurityHeaderEvidence(evidenceRows, evidence);
|
|
469
|
+
}
|
|
470
|
+
break;
|
|
471
|
+
default:
|
|
472
|
+
status = "not_inspected";
|
|
473
|
+
detail = "No mapping defined.";
|
|
474
|
+
}
|
|
475
|
+
return { status: status, detail: detail, evidence: evidenceRows };
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
function computeWatermarkCoverage(files) {
|
|
479
|
+
let total = 0, inspected = 0, present = 0, valid = 0;
|
|
480
|
+
for (const f of files) {
|
|
481
|
+
total++;
|
|
482
|
+
if (f.watermark.inspected) inspected++;
|
|
483
|
+
if (f.watermark.present) present++;
|
|
484
|
+
if (f.watermark.valid === true) valid++;
|
|
485
|
+
}
|
|
486
|
+
return {
|
|
487
|
+
total: total,
|
|
488
|
+
inspectedCount: inspected,
|
|
489
|
+
inspected: inspected > 0,
|
|
490
|
+
withWatermark: present,
|
|
491
|
+
withValidSignature: valid,
|
|
492
|
+
anyPresent: present > 0,
|
|
493
|
+
allPresent: total > 0 && present === total,
|
|
494
|
+
allValid: total > 0 && valid === total,
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
function collectScriptInventoryEvidence(inventoryPath) {
|
|
499
|
+
if (!fs.existsSync(inventoryPath)) {
|
|
500
|
+
throw new Error("generateReport: script inventory export not found: " + inventoryPath);
|
|
501
|
+
}
|
|
502
|
+
const bytes = fs.readFileSync(inventoryPath);
|
|
503
|
+
const text = stripUtf8Bom(bytes.toString("utf8"));
|
|
504
|
+
const trimmed = text.trimStart();
|
|
505
|
+
if (/\.json$/i.test(inventoryPath) || trimmed[0] === "{") {
|
|
506
|
+
return collectScriptInventoryJsonEvidence(inventoryPath, bytes, text);
|
|
507
|
+
}
|
|
508
|
+
return collectScriptInventoryCsvEvidence(inventoryPath, bytes, text);
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
function collectScriptInventoryCsvEvidence(csvPath, bytes, text) {
|
|
512
|
+
const parsed = parseCsv(text);
|
|
513
|
+
const records = parsed.records.map(normalizeScriptInventoryRecord);
|
|
514
|
+
return summarizeScriptInventoryRecords(csvPath, bytes, "csv", parsed.headers, records);
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
function collectScriptInventoryJsonEvidence(jsonPath, bytes, text) {
|
|
518
|
+
let payload;
|
|
519
|
+
try {
|
|
520
|
+
payload = JSON.parse(text);
|
|
521
|
+
} catch (x) {
|
|
522
|
+
throw new Error("generateReport: script inventory JSON is not valid JSON: " + x.message);
|
|
523
|
+
}
|
|
524
|
+
const rows = payload && typeof payload === "object"
|
|
525
|
+
? (payload.scripts || payload.inventory || payload.items)
|
|
526
|
+
: null;
|
|
527
|
+
if (!Array.isArray(rows)) {
|
|
528
|
+
throw new Error("generateReport: script inventory JSON is missing scripts[]");
|
|
529
|
+
}
|
|
530
|
+
const records = rows.map(normalizeScriptInventoryRecord);
|
|
531
|
+
return summarizeScriptInventoryRecords(jsonPath, bytes, "json", [
|
|
532
|
+
"Source", "Authorized", "Justification", "Owner", "Category",
|
|
533
|
+
"Integrity", "LastReviewedUtc", "CheckoutSurface", "FrameContext",
|
|
534
|
+
"FrameOwner", "ParentPageHref", "FrameHref", "FrameOrigin",
|
|
535
|
+
"Risk", "DataAccess", "ApprovalTicket",
|
|
536
|
+
], records);
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
function normalizeScriptInventoryRecord(row) {
|
|
540
|
+
row = row && typeof row === "object" ? row : {};
|
|
541
|
+
return {
|
|
542
|
+
Source: firstJsonValue(row, "Source", "source", "Src", "src", "Url", "URL", "url"),
|
|
543
|
+
Authorized: firstJsonValue(row, "Authorized", "authorized", "Approved", "approved", "Status", "status"),
|
|
544
|
+
Justification: firstJsonValue(row, "Justification", "justification", "Reason", "reason", "BusinessJustification", "businessJustification"),
|
|
545
|
+
Owner: firstJsonValue(row, "Owner", "owner", "Team", "team"),
|
|
546
|
+
Category: firstJsonValue(row, "Category", "category", "Type", "type"),
|
|
547
|
+
Integrity: firstJsonValue(row, "Integrity", "integrity", "Sri", "SRI", "sri", "Sha256", "sha256", "Hash", "hash"),
|
|
548
|
+
LastReviewedUtc: firstJsonValue(row, "LastReviewedUtc", "lastReviewedUtc", "LastReviewed", "lastReviewed", "ReviewedUtc", "reviewedUtc"),
|
|
549
|
+
CheckoutSurface: firstJsonValue(row, "CheckoutSurface", "checkoutSurface", "PaymentSurface", "paymentSurface", "Surface", "surface"),
|
|
550
|
+
FrameContext: firstJsonValue(row, "FrameContext", "frameContext", "FrameRole", "frameRole", "Frame", "frame"),
|
|
551
|
+
FrameOwner: firstJsonValue(row, "FrameOwner", "frameOwner", "IframeOwner", "iframeOwner"),
|
|
552
|
+
ParentPageHref: firstJsonValue(row, "ParentPageHref", "parentPageHref", "ParentHref", "parentHref"),
|
|
553
|
+
FrameHref: firstJsonValue(row, "FrameHref", "frameHref", "IframeHref", "iframeHref"),
|
|
554
|
+
FrameOrigin: firstJsonValue(row, "FrameOrigin", "frameOrigin", "IframeOrigin", "iframeOrigin"),
|
|
555
|
+
Risk: firstJsonValue(row, "Risk", "risk", "RiskRating", "riskRating", "RiskLevel", "riskLevel"),
|
|
556
|
+
DataAccess: firstJsonValue(row, "DataAccess", "dataAccess", "DataAccessScope", "dataAccessScope", "DataCategory", "dataCategory", "SensitiveDataAccess", "sensitiveDataAccess"),
|
|
557
|
+
ApprovalTicket: firstJsonValue(row, "ApprovalTicket", "approvalTicket", "Ticket", "ticket", "ChangeTicket", "changeTicket", "ApprovalId", "approvalId"),
|
|
558
|
+
};
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
function summarizeScriptInventoryRecords(inventoryPath, bytes, sourceFormat, columns, records) {
|
|
562
|
+
records = Array.isArray(records) ? records : [];
|
|
563
|
+
const authStates = records.map(function (r) { return authorizationState(r.Authorized); });
|
|
564
|
+
const authorizedCount = authStates.filter(function (s) { return s === "authorized"; }).length;
|
|
565
|
+
const unauthorizedCount = authStates.filter(function (s) { return s === "unauthorized"; }).length;
|
|
566
|
+
const unknownAuthorizationCount = authStates.filter(function (s) { return s === "unknown"; }).length;
|
|
567
|
+
const withJustificationCount = records.filter(function (r) { return normalizeCsvCell(r.Justification) !== ""; }).length;
|
|
568
|
+
const withOwnerCount = records.filter(function (r) { return normalizeCsvCell(r.Owner) !== ""; }).length;
|
|
569
|
+
const withIntegrityReferenceCount = records.filter(function (r) { return normalizeCsvCell(r.Integrity) !== ""; }).length;
|
|
570
|
+
const withRiskRatingCount = records.filter(function (r) { return normalizeCsvCell(r.Risk) !== ""; }).length;
|
|
571
|
+
const withDataAccessCount = records.filter(function (r) { return normalizeCsvCell(r.DataAccess) !== ""; }).length;
|
|
572
|
+
const withApprovalTicketCount = records.filter(function (r) { return normalizeCsvCell(r.ApprovalTicket) !== ""; }).length;
|
|
573
|
+
const withCheckoutSurfaceCount = records.filter(function (r) { return normalizeCsvCell(r.CheckoutSurface) !== ""; }).length;
|
|
574
|
+
const withFrameContextCount = records.filter(function (r) { return normalizeCsvCell(r.FrameContext) !== ""; }).length;
|
|
575
|
+
const reviewRange = dateRange(records, "LastReviewedUtc");
|
|
576
|
+
const domains = uniqueScriptDomains(records);
|
|
577
|
+
const inlineCount = records.filter(function (r) { return isInlineScriptSource(r.Source); }).length;
|
|
578
|
+
const iframeScopedCount = records.filter(isIframeScopedScriptInventoryRecord).length;
|
|
579
|
+
|
|
580
|
+
return {
|
|
581
|
+
source: path.basename(inventoryPath),
|
|
582
|
+
sourceFormat: sourceFormat,
|
|
583
|
+
sourceSha256: crypto.createHash("sha256").update(bytes).digest("hex"),
|
|
584
|
+
columns: columns,
|
|
585
|
+
count: records.length,
|
|
586
|
+
authorizedCount: authorizedCount,
|
|
587
|
+
unauthorizedCount: unauthorizedCount,
|
|
588
|
+
unknownAuthorizationCount: unknownAuthorizationCount,
|
|
589
|
+
withJustificationCount: withJustificationCount,
|
|
590
|
+
missingJustificationCount: Math.max(0, records.length - withJustificationCount),
|
|
591
|
+
withOwnerCount: withOwnerCount,
|
|
592
|
+
withIntegrityReferenceCount: withIntegrityReferenceCount,
|
|
593
|
+
withRiskRatingCount: withRiskRatingCount,
|
|
594
|
+
withDataAccessCount: withDataAccessCount,
|
|
595
|
+
withApprovalTicketCount: withApprovalTicketCount,
|
|
596
|
+
withCheckoutSurfaceCount: withCheckoutSurfaceCount,
|
|
597
|
+
withFrameContextCount: withFrameContextCount,
|
|
598
|
+
iframeScopedCount: iframeScopedCount,
|
|
599
|
+
inlineCount: inlineCount,
|
|
600
|
+
externalCount: Math.max(0, records.length - inlineCount),
|
|
601
|
+
categoryCounts: countByField(records, "Category"),
|
|
602
|
+
ownerCounts: countByField(records, "Owner"),
|
|
603
|
+
riskCounts: countByField(records, "Risk"),
|
|
604
|
+
dataAccessCounts: countByField(records, "DataAccess"),
|
|
605
|
+
checkoutSurfaceCounts: countByField(records, "CheckoutSurface"),
|
|
606
|
+
frameContextCounts: countByField(records, "FrameContext"),
|
|
607
|
+
frameOwnerCounts: countByField(records, "FrameOwner"),
|
|
608
|
+
uniqueDomainCount: domains.length,
|
|
609
|
+
domains: domains.slice(0, 20),
|
|
610
|
+
oldestReviewedUtc: reviewRange.oldest,
|
|
611
|
+
newestReviewedUtc: reviewRange.newest,
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
function collectScriptInventoryAuditEvidence(auditPath) {
|
|
616
|
+
if (!fs.existsSync(auditPath)) {
|
|
617
|
+
throw new Error("generateReport: script inventory audit export not found: " + auditPath);
|
|
618
|
+
}
|
|
619
|
+
const bytes = fs.readFileSync(auditPath);
|
|
620
|
+
const text = stripUtf8Bom(bytes.toString("utf8"));
|
|
621
|
+
let payload;
|
|
622
|
+
try {
|
|
623
|
+
payload = JSON.parse(text);
|
|
624
|
+
} catch (x) {
|
|
625
|
+
throw new Error("generateReport: script inventory audit JSON is not valid JSON: " + x.message);
|
|
626
|
+
}
|
|
627
|
+
if (!payload || typeof payload !== "object" || payload.format !== "jso-payment-script-inventory-audit") {
|
|
628
|
+
throw new Error("generateReport: script inventory audit JSON must be generated by --script-inventory-audit --json");
|
|
629
|
+
}
|
|
630
|
+
const summary = payload.summary && typeof payload.summary === "object" ? payload.summary : {};
|
|
631
|
+
const runtimeSnapshot = payload.runtimeSnapshot && typeof payload.runtimeSnapshot === "object" ? payload.runtimeSnapshot : {};
|
|
632
|
+
const approvedInventory = payload.approvedInventory && typeof payload.approvedInventory === "object" ? payload.approvedInventory : {};
|
|
633
|
+
return {
|
|
634
|
+
source: path.basename(auditPath),
|
|
635
|
+
sourceFormat: "json",
|
|
636
|
+
sourceSha256: crypto.createHash("sha256").update(bytes).digest("hex"),
|
|
637
|
+
ok: payload.ok === true,
|
|
638
|
+
generatedAt: normalizeCsvCell(payload.generatedAt),
|
|
639
|
+
approvedInventorySource: normalizeCsvCell(approvedInventory.source),
|
|
640
|
+
runtimeSnapshotSource: normalizeCsvCell(runtimeSnapshot.source),
|
|
641
|
+
runtimeSnapshotCount: numericSummaryValue(runtimeSnapshot.snapshotCount),
|
|
642
|
+
approvedScripts: numericSummaryValue(summary.approvedScripts),
|
|
643
|
+
observedScripts: numericSummaryValue(summary.observedScripts),
|
|
644
|
+
unknownObserved: numericSummaryValue(summary.unknownObserved),
|
|
645
|
+
unauthorizedObserved: numericSummaryValue(summary.unauthorizedObserved),
|
|
646
|
+
integrityMismatches: numericSummaryValue(summary.integrityMismatches),
|
|
647
|
+
missingApproved: numericSummaryValue(summary.missingApproved),
|
|
648
|
+
injectedAfterLoad: numericSummaryValue(summary.injectedAfterLoad),
|
|
649
|
+
runtimeViolations: numericSummaryValue(summary.runtimeViolations),
|
|
650
|
+
observedWithoutIntegrityReference: numericSummaryValue(summary.observedWithoutIntegrityReference),
|
|
651
|
+
inventoryGaps: numericSummaryValue(summary.inventoryGaps),
|
|
652
|
+
duplicateApproved: numericSummaryValue(summary.duplicateApproved),
|
|
653
|
+
authorizedApprovedScripts: numericSummaryValue(summary.authorizedApprovedScripts),
|
|
654
|
+
withRiskRating: numericSummaryValue(summary.withRiskRating),
|
|
655
|
+
withDataAccess: numericSummaryValue(summary.withDataAccess),
|
|
656
|
+
withApprovalTicket: numericSummaryValue(summary.withApprovalTicket),
|
|
657
|
+
missingRiskRating: numericSummaryValue(summary.missingRiskRating),
|
|
658
|
+
missingDataAccess: numericSummaryValue(summary.missingDataAccess),
|
|
659
|
+
missingApprovalTicket: numericSummaryValue(summary.missingApprovalTicket),
|
|
660
|
+
reviewMetadataGaps: numericSummaryValue(summary.reviewMetadataGaps),
|
|
661
|
+
approvedCheckoutSurfaces: countSummaryObject(summary.approvedCheckoutSurfaces),
|
|
662
|
+
observedCheckoutSurfaces: countSummaryObject(summary.observedCheckoutSurfaces),
|
|
663
|
+
approvedFrameContexts: countSummaryObject(summary.approvedFrameContexts),
|
|
664
|
+
observedFrameContexts: countSummaryObject(summary.observedFrameContexts),
|
|
665
|
+
approvedFrameOwners: countSummaryObject(summary.approvedFrameOwners),
|
|
666
|
+
observedFrameOwners: countSummaryObject(summary.observedFrameOwners),
|
|
667
|
+
approvedIframeScopedScripts: numericSummaryValue(summary.approvedIframeScopedScripts),
|
|
668
|
+
observedIframeScopedScripts: numericSummaryValue(summary.observedIframeScopedScripts),
|
|
669
|
+
blockingIssues: numericSummaryValue(summary.blockingIssues),
|
|
670
|
+
};
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
function countSummaryObject(value) {
|
|
674
|
+
const out = {};
|
|
675
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return out;
|
|
676
|
+
Object.keys(value).sort().forEach(function (key) {
|
|
677
|
+
const text = normalizeCsvCell(key);
|
|
678
|
+
const n = Number(value[key]);
|
|
679
|
+
if (text && Number.isFinite(n) && n > 0) out[text] = Math.floor(n);
|
|
680
|
+
});
|
|
681
|
+
return out;
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
function numericSummaryValue(value) {
|
|
685
|
+
const n = Number(value);
|
|
686
|
+
return Number.isFinite(n) && n > 0 ? Math.floor(n) : 0;
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
function collectSecurityHeaderEvidence(headerPath) {
|
|
690
|
+
if (!fs.existsSync(headerPath)) {
|
|
691
|
+
throw new Error("generateReport: payment-page security-header snapshot not found: " + headerPath);
|
|
692
|
+
}
|
|
693
|
+
const bytes = fs.readFileSync(headerPath);
|
|
694
|
+
const text = stripUtf8Bom(bytes.toString("utf8"));
|
|
695
|
+
const trimmed = text.trimStart();
|
|
696
|
+
if (/\.json$/i.test(headerPath) || trimmed[0] === "{") {
|
|
697
|
+
return collectSecurityHeaderJsonEvidence(headerPath, bytes, text);
|
|
698
|
+
}
|
|
699
|
+
return collectSecurityHeaderCsvEvidence(headerPath, bytes, text);
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
function collectSecurityHeaderCsvEvidence(csvPath, bytes, text) {
|
|
703
|
+
const parsed = parseCsv(text);
|
|
704
|
+
const records = parsed.records.map(normalizeSecurityHeaderRecord);
|
|
705
|
+
return summarizeSecurityHeaderRecords(csvPath, bytes, "csv", parsed.headers, records, null, null);
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
function collectSecurityHeaderJsonEvidence(jsonPath, bytes, text) {
|
|
709
|
+
let payload;
|
|
710
|
+
try {
|
|
711
|
+
payload = JSON.parse(text);
|
|
712
|
+
} catch (x) {
|
|
713
|
+
throw new Error("generateReport: payment-page security-header JSON is not valid JSON: " + x.message);
|
|
714
|
+
}
|
|
715
|
+
const rows = payload && typeof payload === "object"
|
|
716
|
+
? (payload.pages || payload.snapshots || payload.headers || payload.items)
|
|
717
|
+
: null;
|
|
718
|
+
if (!Array.isArray(rows)) {
|
|
719
|
+
throw new Error("generateReport: payment-page security-header JSON is missing pages[]");
|
|
720
|
+
}
|
|
721
|
+
const records = rows.map(normalizeSecurityHeaderRecord);
|
|
722
|
+
const generatedUtc = firstJsonValue(payload, "generatedUtc", "generatedAt", "observedUtc", "ObservedUtc");
|
|
723
|
+
const reviewAssistant = payload && typeof payload === "object" ? payload.reviewAssistant : null;
|
|
724
|
+
return summarizeSecurityHeaderRecords(jsonPath, bytes, "json", [
|
|
725
|
+
"PageUrl", "StatusCode", "ObservedUtc", "CheckoutSurface", "FrameContext",
|
|
726
|
+
"ContentSecurityPolicy", "ContentSecurityPolicyReportOnly",
|
|
727
|
+
"StrictTransportSecurity", "XFrameOptions", "ReferrerPolicy",
|
|
728
|
+
"PermissionsPolicy", "ReportingEndpoints", "Nel", "HeaderSha256",
|
|
729
|
+
"BaselineSha256", "MatchesBaseline", "Monitor", "AlertRoute",
|
|
730
|
+
], records, generatedUtc, reviewAssistant);
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
function normalizeSecurityHeaderRecord(row) {
|
|
734
|
+
row = row && typeof row === "object" ? row : {};
|
|
735
|
+
return {
|
|
736
|
+
PageUrl: firstJsonValue(row, "PageUrl", "PageURL", "pageUrl", "url", "Url", "URL", "href", "Href"),
|
|
737
|
+
StatusCode: firstJsonValue(row, "StatusCode", "statusCode", "Status", "status", "httpStatus", "HttpStatus"),
|
|
738
|
+
ObservedUtc: firstJsonValue(row, "ObservedUtc", "observedUtc", "CapturedUtc", "capturedUtc", "checkedUtc", "CheckedUtc", "timestamp", "Timestamp"),
|
|
739
|
+
CheckoutSurface: firstJsonValue(row, "CheckoutSurface", "checkoutSurface", "PaymentSurface", "paymentSurface", "Surface", "surface"),
|
|
740
|
+
FrameContext: firstJsonValue(row, "FrameContext", "frameContext", "FrameRole", "frameRole", "Frame", "frame"),
|
|
741
|
+
FrameOwner: firstJsonValue(row, "FrameOwner", "frameOwner", "IframeOwner", "iframeOwner"),
|
|
742
|
+
ContentSecurityPolicy: securityHeaderValue(row, "content-security-policy", "ContentSecurityPolicy", "contentSecurityPolicy", "CSP", "csp"),
|
|
743
|
+
ContentSecurityPolicyReportOnly: securityHeaderValue(row, "content-security-policy-report-only", "ContentSecurityPolicyReportOnly", "contentSecurityPolicyReportOnly", "CSPReportOnly", "cspReportOnly"),
|
|
744
|
+
StrictTransportSecurity: securityHeaderValue(row, "strict-transport-security", "StrictTransportSecurity", "strictTransportSecurity", "HSTS", "hsts"),
|
|
745
|
+
XFrameOptions: securityHeaderValue(row, "x-frame-options", "XFrameOptions", "xFrameOptions"),
|
|
746
|
+
ReferrerPolicy: securityHeaderValue(row, "referrer-policy", "ReferrerPolicy", "referrerPolicy"),
|
|
747
|
+
PermissionsPolicy: securityHeaderValue(row, "permissions-policy", "PermissionsPolicy", "permissionsPolicy"),
|
|
748
|
+
CrossOriginOpenerPolicy: securityHeaderValue(row, "cross-origin-opener-policy", "CrossOriginOpenerPolicy", "crossOriginOpenerPolicy"),
|
|
749
|
+
CrossOriginResourcePolicy: securityHeaderValue(row, "cross-origin-resource-policy", "CrossOriginResourcePolicy", "crossOriginResourcePolicy"),
|
|
750
|
+
CrossOriginEmbedderPolicy: securityHeaderValue(row, "cross-origin-embedder-policy", "CrossOriginEmbedderPolicy", "crossOriginEmbedderPolicy"),
|
|
751
|
+
ReportingEndpoints: securityHeaderValue(row, "reporting-endpoints", "ReportingEndpoints", "reportingEndpoints"),
|
|
752
|
+
Nel: securityHeaderValue(row, "nel", "NEL", "nel"),
|
|
753
|
+
HeaderSha256: firstJsonValue(row, "HeaderSha256", "headerSha256", "HeadersSha256", "headersSha256", "SnapshotSha256", "snapshotSha256"),
|
|
754
|
+
BaselineSha256: firstJsonValue(row, "BaselineSha256", "baselineSha256", "ExpectedSha256", "expectedSha256"),
|
|
755
|
+
MatchesBaseline: firstJsonValue(row, "MatchesBaseline", "matchesBaseline", "BaselineMatch", "baselineMatch", "MatchesExpected", "matchesExpected"),
|
|
756
|
+
Monitor: firstJsonValue(row, "Monitor", "monitor", "Watcher", "watcher", "Scanner", "scanner", "Job", "job"),
|
|
757
|
+
AlertRoute: firstJsonValue(row, "AlertRoute", "alertRoute", "Notify", "notify", "NotificationRoute", "notificationRoute", "EscalationRoute", "escalationRoute"),
|
|
758
|
+
};
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
function securityHeaderValue(row) {
|
|
762
|
+
const names = Array.prototype.slice.call(arguments, 2);
|
|
763
|
+
const direct = firstJsonValue.apply(null, [row].concat(names));
|
|
764
|
+
if (direct) return direct;
|
|
765
|
+
const headers = firstJsonObject(row, "headers", "Headers", "responseHeaders", "ResponseHeaders", "securityHeaders", "SecurityHeaders");
|
|
766
|
+
if (!headers) return "";
|
|
767
|
+
const wanted = normalizeHeaderName(arguments[1]);
|
|
768
|
+
for (const key of Object.keys(headers)) {
|
|
769
|
+
if (normalizeHeaderName(key) === wanted && headers[key] != null) {
|
|
770
|
+
return normalizeCsvCell(headers[key]);
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
return "";
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
function firstJsonObject(row) {
|
|
777
|
+
row = row && typeof row === "object" ? row : {};
|
|
778
|
+
for (let i = 1; i < arguments.length; i++) {
|
|
779
|
+
const name = arguments[i];
|
|
780
|
+
if (Object.prototype.hasOwnProperty.call(row, name) &&
|
|
781
|
+
row[name] && typeof row[name] === "object" &&
|
|
782
|
+
!Array.isArray(row[name])) {
|
|
783
|
+
return row[name];
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
return null;
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
function normalizeHeaderName(name) {
|
|
790
|
+
return normalizeCsvCell(name).toLowerCase().replace(/_/g, "-");
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
function summarizeSecurityHeaderRecords(headerPath, bytes, sourceFormat, columns, records, generatedUtc, reviewAssistant) {
|
|
794
|
+
records = Array.isArray(records) ? records : [];
|
|
795
|
+
const observedRange = dateRange(records, "ObservedUtc");
|
|
796
|
+
const pageDomains = uniqueSecurityHeaderPageDomains(records);
|
|
797
|
+
const baselineStates = records.map(function (r) { return baselineMatchState(r.MatchesBaseline); });
|
|
798
|
+
const baselineKnownCount = records.filter(function (r, index) {
|
|
799
|
+
return normalizeCsvCell(r.BaselineSha256) !== "" || baselineStates[index] !== "unknown";
|
|
800
|
+
}).length;
|
|
801
|
+
const baselineMatchCount = baselineStates.filter(function (s) { return s === "match"; }).length;
|
|
802
|
+
const baselineMismatchCount = baselineStates.filter(function (s) { return s === "mismatch"; }).length;
|
|
803
|
+
const baselineMissingCount = baselineStates.filter(function (s) { return s === "missing"; }).length;
|
|
804
|
+
|
|
805
|
+
const summary = {
|
|
806
|
+
source: path.basename(headerPath),
|
|
807
|
+
sourceFormat: sourceFormat,
|
|
808
|
+
sourceSha256: crypto.createHash("sha256").update(bytes).digest("hex"),
|
|
809
|
+
columns: columns,
|
|
810
|
+
generatedUtc: generatedUtc || null,
|
|
811
|
+
count: records.length,
|
|
812
|
+
statusCounts: countByField(records, "StatusCode"),
|
|
813
|
+
checkoutSurfaceCounts: countByField(records, "CheckoutSurface"),
|
|
814
|
+
frameContextCounts: countByField(records, "FrameContext"),
|
|
815
|
+
frameOwnerCounts: countByField(records, "FrameOwner"),
|
|
816
|
+
withCspCount: records.filter(function (r) { return normalizeCsvCell(r.ContentSecurityPolicy) !== ""; }).length,
|
|
817
|
+
withReportOnlyCspCount: records.filter(function (r) { return normalizeCsvCell(r.ContentSecurityPolicyReportOnly) !== ""; }).length,
|
|
818
|
+
withScriptSrcCount: records.filter(function (r) { return cspHasDirective(r.ContentSecurityPolicy, ["script-src", "script-src-elem", "default-src"]); }).length,
|
|
819
|
+
withFrameSrcCount: records.filter(function (r) { return cspHasDirective(r.ContentSecurityPolicy, ["frame-src", "child-src"]); }).length,
|
|
820
|
+
withConnectSrcCount: records.filter(function (r) { return cspHasDirective(r.ContentSecurityPolicy, ["connect-src", "default-src"]); }).length,
|
|
821
|
+
withReportEndpointCount: records.filter(hasSecurityHeaderReportEndpoint).length,
|
|
822
|
+
withHstsCount: records.filter(function (r) { return normalizeCsvCell(r.StrictTransportSecurity) !== ""; }).length,
|
|
823
|
+
withXFrameOptionsCount: records.filter(function (r) { return normalizeCsvCell(r.XFrameOptions) !== ""; }).length,
|
|
824
|
+
withReferrerPolicyCount: records.filter(function (r) { return normalizeCsvCell(r.ReferrerPolicy) !== ""; }).length,
|
|
825
|
+
withPermissionsPolicyCount: records.filter(function (r) { return normalizeCsvCell(r.PermissionsPolicy) !== ""; }).length,
|
|
826
|
+
withMonitorCount: records.filter(function (r) { return normalizeCsvCell(r.Monitor) !== ""; }).length,
|
|
827
|
+
withAlertRouteCount: records.filter(function (r) { return normalizeCsvCell(r.AlertRoute) !== ""; }).length,
|
|
828
|
+
baselineKnownCount: baselineKnownCount,
|
|
829
|
+
baselineMatchCount: baselineMatchCount,
|
|
830
|
+
baselineMismatchCount: baselineMismatchCount,
|
|
831
|
+
baselineMissingCount: baselineMissingCount,
|
|
832
|
+
uniqueDomainCount: pageDomains.length,
|
|
833
|
+
domains: pageDomains.slice(0, 20),
|
|
834
|
+
oldestObservedUtc: observedRange.oldest,
|
|
835
|
+
newestObservedUtc: observedRange.newest,
|
|
836
|
+
};
|
|
837
|
+
summary.reviewAssistant = normalizeSecurityHeaderReviewAssistant(reviewAssistant) || buildSecurityHeaderReviewAssistant(summary);
|
|
838
|
+
return summary;
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
function normalizeSecurityHeaderReviewAssistant(assistant) {
|
|
842
|
+
if (!assistant || typeof assistant !== "object" || Array.isArray(assistant)) return null;
|
|
843
|
+
const safeInputs = normalizeSecurityHeaderReviewList(assistant.safeInputs);
|
|
844
|
+
const doNotInclude = normalizeSecurityHeaderReviewList(assistant.doNotInclude);
|
|
845
|
+
const questions = Array.isArray(assistant.questions)
|
|
846
|
+
? assistant.questions.map(function (item) {
|
|
847
|
+
item = item && typeof item === "object" ? item : {};
|
|
848
|
+
return {
|
|
849
|
+
topic: normalizeCsvCell(item.topic),
|
|
850
|
+
prompt: normalizeCsvCell(item.prompt),
|
|
851
|
+
ownerAction: normalizeCsvCell(item.ownerAction),
|
|
852
|
+
};
|
|
853
|
+
}).filter(function (item) {
|
|
854
|
+
return item.topic !== "" || item.prompt !== "" || item.ownerAction !== "";
|
|
855
|
+
})
|
|
856
|
+
: [];
|
|
857
|
+
return {
|
|
858
|
+
sourceFree: assistant.sourceFree !== false,
|
|
859
|
+
intendedUse: normalizeCsvCell(assistant.intendedUse) || "Use with a BYO AI key or internal reviewer to triage payment-page security-header evidence without sending source code, cookies, raw response headers, or secrets.",
|
|
860
|
+
reviewerPrompt: normalizeCsvCell(assistant.reviewerPrompt) || "Review this JSO payment-page security-header packet using only source-free summary fields and produce checkout-owner actions without claiming this replaces a QSA assessment.",
|
|
861
|
+
safeInputs: safeInputs,
|
|
862
|
+
doNotInclude: doNotInclude,
|
|
863
|
+
questions: questions,
|
|
864
|
+
};
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
function normalizeSecurityHeaderReviewList(values) {
|
|
868
|
+
if (!Array.isArray(values)) return [];
|
|
869
|
+
return values.map(function (value) {
|
|
870
|
+
return normalizeCsvCell(value);
|
|
871
|
+
}).filter(function (value, index, arr) {
|
|
872
|
+
return value !== "" && arr.indexOf(value) === index;
|
|
873
|
+
});
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
function buildSecurityHeaderReviewAssistant(summary) {
|
|
877
|
+
summary = summary || {};
|
|
878
|
+
const count = summary.count || 0;
|
|
879
|
+
const questions = [];
|
|
880
|
+
if ((summary.baselineMismatchCount || 0) > 0 || (summary.baselineMissingCount || 0) > 0) {
|
|
881
|
+
questions.push({
|
|
882
|
+
topic: "Baseline drift",
|
|
883
|
+
prompt: "Identify each checkout page or frame whose security-header snapshot changed or is missing from the approved baseline. Confirm whether the change maps to an approved release, provider update, or required rollback.",
|
|
884
|
+
ownerAction: "Attach the release ticket, provider notice, or remediation owner before reviewer handoff.",
|
|
885
|
+
});
|
|
886
|
+
}
|
|
887
|
+
if (count > 0 && (summary.withCspCount || 0) < count) {
|
|
888
|
+
questions.push({
|
|
889
|
+
topic: "CSP coverage",
|
|
890
|
+
prompt: "List every checkout page or frame without an enforced Content-Security-Policy header and decide whether a report-only phase, provider constraint, or missing deployment step explains the gap.",
|
|
891
|
+
ownerAction: "Name the checkout owner and target date for enforced CSP coverage.",
|
|
892
|
+
});
|
|
893
|
+
}
|
|
894
|
+
if (count > 0 && (summary.withScriptSrcCount || 0) < count) {
|
|
895
|
+
questions.push({
|
|
896
|
+
topic: "Script policy",
|
|
897
|
+
prompt: "Review pages or frames without script-src, script-src-elem, or default-src coverage. Confirm how payment-page script loading is constrained for those surfaces.",
|
|
898
|
+
ownerAction: "Record the approved script-loading policy or add a CSP directive before release approval.",
|
|
899
|
+
});
|
|
900
|
+
}
|
|
901
|
+
if (count > 0 && (summary.withFrameSrcCount || 0) < count) {
|
|
902
|
+
questions.push({
|
|
903
|
+
topic: "Frame policy",
|
|
904
|
+
prompt: "Review pages or frames without frame-src or child-src coverage. Confirm hosted checkout, PSP iframe, wallet frame, and embedded payment-frame boundaries are intentional.",
|
|
905
|
+
ownerAction: "Document the approved frame providers or tighten the frame directive.",
|
|
906
|
+
});
|
|
907
|
+
}
|
|
908
|
+
if (count > 0 && (summary.withReportEndpointCount || 0) < count) {
|
|
909
|
+
questions.push({
|
|
910
|
+
topic: "CSP reporting",
|
|
911
|
+
prompt: "Find checkout pages or frames without report-uri, report-to, Reporting-Endpoints, or NEL coverage. Decide where CSP/header violations should be routed.",
|
|
912
|
+
ownerAction: "Wire the missing reporting endpoint or record why the surface is intentionally monitor-only.",
|
|
913
|
+
});
|
|
914
|
+
}
|
|
915
|
+
if (count > 0 && (summary.withHstsCount || 0) < count) {
|
|
916
|
+
questions.push({
|
|
917
|
+
topic: "HSTS coverage",
|
|
918
|
+
prompt: "Identify checkout hosts without Strict-Transport-Security in the snapshot and confirm whether HTTPS enforcement is handled upstream or missing from the response.",
|
|
919
|
+
ownerAction: "Attach the platform or CDN control evidence, or add HSTS before release approval.",
|
|
920
|
+
});
|
|
921
|
+
}
|
|
922
|
+
if (questions.length === 0) {
|
|
923
|
+
questions.push({
|
|
924
|
+
topic: "Clean review",
|
|
925
|
+
prompt: "Confirm the approved security-header baseline still matches the checkout scope, CSP reporting reaches the right owner, and the snapshot is ready for PCI evidence handoff.",
|
|
926
|
+
ownerAction: "Attach this source-free packet next to the header snapshot and release evidence.",
|
|
927
|
+
});
|
|
928
|
+
}
|
|
929
|
+
return {
|
|
930
|
+
sourceFree: true,
|
|
931
|
+
intendedUse: "Use with a BYO AI key or internal reviewer to triage payment-page security-header evidence without sending source code, cookies, raw response headers, or secrets.",
|
|
932
|
+
reviewerPrompt: "Review this JSO payment-page security-header packet. Use only the source-free summary, domains, baseline states, header-presence counts, frame context, monitor, and alert-route fields. Produce checkout-owner actions for baseline drift, CSP/reporting, HSTS, and frame-policy gaps without claiming this replaces a QSA assessment.",
|
|
933
|
+
safeInputs: [
|
|
934
|
+
"summary counts",
|
|
935
|
+
"page domains",
|
|
936
|
+
"baseline match, mismatch, and missing counts",
|
|
937
|
+
"checkout surface, iframe context, and frame owner metadata",
|
|
938
|
+
"CSP, reporting, HSTS, frame-policy, monitor, and alert-route coverage counts",
|
|
939
|
+
"header snapshot SHA-256 values",
|
|
940
|
+
],
|
|
941
|
+
doNotInclude: [
|
|
942
|
+
"raw response headers",
|
|
943
|
+
"cookies",
|
|
944
|
+
"authorization headers",
|
|
945
|
+
"raw source code",
|
|
946
|
+
"payment-card data",
|
|
947
|
+
"customer personal data",
|
|
948
|
+
"provider API keys",
|
|
949
|
+
"collector tokens",
|
|
950
|
+
"session tokens or secrets",
|
|
951
|
+
],
|
|
952
|
+
questions: questions,
|
|
953
|
+
};
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
function cspHasDirective(value, directives) {
|
|
957
|
+
const csp = normalizeCsvCell(value).toLowerCase();
|
|
958
|
+
if (!csp) return false;
|
|
959
|
+
return directives.some(function (directive) {
|
|
960
|
+
return new RegExp("(^|;)\\s*" + directive.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&") + "\\b").test(csp);
|
|
961
|
+
});
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
function hasSecurityHeaderReportEndpoint(record) {
|
|
965
|
+
if (normalizeCsvCell(record.ReportingEndpoints) !== "" || normalizeCsvCell(record.Nel) !== "") return true;
|
|
966
|
+
const csp = normalizeCsvCell(record.ContentSecurityPolicy).toLowerCase() + ";" +
|
|
967
|
+
normalizeCsvCell(record.ContentSecurityPolicyReportOnly).toLowerCase();
|
|
968
|
+
return /(^|;)\s*(report-uri|report-to)\b/.test(csp);
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
function baselineMatchState(value) {
|
|
972
|
+
const v = normalizeCsvCell(value).toLowerCase();
|
|
973
|
+
if (/^(true|yes|y|1|match|matched|ok|pass|same)$/.test(v)) return "match";
|
|
974
|
+
if (/^(false|no|n|0|mismatch|changed|drift|fail|different)$/.test(v)) return "mismatch";
|
|
975
|
+
if (/^(missing|not-found|not found|new|absent|unmatched)$/.test(v)) return "missing";
|
|
976
|
+
return "unknown";
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
function uniqueSecurityHeaderPageDomains(records) {
|
|
980
|
+
const seen = new Set();
|
|
981
|
+
for (const r of records) {
|
|
982
|
+
const pageUrl = normalizeCsvCell(r.PageUrl);
|
|
983
|
+
if (!pageUrl) continue;
|
|
984
|
+
try {
|
|
985
|
+
const u = new URL(pageUrl, "https://example.invalid/");
|
|
986
|
+
if (u.hostname && u.hostname !== "example.invalid") seen.add(u.hostname.toLowerCase());
|
|
987
|
+
} catch (x) {
|
|
988
|
+
// Non-URL page labels remain valid evidence rows; they do not
|
|
989
|
+
// contribute to the domain summary.
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
return Array.from(seen).sort();
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
function authorizationState(value) {
|
|
996
|
+
const v = normalizeCsvCell(value).toLowerCase();
|
|
997
|
+
if (/^(true|yes|y|1|approved|authorized|allowed|active)$/.test(v)) return "authorized";
|
|
998
|
+
if (/^(false|no|n|0|rejected|blocked|denied|unauthorized|not authorized)$/.test(v)) return "unauthorized";
|
|
999
|
+
return "unknown";
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
function isInlineScriptSource(source) {
|
|
1003
|
+
const s = normalizeCsvCell(source).toLowerCase();
|
|
1004
|
+
return s === "" || s.indexOf("inline") === 0 || s.indexOf("sha256:") === 0;
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
function uniqueScriptDomains(records) {
|
|
1008
|
+
const seen = new Set();
|
|
1009
|
+
for (const r of records) {
|
|
1010
|
+
const source = normalizeCsvCell(r.Source);
|
|
1011
|
+
if (!source || isInlineScriptSource(source)) continue;
|
|
1012
|
+
try {
|
|
1013
|
+
const u = new URL(source, "https://example.invalid/");
|
|
1014
|
+
if (u.hostname && u.hostname !== "example.invalid") seen.add(u.hostname.toLowerCase());
|
|
1015
|
+
} catch (x) {
|
|
1016
|
+
// Non-URL sources are still valid inventory entries; they just do
|
|
1017
|
+
// not contribute to the domain summary.
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
return Array.from(seen).sort();
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
function isIframeScopedScriptInventoryRecord(record) {
|
|
1024
|
+
const context = normalizeCsvCell(record && record.FrameContext).toLowerCase();
|
|
1025
|
+
if (context.indexOf("iframe") >= 0 || context.indexOf("frame") >= 0) return true;
|
|
1026
|
+
return normalizeCsvCell(record && record.FrameHref) !== "";
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1029
|
+
function collectRuntimeIncidentEvidence(exportPath) {
|
|
1030
|
+
if (!fs.existsSync(exportPath)) {
|
|
1031
|
+
throw new Error("generateReport: runtime incident export not found: " + exportPath);
|
|
1032
|
+
}
|
|
1033
|
+
const bytes = fs.readFileSync(exportPath);
|
|
1034
|
+
const text = stripUtf8Bom(bytes.toString("utf8"));
|
|
1035
|
+
const trimmed = text.trimStart();
|
|
1036
|
+
if (/\.json$/i.test(exportPath) || trimmed[0] === "{") {
|
|
1037
|
+
return collectRuntimeIncidentJsonEvidence(exportPath, bytes, text);
|
|
1038
|
+
}
|
|
1039
|
+
return collectRuntimeIncidentCsvEvidence(exportPath, bytes, text);
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
function collectRuntimeIncidentCsvEvidence(csvPath, bytes, text) {
|
|
1043
|
+
const parsed = parseCsv(text);
|
|
1044
|
+
const requiredColumns = ["IncidentID", "Status", "Severity", "BuildID", "ReceivedUtc"];
|
|
1045
|
+
const missingColumns = requiredColumns.filter(function (name) {
|
|
1046
|
+
return parsed.headers.indexOf(name) < 0;
|
|
1047
|
+
});
|
|
1048
|
+
if (missingColumns.length > 0) {
|
|
1049
|
+
throw new Error("generateReport: runtime incident CSV is missing columns: " + missingColumns.join(", "));
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
|
+
const records = parsed.records;
|
|
1053
|
+
return summarizeRuntimeIncidentRecords(csvPath, bytes, "csv", parsed.headers, records, null, null, null, null, null, null, null);
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
function collectRuntimeIncidentJsonEvidence(jsonPath, bytes, text) {
|
|
1057
|
+
let payload;
|
|
1058
|
+
try {
|
|
1059
|
+
payload = JSON.parse(text);
|
|
1060
|
+
} catch (x) {
|
|
1061
|
+
throw new Error("generateReport: runtime incident JSON is not valid JSON: " + x.message);
|
|
1062
|
+
}
|
|
1063
|
+
if (!payload || typeof payload !== "object" || !Array.isArray(payload.incidents)) {
|
|
1064
|
+
throw new Error("generateReport: runtime incident JSON is missing incidents[]");
|
|
1065
|
+
}
|
|
1066
|
+
const records = payload.incidents.map(normalizeRuntimeIncidentJsonRecord);
|
|
1067
|
+
const filters = normalizeRuntimeIncidentExportFilters(payload.filters);
|
|
1068
|
+
const routing = normalizeRuntimeIncidentExportRouting(payload.routing);
|
|
1069
|
+
const responseWindow = normalizeRuntimeIncidentExportResponseWindow(payload.responseWindow);
|
|
1070
|
+
const responseChecklist = normalizeRuntimeIncidentExportResponseChecklist(payload.responseChecklist);
|
|
1071
|
+
const dashboardActions = normalizeRuntimeIncidentDashboardActions(payload.dashboardActions);
|
|
1072
|
+
const correlation = normalizeRuntimeIncidentExportCorrelation(payload.correlation);
|
|
1073
|
+
const generatedUtc = firstJsonValue(payload, "generatedUtc", "generatedAt");
|
|
1074
|
+
return summarizeRuntimeIncidentRecords(jsonPath, bytes, "json", [
|
|
1075
|
+
"IncidentID", "Status", "Severity", "Kind", "Reason", "BuildID",
|
|
1076
|
+
"Fingerprint", "PageUrl", "RemoteIP", "EventUtc", "ReceivedUtc", "UserAgent",
|
|
1077
|
+
], records, filters, routing, responseChecklist, responseWindow, generatedUtc, dashboardActions, correlation);
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
function summarizeRuntimeIncidentRecords(exportPath, bytes, sourceFormat, columns, records, filters, routing, responseChecklist, responseWindow, generatedUtc, dashboardActions, correlation) {
|
|
1081
|
+
const receivedRange = dateRange(records, "ReceivedUtc");
|
|
1082
|
+
const eventRange = dateRange(records, "EventUtc");
|
|
1083
|
+
const buildIds = uniqueValues(records, "BuildID");
|
|
1084
|
+
const unresolved = records.filter(function (r) { return isUnresolvedStatus(r.Status); });
|
|
1085
|
+
const unresolvedHighCritical = unresolved.filter(function (r) { return isHighOrCriticalSeverity(r.Severity); });
|
|
1086
|
+
const activeReceivedRange = dateRange(unresolved, "ReceivedUtc");
|
|
1087
|
+
const highCriticalActiveReceivedRange = dateRange(unresolvedHighCritical, "ReceivedUtc");
|
|
1088
|
+
const summary = {
|
|
1089
|
+
source: path.basename(exportPath),
|
|
1090
|
+
sourceFormat: sourceFormat,
|
|
1091
|
+
sourceSha256: crypto.createHash("sha256").update(bytes).digest("hex"),
|
|
1092
|
+
columns: columns,
|
|
1093
|
+
filters: filters || {},
|
|
1094
|
+
generatedUtc: generatedUtc || null,
|
|
1095
|
+
dashboardActions: Array.isArray(dashboardActions) ? dashboardActions : [],
|
|
1096
|
+
correlation: correlation || buildRuntimeIncidentCorrelation(records),
|
|
1097
|
+
count: records.length,
|
|
1098
|
+
statusCounts: countByField(records, "Status"),
|
|
1099
|
+
severityCounts: countByField(records, "Severity"),
|
|
1100
|
+
routing: routing || {},
|
|
1101
|
+
unresolvedCount: unresolved.length,
|
|
1102
|
+
unresolvedHighCriticalCount: unresolvedHighCritical.length,
|
|
1103
|
+
uniqueBuildIdCount: buildIds.length,
|
|
1104
|
+
buildIds: buildIds.slice(0, 20),
|
|
1105
|
+
oldestReceivedUtc: receivedRange.oldest,
|
|
1106
|
+
newestReceivedUtc: receivedRange.newest,
|
|
1107
|
+
oldestActiveReceivedUtc: activeReceivedRange.oldest,
|
|
1108
|
+
newestActiveReceivedUtc: activeReceivedRange.newest,
|
|
1109
|
+
oldestHighOrCriticalActiveReceivedUtc: highCriticalActiveReceivedRange.oldest,
|
|
1110
|
+
newestHighOrCriticalActiveReceivedUtc: highCriticalActiveReceivedRange.newest,
|
|
1111
|
+
oldestEventUtc: eventRange.oldest,
|
|
1112
|
+
newestEventUtc: eventRange.newest,
|
|
1113
|
+
};
|
|
1114
|
+
summary.actionPlanSummary = buildRuntimeIncidentActionPlanSummary(records);
|
|
1115
|
+
summary.responseWindow = responseWindow || buildRuntimeIncidentResponseWindow(summary);
|
|
1116
|
+
summary.responseChecklist = responseChecklist || buildRuntimeIncidentResponseChecklist(summary);
|
|
1117
|
+
return summary;
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
function buildRuntimeIncidentResponseChecklist(runtimeIncidents) {
|
|
1121
|
+
const routing = runtimeIncidents.routing || {};
|
|
1122
|
+
const destinations = Array.isArray(routing.routeConfirmedIncidentsTo) && routing.routeConfirmedIncidentsTo.length
|
|
1123
|
+
? routing.routeConfirmedIncidentsTo
|
|
1124
|
+
: ["customer-owned SIEM or on-call workflow"];
|
|
1125
|
+
const queue = routing.recommendedQueue || (runtimeIncidents.unresolvedHighCriticalCount > 0
|
|
1126
|
+
? "security response owner"
|
|
1127
|
+
: "checkout owner");
|
|
1128
|
+
const target = routing.responseTargetLabel || (runtimeIncidents.unresolvedHighCriticalCount > 0
|
|
1129
|
+
? "same day"
|
|
1130
|
+
: "next business day");
|
|
1131
|
+
const steps = [];
|
|
1132
|
+
|
|
1133
|
+
if (runtimeIncidents.count === 0) {
|
|
1134
|
+
steps.push({
|
|
1135
|
+
id: "archive-empty-export",
|
|
1136
|
+
owner: "release owner",
|
|
1137
|
+
target: "release evidence window",
|
|
1138
|
+
action: "Attach this empty Dashboard Monitoring export to the release packet and keep monitoring routed to the customer-owned alerting path.",
|
|
1139
|
+
});
|
|
1140
|
+
} else if (runtimeIncidents.unresolvedHighCriticalCount > 0) {
|
|
1141
|
+
steps.push({
|
|
1142
|
+
id: "acknowledge-active-high-critical",
|
|
1143
|
+
owner: queue,
|
|
1144
|
+
target: target,
|
|
1145
|
+
action: routing.statusAction || "Move matching Open high/critical incidents to Reviewing and confirm whether the affected BuildID is currently serving payment traffic.",
|
|
1146
|
+
});
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
if (runtimeIncidents.unresolvedCount > 0) {
|
|
1150
|
+
steps.push({
|
|
1151
|
+
id: "triage-open-reviewing",
|
|
1152
|
+
owner: queue,
|
|
1153
|
+
target: target,
|
|
1154
|
+
action: "Review Open and Reviewing incidents by fingerprint, reason, BuildID, and severity; mark each one Resolved or Ignored only after the checkout owner records the decision.",
|
|
1155
|
+
});
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1158
|
+
if (runtimeIncidents.uniqueBuildIdCount > 0) {
|
|
1159
|
+
steps.push({
|
|
1160
|
+
id: "confirm-export-scope",
|
|
1161
|
+
owner: "release owner",
|
|
1162
|
+
target: "before reviewer handoff",
|
|
1163
|
+
action: "Confirm the BuildID and filter scope before treating this packet as full incident history; filtered exports are evidence for the selected queue, not the entire account.",
|
|
1164
|
+
});
|
|
1165
|
+
}
|
|
1166
|
+
|
|
1167
|
+
steps.push({
|
|
1168
|
+
id: "route-confirmed-incidents",
|
|
1169
|
+
owner: "security response owner",
|
|
1170
|
+
target: target,
|
|
1171
|
+
action: "Route confirmed production incidents to " + destinations.join(", ") + " and keep the Dashboard Monitoring export SHA-256 with the incident ticket.",
|
|
1172
|
+
});
|
|
1173
|
+
steps.push({
|
|
1174
|
+
id: "preserve-source-free-boundary",
|
|
1175
|
+
owner: "review coordinator",
|
|
1176
|
+
target: "before external review",
|
|
1177
|
+
action: "Share this source-free summary, its SHA-256, and the export attachment; do not add source code, payment-card data, customer personal data, tokens, provider keys, or secrets.",
|
|
1178
|
+
});
|
|
1179
|
+
|
|
1180
|
+
return {
|
|
1181
|
+
sourceFree: true,
|
|
1182
|
+
filterScope: formatRuntimeIncidentFilters(runtimeIncidents),
|
|
1183
|
+
routingScope: formatRuntimeIncidentRouting(runtimeIncidents),
|
|
1184
|
+
steps: steps,
|
|
1185
|
+
};
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
function buildRuntimeIncidentResponseWindow(runtimeIncidents) {
|
|
1189
|
+
const routing = runtimeIncidents.routing || {};
|
|
1190
|
+
const targetMinutes = runtimeIncidentResponseTargetMinutes(runtimeIncidents);
|
|
1191
|
+
const targetLabel = routing.responseTargetLabel || (runtimeIncidents.unresolvedHighCriticalCount > 0
|
|
1192
|
+
? "15 minutes"
|
|
1193
|
+
: (runtimeIncidents.unresolvedCount > 0 ? "4 hours" : "No active incident"));
|
|
1194
|
+
let basis = "no active incident";
|
|
1195
|
+
let basisUtc = null;
|
|
1196
|
+
if (runtimeIncidents.unresolvedHighCriticalCount > 0) {
|
|
1197
|
+
basis = "oldest active high/critical receivedUtc";
|
|
1198
|
+
basisUtc = runtimeIncidents.oldestHighOrCriticalActiveReceivedUtc;
|
|
1199
|
+
} else if (runtimeIncidents.unresolvedCount > 0) {
|
|
1200
|
+
basis = "oldest active receivedUtc";
|
|
1201
|
+
basisUtc = runtimeIncidents.oldestActiveReceivedUtc;
|
|
1202
|
+
}
|
|
1203
|
+
const dueUtc = basisUtc && targetMinutes > 0 ? addUtcMinutes(basisUtc, targetMinutes) : null;
|
|
1204
|
+
const generatedUtc = runtimeIncidents.generatedUtc || "";
|
|
1205
|
+
const overdue = dueUtc && generatedUtc && Number.isFinite(Date.parse(generatedUtc))
|
|
1206
|
+
? Date.parse(generatedUtc) > Date.parse(dueUtc)
|
|
1207
|
+
: null;
|
|
1208
|
+
return {
|
|
1209
|
+
sourceFree: true,
|
|
1210
|
+
basis: basis,
|
|
1211
|
+
generatedUtc: generatedUtc,
|
|
1212
|
+
targetMinutes: targetMinutes,
|
|
1213
|
+
targetLabel: targetLabel,
|
|
1214
|
+
recommendedQueue: routing.recommendedQueue || "",
|
|
1215
|
+
statusAction: routing.statusAction || "",
|
|
1216
|
+
oldestActiveReceivedUtc: runtimeIncidents.oldestActiveReceivedUtc || null,
|
|
1217
|
+
oldestHighOrCriticalActiveReceivedUtc: runtimeIncidents.oldestHighOrCriticalActiveReceivedUtc || null,
|
|
1218
|
+
responseDueUtc: dueUtc,
|
|
1219
|
+
overdue: overdue,
|
|
1220
|
+
windowState: dueUtc
|
|
1221
|
+
? (overdue === true ? "overdue" : (overdue === false ? "within-target" : "due-time-recorded"))
|
|
1222
|
+
: "no-active-incident",
|
|
1223
|
+
};
|
|
1224
|
+
}
|
|
1225
|
+
|
|
1226
|
+
function runtimeIncidentResponseTargetMinutes(runtimeIncidents) {
|
|
1227
|
+
const routing = runtimeIncidents.routing || {};
|
|
1228
|
+
if (Number.isFinite(routing.responseTargetMinutes) && routing.responseTargetMinutes >= 0) {
|
|
1229
|
+
return routing.responseTargetMinutes;
|
|
1230
|
+
}
|
|
1231
|
+
if (runtimeIncidents.unresolvedHighCriticalCount > 0) return 15;
|
|
1232
|
+
if (runtimeIncidents.unresolvedCount > 0) return 240;
|
|
1233
|
+
if (runtimeIncidents.count > 0) return 1440;
|
|
1234
|
+
return 0;
|
|
1235
|
+
}
|
|
1236
|
+
|
|
1237
|
+
function buildRuntimeIncidentActionPlanSummary(records) {
|
|
1238
|
+
const plans = [];
|
|
1239
|
+
const nextOwnerCounts = {};
|
|
1240
|
+
const escalationCounts = {};
|
|
1241
|
+
let overdueCount = 0;
|
|
1242
|
+
let acknowledgementRequiredCount = 0;
|
|
1243
|
+
|
|
1244
|
+
function increment(counts, key) {
|
|
1245
|
+
key = normalizeCsvCell(key) || "unknown";
|
|
1246
|
+
counts[key] = (counts[key] || 0) + 1;
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1249
|
+
for (const record of records || []) {
|
|
1250
|
+
const plan = record && (record.ActionPlan || normalizeRuntimeIncidentActionPlan(null, record));
|
|
1251
|
+
if (!plan) continue;
|
|
1252
|
+
const row = {
|
|
1253
|
+
incidentId: normalizeCsvCell(record.IncidentID),
|
|
1254
|
+
escalationLevel: normalizeCsvCell(plan.escalationLevel),
|
|
1255
|
+
nextOwner: normalizeCsvCell(plan.nextOwner),
|
|
1256
|
+
nextAction: normalizeCsvCell(plan.nextAction),
|
|
1257
|
+
evidence: normalizeCsvCell(plan.evidence),
|
|
1258
|
+
responseTargetLabel: normalizeCsvCell(plan.responseTargetLabel),
|
|
1259
|
+
responseDueUtc: normalizeCsvCell(plan.responseDueUtc),
|
|
1260
|
+
windowState: normalizeCsvCell(plan.windowState),
|
|
1261
|
+
statusTransition: normalizeCsvCell(plan.statusTransition),
|
|
1262
|
+
requiresAcknowledgement: plan.requiresAcknowledgement === true,
|
|
1263
|
+
overdue: plan.overdue === true,
|
|
1264
|
+
};
|
|
1265
|
+
plans.push(row);
|
|
1266
|
+
increment(nextOwnerCounts, row.nextOwner);
|
|
1267
|
+
increment(escalationCounts, row.escalationLevel);
|
|
1268
|
+
if (row.overdue) overdueCount += 1;
|
|
1269
|
+
if (row.requiresAcknowledgement) acknowledgementRequiredCount += 1;
|
|
1270
|
+
}
|
|
1271
|
+
|
|
1272
|
+
return {
|
|
1273
|
+
sourceFree: true,
|
|
1274
|
+
incidentsWithActionPlan: plans.length,
|
|
1275
|
+
nextOwnerCounts: nextOwnerCounts,
|
|
1276
|
+
escalationCounts: escalationCounts,
|
|
1277
|
+
overdueCount: overdueCount,
|
|
1278
|
+
acknowledgementRequiredCount: acknowledgementRequiredCount,
|
|
1279
|
+
topActions: plans.slice(0, 10),
|
|
1280
|
+
};
|
|
1281
|
+
}
|
|
1282
|
+
|
|
1283
|
+
function normalizeRuntimeIncidentExportCorrelation(correlation) {
|
|
1284
|
+
if (!correlation || typeof correlation !== "object" || Array.isArray(correlation)) return null;
|
|
1285
|
+
const fingerprintGroups = normalizeRuntimeIncidentCorrelationGroups(
|
|
1286
|
+
Array.isArray(correlation.topFingerprintGroups) ? correlation.topFingerprintGroups :
|
|
1287
|
+
(Array.isArray(correlation.TopFingerprintGroups) ? correlation.TopFingerprintGroups : [])
|
|
1288
|
+
);
|
|
1289
|
+
const reasonGroups = normalizeRuntimeIncidentCorrelationGroups(
|
|
1290
|
+
Array.isArray(correlation.topReasonGroups) ? correlation.topReasonGroups :
|
|
1291
|
+
(Array.isArray(correlation.TopReasonGroups) ? correlation.TopReasonGroups : [])
|
|
1292
|
+
);
|
|
1293
|
+
const repeatedFingerprintGroupCount = parseInt(firstJsonValue(correlation, "repeatedFingerprintGroupCount", "RepeatedFingerprintGroupCount"), 10);
|
|
1294
|
+
const repeatedReasonGroupCount = parseInt(firstJsonValue(correlation, "repeatedReasonGroupCount", "RepeatedReasonGroupCount"), 10);
|
|
1295
|
+
return {
|
|
1296
|
+
sourceFree: firstJsonValue(correlation, "sourceFree", "SourceFree") !== "false",
|
|
1297
|
+
groupBy: ["fingerprint", "reason"],
|
|
1298
|
+
repeatedFingerprintGroupCount: Number.isFinite(repeatedFingerprintGroupCount) ? repeatedFingerprintGroupCount : fingerprintGroups.length,
|
|
1299
|
+
repeatedReasonGroupCount: Number.isFinite(repeatedReasonGroupCount) ? repeatedReasonGroupCount : reasonGroups.length,
|
|
1300
|
+
topFingerprintGroups: fingerprintGroups,
|
|
1301
|
+
topReasonGroups: reasonGroups,
|
|
1302
|
+
safeSharingBoundary: firstJsonValue(correlation, "safeSharingBoundary", "SafeSharingBoundary") || "Correlation groups include source-free counts, statuses, BuildIDs, timestamps, fingerprints, and reasons only."
|
|
1303
|
+
};
|
|
1304
|
+
}
|
|
1305
|
+
|
|
1306
|
+
function normalizeRuntimeIncidentCorrelationGroups(groups) {
|
|
1307
|
+
return groups.map(function (group) {
|
|
1308
|
+
group = group && typeof group === "object" ? group : {};
|
|
1309
|
+
const count = parseInt(firstJsonValue(group, "count", "Count"), 10);
|
|
1310
|
+
const activeCount = parseInt(firstJsonValue(group, "activeCount", "ActiveCount"), 10);
|
|
1311
|
+
const highOrCriticalActiveCount = parseInt(firstJsonValue(group, "highOrCriticalActiveCount", "HighOrCriticalActiveCount"), 10);
|
|
1312
|
+
const buildIds = Array.isArray(group.buildIds) ? group.buildIds :
|
|
1313
|
+
(Array.isArray(group.BuildIds) ? group.BuildIds : []);
|
|
1314
|
+
return {
|
|
1315
|
+
groupBy: firstJsonValue(group, "groupBy", "GroupBy") || "fingerprint",
|
|
1316
|
+
key: firstJsonValue(group, "key", "Key", "fingerprint", "reason"),
|
|
1317
|
+
count: Number.isFinite(count) ? count : 0,
|
|
1318
|
+
activeCount: Number.isFinite(activeCount) ? activeCount : 0,
|
|
1319
|
+
highOrCriticalActiveCount: Number.isFinite(highOrCriticalActiveCount) ? highOrCriticalActiveCount : 0,
|
|
1320
|
+
highestSeverity: firstJsonValue(group, "highestSeverity", "HighestSeverity"),
|
|
1321
|
+
statusCounts: normalizeRuntimeIncidentCorrelationCounts(group.statusCounts || group.StatusCounts),
|
|
1322
|
+
buildIds: buildIds.map(function (item) { return normalizeCsvCell(item); }).filter(Boolean).slice(0, 8),
|
|
1323
|
+
firstReceivedUtc: firstJsonValue(group, "firstReceivedUtc", "FirstReceivedUtc"),
|
|
1324
|
+
lastReceivedUtc: firstJsonValue(group, "lastReceivedUtc", "LastReceivedUtc"),
|
|
1325
|
+
recommendedAction: firstJsonValue(group, "recommendedAction", "RecommendedAction")
|
|
1326
|
+
};
|
|
1327
|
+
}).filter(function (group) {
|
|
1328
|
+
return group.key && group.count > 1;
|
|
1329
|
+
}).slice(0, 10);
|
|
1330
|
+
}
|
|
1331
|
+
|
|
1332
|
+
function normalizeRuntimeIncidentCorrelationCounts(counts) {
|
|
1333
|
+
const out = {};
|
|
1334
|
+
if (!counts || typeof counts !== "object" || Array.isArray(counts)) return out;
|
|
1335
|
+
for (const key of Object.keys(counts)) {
|
|
1336
|
+
const value = parseInt(counts[key], 10);
|
|
1337
|
+
if (Number.isFinite(value) && value > 0) out[normalizeCsvCell(key) || "Unknown"] = value;
|
|
1338
|
+
}
|
|
1339
|
+
return out;
|
|
1340
|
+
}
|
|
1341
|
+
|
|
1342
|
+
function buildRuntimeIncidentCorrelation(records) {
|
|
1343
|
+
const fingerprint = buildRuntimeIncidentCorrelationGroups(records, "Fingerprint", "fingerprint");
|
|
1344
|
+
const reason = buildRuntimeIncidentCorrelationGroups(records, "Reason", "reason");
|
|
1345
|
+
return {
|
|
1346
|
+
sourceFree: true,
|
|
1347
|
+
groupBy: ["fingerprint", "reason"],
|
|
1348
|
+
repeatedFingerprintGroupCount: fingerprint.totalRepeatedGroups,
|
|
1349
|
+
repeatedReasonGroupCount: reason.totalRepeatedGroups,
|
|
1350
|
+
topFingerprintGroups: fingerprint.groups,
|
|
1351
|
+
topReasonGroups: reason.groups,
|
|
1352
|
+
safeSharingBoundary: "Correlation groups include source-free counts, statuses, BuildIDs, timestamps, fingerprints, and reasons only."
|
|
1353
|
+
};
|
|
1354
|
+
}
|
|
1355
|
+
|
|
1356
|
+
function buildRuntimeIncidentCorrelationGroups(records, fieldName, groupBy) {
|
|
1357
|
+
const groups = new Map();
|
|
1358
|
+
for (const record of records || []) {
|
|
1359
|
+
const key = normalizeCsvCell(record && record[fieldName]);
|
|
1360
|
+
if (!key) continue;
|
|
1361
|
+
let group = groups.get(key);
|
|
1362
|
+
if (!group) {
|
|
1363
|
+
group = {
|
|
1364
|
+
groupBy: groupBy,
|
|
1365
|
+
key: key,
|
|
1366
|
+
count: 0,
|
|
1367
|
+
activeCount: 0,
|
|
1368
|
+
highOrCriticalActiveCount: 0,
|
|
1369
|
+
highestSeverityRank: 0,
|
|
1370
|
+
statusCounts: {},
|
|
1371
|
+
buildIds: new Set(),
|
|
1372
|
+
receivedTimes: []
|
|
1373
|
+
};
|
|
1374
|
+
groups.set(key, group);
|
|
1375
|
+
}
|
|
1376
|
+
group.count += 1;
|
|
1377
|
+
if (isUnresolvedStatus(record.Status)) group.activeCount += 1;
|
|
1378
|
+
if (isUnresolvedStatus(record.Status) && isHighOrCriticalSeverity(record.Severity)) group.highOrCriticalActiveCount += 1;
|
|
1379
|
+
group.highestSeverityRank = Math.max(group.highestSeverityRank, runtimeIncidentSeverityRank(record.Severity));
|
|
1380
|
+
const status = normalizeCsvCell(record.Status) || "Unknown";
|
|
1381
|
+
group.statusCounts[status] = (group.statusCounts[status] || 0) + 1;
|
|
1382
|
+
const buildId = normalizeCsvCell(record.BuildID);
|
|
1383
|
+
if (buildId) group.buildIds.add(buildId);
|
|
1384
|
+
const received = Date.parse(normalizeCsvCell(record.ReceivedUtc));
|
|
1385
|
+
if (Number.isFinite(received)) group.receivedTimes.push(received);
|
|
1386
|
+
}
|
|
1387
|
+
|
|
1388
|
+
const repeated = Array.from(groups.values()).filter(function (group) { return group.count > 1; });
|
|
1389
|
+
repeated.sort(function (a, b) {
|
|
1390
|
+
return b.highOrCriticalActiveCount - a.highOrCriticalActiveCount ||
|
|
1391
|
+
b.activeCount - a.activeCount ||
|
|
1392
|
+
b.count - a.count ||
|
|
1393
|
+
Math.max.apply(null, b.receivedTimes.concat([0])) - Math.max.apply(null, a.receivedTimes.concat([0])) ||
|
|
1394
|
+
a.key.localeCompare(b.key);
|
|
1395
|
+
});
|
|
1396
|
+
|
|
1397
|
+
return {
|
|
1398
|
+
totalRepeatedGroups: repeated.length,
|
|
1399
|
+
groups: repeated.slice(0, 5).map(function (group) {
|
|
1400
|
+
const sortedTimes = group.receivedTimes.slice().sort(function (a, b) { return a - b; });
|
|
1401
|
+
return {
|
|
1402
|
+
groupBy: group.groupBy,
|
|
1403
|
+
key: group.key,
|
|
1404
|
+
count: group.count,
|
|
1405
|
+
activeCount: group.activeCount,
|
|
1406
|
+
highOrCriticalActiveCount: group.highOrCriticalActiveCount,
|
|
1407
|
+
highestSeverity: runtimeIncidentSeverityLabel(group.highestSeverityRank),
|
|
1408
|
+
statusCounts: group.statusCounts,
|
|
1409
|
+
buildIds: Array.from(group.buildIds).sort().slice(0, 8),
|
|
1410
|
+
firstReceivedUtc: sortedTimes.length ? new Date(sortedTimes[0]).toISOString() : "",
|
|
1411
|
+
lastReceivedUtc: sortedTimes.length ? new Date(sortedTimes[sortedTimes.length - 1]).toISOString() : "",
|
|
1412
|
+
recommendedAction: runtimeIncidentCorrelationAction(group)
|
|
1413
|
+
};
|
|
1414
|
+
})
|
|
1415
|
+
};
|
|
1416
|
+
}
|
|
1417
|
+
|
|
1418
|
+
function runtimeIncidentSeverityRank(severity) {
|
|
1419
|
+
const value = normalizeCsvCell(severity).toLowerCase();
|
|
1420
|
+
if (value === "critical") return 4;
|
|
1421
|
+
if (value === "high") return 3;
|
|
1422
|
+
if (value === "medium") return 2;
|
|
1423
|
+
if (value === "low") return 1;
|
|
1424
|
+
return 0;
|
|
1425
|
+
}
|
|
1426
|
+
|
|
1427
|
+
function runtimeIncidentSeverityLabel(rank) {
|
|
1428
|
+
if (rank >= 4) return "critical";
|
|
1429
|
+
if (rank === 3) return "high";
|
|
1430
|
+
if (rank === 2) return "medium";
|
|
1431
|
+
if (rank === 1) return "low";
|
|
1432
|
+
return "unknown";
|
|
1433
|
+
}
|
|
1434
|
+
|
|
1435
|
+
function runtimeIncidentCorrelationAction(group) {
|
|
1436
|
+
if (group.highOrCriticalActiveCount > 0) {
|
|
1437
|
+
return "Prioritize this repeated high/critical signal before reviewer handoff, then route confirmed production incidents to the customer-owned alerting path.";
|
|
1438
|
+
}
|
|
1439
|
+
if (group.activeCount > 0) {
|
|
1440
|
+
return "Review this repeated active signal by BuildID, URL, and runtime fingerprint before closing the filtered packet.";
|
|
1441
|
+
}
|
|
1442
|
+
return "Keep this repeated signal with the export as resolved or ignored evidence for the selected filter.";
|
|
1443
|
+
}
|
|
1444
|
+
|
|
1445
|
+
function normalizeRuntimeIncidentExportRouting(routing) {
|
|
1446
|
+
if (!routing || typeof routing !== "object" || Array.isArray(routing)) return {};
|
|
1447
|
+
const out = {};
|
|
1448
|
+
const escalationLevel = firstJsonValue(routing, "escalationLevel", "EscalationLevel", "severityLevel");
|
|
1449
|
+
const recommendedQueue = firstJsonValue(routing, "recommendedQueue", "RecommendedQueue", "queue");
|
|
1450
|
+
const preferredEvidence = firstJsonValue(routing, "preferredEvidence", "PreferredEvidence", "evidence");
|
|
1451
|
+
const recommendedAction = firstJsonValue(routing, "recommendedAction", "RecommendedAction", "action");
|
|
1452
|
+
const responseTargetMinutesRaw = firstJsonValue(routing, "responseTargetMinutes", "ResponseTargetMinutes", "targetMinutes");
|
|
1453
|
+
const responseTargetLabel = firstJsonValue(routing, "responseTargetLabel", "ResponseTargetLabel", "targetLabel");
|
|
1454
|
+
const statusAction = firstJsonValue(routing, "statusAction", "StatusAction", "statusNextStep");
|
|
1455
|
+
const filterContext = firstJsonValue(routing, "filterContext", "FilterContext");
|
|
1456
|
+
const buildId = firstJsonValue(routing, "buildId", "BuildID", "BuildId", "buildID");
|
|
1457
|
+
const responseTargetMinutes = parseInt(responseTargetMinutesRaw, 10);
|
|
1458
|
+
if (escalationLevel) out.escalationLevel = escalationLevel;
|
|
1459
|
+
if (recommendedQueue) out.recommendedQueue = recommendedQueue;
|
|
1460
|
+
if (preferredEvidence) out.preferredEvidence = preferredEvidence;
|
|
1461
|
+
if (recommendedAction) out.recommendedAction = recommendedAction;
|
|
1462
|
+
if (Number.isFinite(responseTargetMinutes) && responseTargetMinutes >= 0) out.responseTargetMinutes = responseTargetMinutes;
|
|
1463
|
+
if (responseTargetLabel) out.responseTargetLabel = responseTargetLabel;
|
|
1464
|
+
if (statusAction) out.statusAction = statusAction;
|
|
1465
|
+
if (filterContext) out.filterContext = filterContext;
|
|
1466
|
+
if (buildId) out.buildId = buildId;
|
|
1467
|
+
if (Array.isArray(routing.routeConfirmedIncidentsTo)) {
|
|
1468
|
+
out.routeConfirmedIncidentsTo = routing.routeConfirmedIncidentsTo
|
|
1469
|
+
.map(function (item) { return normalizeCsvCell(item); })
|
|
1470
|
+
.filter(Boolean)
|
|
1471
|
+
.slice(0, 10);
|
|
1472
|
+
}
|
|
1473
|
+
const alertRoutingPlaybook = normalizeRuntimeIncidentAlertRoutingPlaybook(routing);
|
|
1474
|
+
if (alertRoutingPlaybook.length > 0) out.alertRoutingPlaybook = alertRoutingPlaybook;
|
|
1475
|
+
return out;
|
|
1476
|
+
}
|
|
1477
|
+
|
|
1478
|
+
function normalizeRuntimeIncidentAlertRoutingPlaybook(routing) {
|
|
1479
|
+
const raw = routing && (
|
|
1480
|
+
Array.isArray(routing.alertRoutingPlaybook) ? routing.alertRoutingPlaybook :
|
|
1481
|
+
Array.isArray(routing.AlertRoutingPlaybook) ? routing.AlertRoutingPlaybook :
|
|
1482
|
+
Array.isArray(routing.playbook) ? routing.playbook :
|
|
1483
|
+
Array.isArray(routing.routingPlaybook) ? routing.routingPlaybook :
|
|
1484
|
+
null
|
|
1485
|
+
);
|
|
1486
|
+
if (!raw) return [];
|
|
1487
|
+
return raw.map(function (step) {
|
|
1488
|
+
step = step && typeof step === "object" ? step : {};
|
|
1489
|
+
return {
|
|
1490
|
+
id: firstJsonValue(step, "id", "ID", "stepId"),
|
|
1491
|
+
lane: firstJsonValue(step, "lane", "Lane", "name"),
|
|
1492
|
+
owner: firstJsonValue(step, "owner", "Owner", "queue"),
|
|
1493
|
+
trigger: firstJsonValue(step, "trigger", "Trigger", "condition"),
|
|
1494
|
+
target: firstJsonValue(step, "target", "Target", "responseTarget"),
|
|
1495
|
+
evidence: firstJsonValue(step, "evidence", "Evidence", "artifact", "artefact"),
|
|
1496
|
+
action: firstJsonValue(step, "action", "Action", "description"),
|
|
1497
|
+
boundary: firstJsonValue(step, "boundary", "Boundary", "safeSharingBoundary"),
|
|
1498
|
+
};
|
|
1499
|
+
}).filter(function (step) {
|
|
1500
|
+
return step.id || step.lane || step.action;
|
|
1501
|
+
}).slice(0, 12);
|
|
1502
|
+
}
|
|
1503
|
+
|
|
1504
|
+
function normalizeRuntimeIncidentDashboardActions(actions) {
|
|
1505
|
+
if (!Array.isArray(actions)) return [];
|
|
1506
|
+
return actions.map(function (action) {
|
|
1507
|
+
action = action && typeof action === "object" ? action : {};
|
|
1508
|
+
const enabledRaw = firstJsonValue(action, "enabled", "Enabled", "available");
|
|
1509
|
+
const matchingOpenRaw = firstJsonValue(action, "matchingOpenIncidentCount", "MatchingOpenIncidentCount", "openCount");
|
|
1510
|
+
const matchingReviewingRaw = firstJsonValue(action, "matchingReviewingIncidentCount", "MatchingReviewingIncidentCount", "reviewingCount");
|
|
1511
|
+
const matchingOpenIncidentCount = parseInt(matchingOpenRaw, 10);
|
|
1512
|
+
const matchingReviewingIncidentCount = parseInt(matchingReviewingRaw, 10);
|
|
1513
|
+
const preserves = Array.isArray(action.preserves) ? action.preserves
|
|
1514
|
+
: (Array.isArray(action.Preserves) ? action.Preserves : []);
|
|
1515
|
+
const filters = normalizeRuntimeIncidentExportFilters(
|
|
1516
|
+
action.filters && typeof action.filters === "object" ? action.filters :
|
|
1517
|
+
(action.Filters && typeof action.Filters === "object" ? action.Filters : {})
|
|
1518
|
+
);
|
|
1519
|
+
const row = {
|
|
1520
|
+
id: firstJsonValue(action, "id", "ID", "actionId"),
|
|
1521
|
+
label: firstJsonValue(action, "label", "Label", "name"),
|
|
1522
|
+
dashboardAction: firstJsonValue(action, "dashboardAction", "DashboardAction", "action"),
|
|
1523
|
+
formFieldName: firstJsonValue(action, "formFieldName", "FormFieldName"),
|
|
1524
|
+
formFieldValue: firstJsonValue(action, "formFieldValue", "FormFieldValue"),
|
|
1525
|
+
method: firstJsonValue(action, "method", "Method"),
|
|
1526
|
+
sourceFree: firstJsonValue(action, "sourceFree", "SourceFree") !== "false",
|
|
1527
|
+
requiresDashboardLogin: firstJsonValue(action, "requiresDashboardLogin", "RequiresDashboardLogin") !== "false",
|
|
1528
|
+
statusFrom: firstJsonValue(action, "statusFrom", "StatusFrom", "fromStatus"),
|
|
1529
|
+
statusTo: firstJsonValue(action, "statusTo", "StatusTo", "targetStatus", "toStatus"),
|
|
1530
|
+
scope: firstJsonValue(action, "scope", "Scope"),
|
|
1531
|
+
filterContext: firstJsonValue(action, "filterContext", "FilterContext"),
|
|
1532
|
+
safety: firstJsonValue(action, "safety", "Safety", "safeSharingBoundary"),
|
|
1533
|
+
filters: filters,
|
|
1534
|
+
preserves: preserves.map(function (item) { return normalizeCsvCell(item); }).filter(Boolean).slice(0, 8),
|
|
1535
|
+
};
|
|
1536
|
+
if (/^(true|yes|1)$/i.test(enabledRaw)) row.enabled = true;
|
|
1537
|
+
else if (/^(false|no|0)$/i.test(enabledRaw)) row.enabled = false;
|
|
1538
|
+
if (Number.isFinite(matchingOpenIncidentCount) && matchingOpenIncidentCount >= 0) {
|
|
1539
|
+
row.matchingOpenIncidentCount = matchingOpenIncidentCount;
|
|
1540
|
+
}
|
|
1541
|
+
if (Number.isFinite(matchingReviewingIncidentCount) && matchingReviewingIncidentCount >= 0) {
|
|
1542
|
+
row.matchingReviewingIncidentCount = matchingReviewingIncidentCount;
|
|
1543
|
+
}
|
|
1544
|
+
return row;
|
|
1545
|
+
}).filter(function (action) {
|
|
1546
|
+
return action.id || action.label || action.dashboardAction;
|
|
1547
|
+
}).slice(0, 10);
|
|
1548
|
+
}
|
|
1549
|
+
|
|
1550
|
+
function normalizeRuntimeIncidentExportResponseWindow(window) {
|
|
1551
|
+
if (!window || typeof window !== "object" || Array.isArray(window)) return null;
|
|
1552
|
+
const out = { sourceFree: firstJsonValue(window, "sourceFree", "SourceFree") !== "false" };
|
|
1553
|
+
const targetMinutesRaw = firstJsonValue(window, "targetMinutes", "TargetMinutes", "responseTargetMinutes", "ResponseTargetMinutes");
|
|
1554
|
+
const targetMinutes = parseInt(targetMinutesRaw, 10);
|
|
1555
|
+
if (Number.isFinite(targetMinutes) && targetMinutes >= 0) out.targetMinutes = targetMinutes;
|
|
1556
|
+
const stringFields = [
|
|
1557
|
+
["basis", "basis", "Basis"],
|
|
1558
|
+
["generatedUtc", "generatedUtc", "GeneratedUtc", "generatedAt"],
|
|
1559
|
+
["targetLabel", "targetLabel", "TargetLabel", "responseTargetLabel", "ResponseTargetLabel"],
|
|
1560
|
+
["recommendedQueue", "recommendedQueue", "RecommendedQueue"],
|
|
1561
|
+
["statusAction", "statusAction", "StatusAction"],
|
|
1562
|
+
["oldestActiveReceivedUtc", "oldestActiveReceivedUtc", "OldestActiveReceivedUtc"],
|
|
1563
|
+
["oldestHighOrCriticalActiveReceivedUtc", "oldestHighOrCriticalActiveReceivedUtc", "OldestHighOrCriticalActiveReceivedUtc"],
|
|
1564
|
+
["responseDueUtc", "responseDueUtc", "ResponseDueUtc", "dueUtc", "dueByUtc"],
|
|
1565
|
+
["windowState", "windowState", "WindowState", "state"],
|
|
1566
|
+
];
|
|
1567
|
+
for (const spec of stringFields) {
|
|
1568
|
+
const name = spec[0];
|
|
1569
|
+
const value = firstJsonValue.apply(null, [window].concat(spec.slice(1)));
|
|
1570
|
+
if (value) out[name] = value;
|
|
1571
|
+
}
|
|
1572
|
+
const overdueRaw = firstJsonValue(window, "overdue", "Overdue", "isOverdue");
|
|
1573
|
+
if (/^(true|yes|1)$/i.test(overdueRaw)) out.overdue = true;
|
|
1574
|
+
else if (/^(false|no|0)$/i.test(overdueRaw)) out.overdue = false;
|
|
1575
|
+
return Object.keys(out).length > 1 ? out : null;
|
|
1576
|
+
}
|
|
1577
|
+
|
|
1578
|
+
function normalizeRuntimeIncidentExportResponseChecklist(checklist) {
|
|
1579
|
+
if (!checklist || typeof checklist !== "object" || Array.isArray(checklist)) return null;
|
|
1580
|
+
const rawSteps = Array.isArray(checklist.steps) ? checklist.steps : [];
|
|
1581
|
+
const steps = rawSteps.map(function (step) {
|
|
1582
|
+
step = step && typeof step === "object" ? step : {};
|
|
1583
|
+
return {
|
|
1584
|
+
id: firstJsonValue(step, "id", "ID", "stepId"),
|
|
1585
|
+
owner: firstJsonValue(step, "owner", "Owner", "queue"),
|
|
1586
|
+
target: firstJsonValue(step, "target", "Target", "responseTarget"),
|
|
1587
|
+
action: firstJsonValue(step, "action", "Action", "description"),
|
|
1588
|
+
};
|
|
1589
|
+
}).filter(function (step) {
|
|
1590
|
+
return step.id || step.action;
|
|
1591
|
+
}).slice(0, 12);
|
|
1592
|
+
if (steps.length === 0) return null;
|
|
1593
|
+
return {
|
|
1594
|
+
sourceFree: firstJsonValue(checklist, "sourceFree", "SourceFree") !== "false",
|
|
1595
|
+
filterScope: firstJsonValue(checklist, "filterScope", "FilterScope"),
|
|
1596
|
+
routingScope: firstJsonValue(checklist, "routingScope", "RoutingScope"),
|
|
1597
|
+
steps: steps,
|
|
1598
|
+
};
|
|
1599
|
+
}
|
|
1600
|
+
|
|
1601
|
+
function normalizeRuntimeIncidentExportFilters(filters) {
|
|
1602
|
+
if (!filters || typeof filters !== "object" || Array.isArray(filters)) return {};
|
|
1603
|
+
const out = {};
|
|
1604
|
+
const status = firstJsonValue(filters, "status", "Status", "runtimeStatus", "runtime_status");
|
|
1605
|
+
const severity = firstJsonValue(filters, "severity", "Severity", "runtimeSeverity", "runtime_severity");
|
|
1606
|
+
const buildId = firstJsonValue(filters, "buildId", "BuildID", "BuildId", "buildID", "runtimeBuild", "runtime_build");
|
|
1607
|
+
if (status) out.status = status;
|
|
1608
|
+
if (severity) out.severity = severity;
|
|
1609
|
+
if (buildId) out.buildId = buildId;
|
|
1610
|
+
return out;
|
|
1611
|
+
}
|
|
1612
|
+
|
|
1613
|
+
function normalizeRuntimeIncidentJsonRecord(row) {
|
|
1614
|
+
row = row && typeof row === "object" ? row : {};
|
|
1615
|
+
const record = {
|
|
1616
|
+
IncidentID: firstJsonValue(row, "IncidentID", "incidentId", "id"),
|
|
1617
|
+
Status: firstJsonValue(row, "Status", "status"),
|
|
1618
|
+
Severity: firstJsonValue(row, "Severity", "severity"),
|
|
1619
|
+
Kind: firstJsonValue(row, "Kind", "kind"),
|
|
1620
|
+
Reason: firstJsonValue(row, "Reason", "reason"),
|
|
1621
|
+
BuildID: firstJsonValue(row, "BuildID", "BuildId", "buildID", "buildId"),
|
|
1622
|
+
Fingerprint: firstJsonValue(row, "Fingerprint", "fingerprint"),
|
|
1623
|
+
PageUrl: firstJsonValue(row, "PageUrl", "PageURL", "pageUrl", "url"),
|
|
1624
|
+
RemoteIP: firstJsonValue(row, "RemoteIP", "RemoteIp", "remoteIP", "remoteIp"),
|
|
1625
|
+
EventUtc: firstJsonValue(row, "EventUtc", "eventUtc"),
|
|
1626
|
+
ReceivedUtc: firstJsonValue(row, "ReceivedUtc", "receivedUtc"),
|
|
1627
|
+
UserAgent: firstJsonValue(row, "UserAgent", "userAgent"),
|
|
1628
|
+
};
|
|
1629
|
+
const actionPlan = normalizeRuntimeIncidentActionPlan(row.actionPlan || row.ActionPlan, row);
|
|
1630
|
+
if (actionPlan) record.ActionPlan = actionPlan;
|
|
1631
|
+
return record;
|
|
1632
|
+
}
|
|
1633
|
+
|
|
1634
|
+
function normalizeRuntimeIncidentActionPlan(raw, row) {
|
|
1635
|
+
const source = raw && typeof raw === "object" && !Array.isArray(raw) ? raw : (row || {});
|
|
1636
|
+
const nextOwner = firstJsonValue(source, "nextOwner", "NextOwner", "owner", "Owner");
|
|
1637
|
+
const nextAction = firstJsonValue(source, "nextAction", "NextAction", "action", "Action");
|
|
1638
|
+
const escalationLevel = firstJsonValue(source, "escalationLevel", "EscalationLevel", "level", "Level");
|
|
1639
|
+
const evidence = firstJsonValue(source, "evidence", "Evidence", "preferredEvidence", "PreferredEvidence");
|
|
1640
|
+
const responseTargetLabel = firstJsonValue(source, "responseTargetLabel", "ResponseTargetLabel", "targetLabel", "TargetLabel");
|
|
1641
|
+
const responseDueUtc = firstJsonValue(source, "responseDueUtc", "ResponseDueUtc", "dueUtc", "DueUtc");
|
|
1642
|
+
const windowState = firstJsonValue(source, "windowState", "WindowState", "responseWindowState", "ResponseWindowState", "state", "State");
|
|
1643
|
+
const statusTransition = firstJsonValue(source, "statusTransition", "StatusTransition", "statusMove", "StatusMove");
|
|
1644
|
+
const responseTargetMinutesRaw = firstJsonValue(source, "responseTargetMinutes", "ResponseTargetMinutes", "targetMinutes", "TargetMinutes");
|
|
1645
|
+
const responseTargetMinutes = parseInt(responseTargetMinutesRaw, 10);
|
|
1646
|
+
const overdueRaw = firstJsonValue(source, "overdue", "Overdue", "isOverdue", "IsOverdue");
|
|
1647
|
+
const acknowledgementRaw = firstJsonValue(source, "requiresAcknowledgement", "RequiresAcknowledgement", "acknowledgementRequired", "AcknowledgementRequired");
|
|
1648
|
+
|
|
1649
|
+
if (!nextOwner && !nextAction && !escalationLevel && !responseDueUtc && !statusTransition) return null;
|
|
1650
|
+
|
|
1651
|
+
const out = {
|
|
1652
|
+
sourceFree: firstJsonValue(source, "sourceFree", "SourceFree") !== "false",
|
|
1653
|
+
escalationLevel: escalationLevel,
|
|
1654
|
+
nextOwner: nextOwner,
|
|
1655
|
+
nextAction: nextAction,
|
|
1656
|
+
evidence: evidence,
|
|
1657
|
+
responseTargetLabel: responseTargetLabel,
|
|
1658
|
+
responseDueUtc: responseDueUtc,
|
|
1659
|
+
windowState: windowState,
|
|
1660
|
+
statusTransition: statusTransition,
|
|
1661
|
+
};
|
|
1662
|
+
if (Number.isFinite(responseTargetMinutes) && responseTargetMinutes >= 0) out.responseTargetMinutes = responseTargetMinutes;
|
|
1663
|
+
if (/^(true|yes|1)$/i.test(overdueRaw)) out.overdue = true;
|
|
1664
|
+
else if (/^(false|no|0)$/i.test(overdueRaw)) out.overdue = false;
|
|
1665
|
+
if (/^(true|yes|1)$/i.test(acknowledgementRaw)) out.requiresAcknowledgement = true;
|
|
1666
|
+
else if (/^(false|no|0)$/i.test(acknowledgementRaw)) out.requiresAcknowledgement = false;
|
|
1667
|
+
return out;
|
|
1668
|
+
}
|
|
1669
|
+
|
|
1670
|
+
function firstJsonValue(row) {
|
|
1671
|
+
for (let i = 1; i < arguments.length; i++) {
|
|
1672
|
+
const name = arguments[i];
|
|
1673
|
+
if (Object.prototype.hasOwnProperty.call(row, name) && row[name] != null) {
|
|
1674
|
+
return normalizeCsvCell(row[name]);
|
|
1675
|
+
}
|
|
1676
|
+
}
|
|
1677
|
+
return "";
|
|
1678
|
+
}
|
|
1679
|
+
|
|
1680
|
+
function stripUtf8Bom(text) {
|
|
1681
|
+
return text && text.charCodeAt(0) === 0xFEFF ? text.slice(1) : text;
|
|
1682
|
+
}
|
|
1683
|
+
|
|
1684
|
+
function parseCsv(text) {
|
|
1685
|
+
text = stripUtf8Bom(text);
|
|
1686
|
+
const rows = [];
|
|
1687
|
+
let row = [];
|
|
1688
|
+
let field = "";
|
|
1689
|
+
let inQuotes = false;
|
|
1690
|
+
for (let i = 0; i < text.length; i++) {
|
|
1691
|
+
const ch = text[i];
|
|
1692
|
+
if (inQuotes) {
|
|
1693
|
+
if (ch === "\"") {
|
|
1694
|
+
if (text[i + 1] === "\"") {
|
|
1695
|
+
field += "\"";
|
|
1696
|
+
i++;
|
|
1697
|
+
} else {
|
|
1698
|
+
inQuotes = false;
|
|
1699
|
+
}
|
|
1700
|
+
} else {
|
|
1701
|
+
field += ch;
|
|
1702
|
+
}
|
|
1703
|
+
} else if (ch === "\"") {
|
|
1704
|
+
inQuotes = true;
|
|
1705
|
+
} else if (ch === ",") {
|
|
1706
|
+
row.push(field);
|
|
1707
|
+
field = "";
|
|
1708
|
+
} else if (ch === "\r" || ch === "\n") {
|
|
1709
|
+
row.push(field);
|
|
1710
|
+
rows.push(row);
|
|
1711
|
+
row = [];
|
|
1712
|
+
field = "";
|
|
1713
|
+
if (ch === "\r" && text[i + 1] === "\n") i++;
|
|
1714
|
+
} else {
|
|
1715
|
+
field += ch;
|
|
1716
|
+
}
|
|
1717
|
+
}
|
|
1718
|
+
if (field.length > 0 || row.length > 0) {
|
|
1719
|
+
row.push(field);
|
|
1720
|
+
rows.push(row);
|
|
1721
|
+
}
|
|
1722
|
+
if (rows.length === 0) {
|
|
1723
|
+
throw new Error("generateReport: runtime incident CSV is empty");
|
|
1724
|
+
}
|
|
1725
|
+
const headers = rows[0].map(function (h) { return normalizeCsvCell(h); });
|
|
1726
|
+
const records = rows.slice(1).filter(function (r) {
|
|
1727
|
+
return r.some(function (cell) { return normalizeCsvCell(cell) !== ""; });
|
|
1728
|
+
}).map(function (r) {
|
|
1729
|
+
const obj = {};
|
|
1730
|
+
for (let i = 0; i < headers.length; i++) {
|
|
1731
|
+
obj[headers[i]] = normalizeCsvCell(r[i] || "");
|
|
1732
|
+
}
|
|
1733
|
+
return obj;
|
|
1734
|
+
});
|
|
1735
|
+
return { headers: headers, records: records };
|
|
1736
|
+
}
|
|
1737
|
+
|
|
1738
|
+
function normalizeCsvCell(value) {
|
|
1739
|
+
return value == null ? "" : String(value).trim();
|
|
1740
|
+
}
|
|
1741
|
+
|
|
1742
|
+
function countByField(records, fieldName) {
|
|
1743
|
+
const counts = {};
|
|
1744
|
+
for (const r of records) {
|
|
1745
|
+
const key = normalizeCsvCell(r[fieldName]) || "Unknown";
|
|
1746
|
+
counts[key] = (counts[key] || 0) + 1;
|
|
1747
|
+
}
|
|
1748
|
+
return counts;
|
|
1749
|
+
}
|
|
1750
|
+
|
|
1751
|
+
function uniqueValues(records, fieldName) {
|
|
1752
|
+
const seen = new Set();
|
|
1753
|
+
for (const r of records) {
|
|
1754
|
+
const value = normalizeCsvCell(r[fieldName]);
|
|
1755
|
+
if (value) seen.add(value);
|
|
1756
|
+
}
|
|
1757
|
+
return Array.from(seen).sort();
|
|
1758
|
+
}
|
|
1759
|
+
|
|
1760
|
+
function dateRange(records, fieldName) {
|
|
1761
|
+
const times = [];
|
|
1762
|
+
for (const r of records) {
|
|
1763
|
+
const value = normalizeCsvCell(r[fieldName]);
|
|
1764
|
+
if (!value) continue;
|
|
1765
|
+
const ms = Date.parse(value);
|
|
1766
|
+
if (Number.isFinite(ms)) times.push(ms);
|
|
1767
|
+
}
|
|
1768
|
+
if (times.length === 0) return { oldest: null, newest: null };
|
|
1769
|
+
times.sort(function (a, b) { return a - b; });
|
|
1770
|
+
return {
|
|
1771
|
+
oldest: new Date(times[0]).toISOString(),
|
|
1772
|
+
newest: new Date(times[times.length - 1]).toISOString(),
|
|
1773
|
+
};
|
|
1774
|
+
}
|
|
1775
|
+
|
|
1776
|
+
function addUtcMinutes(value, minutes) {
|
|
1777
|
+
const ms = Date.parse(value);
|
|
1778
|
+
if (!Number.isFinite(ms) || !Number.isFinite(minutes)) return null;
|
|
1779
|
+
return new Date(ms + minutes * 60 * 1000).toISOString();
|
|
1780
|
+
}
|
|
1781
|
+
|
|
1782
|
+
function isUnresolvedStatus(status) {
|
|
1783
|
+
return /^(open|reviewing)$/i.test(normalizeCsvCell(status));
|
|
1784
|
+
}
|
|
1785
|
+
|
|
1786
|
+
function isHighOrCriticalSeverity(severity) {
|
|
1787
|
+
return /^(high|critical)$/i.test(normalizeCsvCell(severity));
|
|
1788
|
+
}
|
|
1789
|
+
|
|
1790
|
+
function hasScriptInventoryRows(evidence) {
|
|
1791
|
+
return !!(evidence && evidence.scriptInventory && evidence.scriptInventory.count > 0);
|
|
1792
|
+
}
|
|
1793
|
+
|
|
1794
|
+
function hasScriptInventoryAudit(evidence) {
|
|
1795
|
+
return !!(evidence && evidence.scriptInventoryAudit);
|
|
1796
|
+
}
|
|
1797
|
+
|
|
1798
|
+
function hasRuntimeIncidentRows(evidence) {
|
|
1799
|
+
return !!(evidence && evidence.runtimeIncidents && evidence.runtimeIncidents.count > 0);
|
|
1800
|
+
}
|
|
1801
|
+
|
|
1802
|
+
function pushScriptInventoryEvidence(evidenceRows, evidence) {
|
|
1803
|
+
const si = evidence && evidence.scriptInventory;
|
|
1804
|
+
if (!si) return;
|
|
1805
|
+
evidenceRows.push({
|
|
1806
|
+
artefact: "Payment-page script inventory " + scriptInventoryFormatLabel(si) + " summary",
|
|
1807
|
+
location: si.source + " (sha256=" + si.sourceSha256.slice(0, 12) + "...)",
|
|
1808
|
+
citation: "jso-protector compliance pci-dss-v4 --script-inventory",
|
|
1809
|
+
});
|
|
1810
|
+
}
|
|
1811
|
+
|
|
1812
|
+
function scriptInventoryFormatLabel(scriptInventory) {
|
|
1813
|
+
return scriptInventory && scriptInventory.sourceFormat === "json" ? "JSON" : "CSV";
|
|
1814
|
+
}
|
|
1815
|
+
|
|
1816
|
+
function scriptInventoryReviewContextDetail(scriptInventory) {
|
|
1817
|
+
if (!scriptInventory || scriptInventory.count <= 0) return "";
|
|
1818
|
+
let detail = " Review context coverage: risk ratings " + scriptInventory.withRiskRatingCount + "/" + scriptInventory.count +
|
|
1819
|
+
", data-access scopes " + scriptInventory.withDataAccessCount + "/" + scriptInventory.count +
|
|
1820
|
+
", approval tickets " + scriptInventory.withApprovalTicketCount + "/" + scriptInventory.count + ".";
|
|
1821
|
+
const surfaces = formatCounts(scriptInventory.checkoutSurfaceCounts);
|
|
1822
|
+
const frames = formatCounts(scriptInventory.frameContextCounts);
|
|
1823
|
+
if (surfaces !== "none" || frames !== "none") {
|
|
1824
|
+
detail += " Checkout surface context: surfaces " + surfaces + "; frame contexts " + frames +
|
|
1825
|
+
"; iframe-scoped scripts " + scriptInventory.iframeScopedCount + ".";
|
|
1826
|
+
}
|
|
1827
|
+
return detail;
|
|
1828
|
+
}
|
|
1829
|
+
|
|
1830
|
+
function scriptInventoryAuditDetail(evidence) {
|
|
1831
|
+
const audit = evidence && evidence.scriptInventoryAudit;
|
|
1832
|
+
if (!audit) return "";
|
|
1833
|
+
const bits = [];
|
|
1834
|
+
bits.push("Script inventory audit " + (audit.ok ? "passed" : "needs review"));
|
|
1835
|
+
bits.push(audit.approvedScripts + " approved");
|
|
1836
|
+
bits.push(audit.observedScripts + " observed");
|
|
1837
|
+
bits.push(audit.blockingIssues + " blocking issue" + (audit.blockingIssues === 1 ? "" : "s"));
|
|
1838
|
+
if (audit.unknownObserved > 0) bits.push(audit.unknownObserved + " unknown observed");
|
|
1839
|
+
if (audit.unauthorizedObserved > 0) bits.push(audit.unauthorizedObserved + " unauthorized observed");
|
|
1840
|
+
if (audit.integrityMismatches > 0) bits.push(audit.integrityMismatches + " integrity mismatch");
|
|
1841
|
+
if (audit.missingApproved > 0) bits.push(audit.missingApproved + " missing approved");
|
|
1842
|
+
if (audit.injectedAfterLoad > 0) bits.push(audit.injectedAfterLoad + " late injected");
|
|
1843
|
+
if (audit.runtimeViolations > 0) bits.push(audit.runtimeViolations + " runtime violation");
|
|
1844
|
+
if (audit.reviewMetadataGaps > 0) bits.push(audit.reviewMetadataGaps + " optional review metadata gap");
|
|
1845
|
+
if (audit.approvedIframeScopedScripts > 0 || audit.observedIframeScopedScripts > 0) {
|
|
1846
|
+
bits.push(audit.approvedIframeScopedScripts + " approved iframe-scoped / " + audit.observedIframeScopedScripts + " observed iframe-scoped");
|
|
1847
|
+
}
|
|
1848
|
+
return " " + bits.join("; ") + ".";
|
|
1849
|
+
}
|
|
1850
|
+
|
|
1851
|
+
function pushScriptInventoryAuditEvidence(evidenceRows, evidence) {
|
|
1852
|
+
const audit = evidence && evidence.scriptInventoryAudit;
|
|
1853
|
+
if (!audit) return;
|
|
1854
|
+
evidenceRows.push({
|
|
1855
|
+
artefact: "Payment-page script inventory audit JSON summary",
|
|
1856
|
+
location: audit.source + " (sha256=" + audit.sourceSha256.slice(0, 12) + "...)",
|
|
1857
|
+
citation: "jso-protector --script-inventory-audit --json",
|
|
1858
|
+
});
|
|
1859
|
+
}
|
|
1860
|
+
|
|
1861
|
+
function runtimeIncidentDetail(evidence) {
|
|
1862
|
+
const ri = evidence && evidence.runtimeIncidents;
|
|
1863
|
+
if (!ri) return "";
|
|
1864
|
+
if (ri.count === 0) {
|
|
1865
|
+
return " Runtime incident export was supplied and contains no incidents.";
|
|
1866
|
+
}
|
|
1867
|
+
const bits = [];
|
|
1868
|
+
bits.push("Runtime incident " + runtimeIncidentFormatLabel(ri) + " export summarizes " + ri.count + " Dashboard Monitoring incident" + (ri.count === 1 ? "" : "s"));
|
|
1869
|
+
const filters = formatRuntimeIncidentFilters(ri);
|
|
1870
|
+
if (filters !== "none") bits.push("filters: " + filters);
|
|
1871
|
+
if (ri.oldestReceivedUtc && ri.newestReceivedUtc) {
|
|
1872
|
+
bits.push("received " + ri.oldestReceivedUtc + " to " + ri.newestReceivedUtc);
|
|
1873
|
+
}
|
|
1874
|
+
const routing = formatRuntimeIncidentRouting(ri);
|
|
1875
|
+
if (routing !== "none") bits.push("routing: " + routing);
|
|
1876
|
+
const responseWindow = formatRuntimeIncidentResponseWindow(ri);
|
|
1877
|
+
if (responseWindow !== "none") bits.push("response window: " + responseWindow);
|
|
1878
|
+
const actionPlan = formatRuntimeIncidentActionPlan(ri);
|
|
1879
|
+
if (actionPlan !== "none") bits.push("action plan: " + actionPlan);
|
|
1880
|
+
const alertPlaybook = formatRuntimeIncidentAlertRoutingPlaybook(ri);
|
|
1881
|
+
if (alertPlaybook !== "none") bits.push("alert routing playbook: " + alertPlaybook);
|
|
1882
|
+
const dashboardActions = formatRuntimeIncidentDashboardActions(ri);
|
|
1883
|
+
if (dashboardActions !== "none") bits.push("dashboard actions: " + dashboardActions);
|
|
1884
|
+
bits.push(ri.unresolvedCount + " open/reviewing");
|
|
1885
|
+
bits.push(ri.unresolvedHighCriticalCount + " open/reviewing high-or-critical");
|
|
1886
|
+
return " " + bits.join("; ") + ".";
|
|
1887
|
+
}
|
|
1888
|
+
|
|
1889
|
+
function pushRuntimeIncidentEvidence(evidenceRows, evidence) {
|
|
1890
|
+
const ri = evidence && evidence.runtimeIncidents;
|
|
1891
|
+
if (!ri) return;
|
|
1892
|
+
evidenceRows.push({
|
|
1893
|
+
artefact: "Dashboard Monitoring runtime incident " + runtimeIncidentFormatLabel(ri) + " summary",
|
|
1894
|
+
location: ri.source + " (sha256=" + ri.sourceSha256.slice(0, 12) + "...)",
|
|
1895
|
+
citation: ri.sourceFormat === "json"
|
|
1896
|
+
? "dashboard/monitoring.aspx?runtime_export=incidents-json"
|
|
1897
|
+
: "dashboard/monitoring.aspx?runtime_export=incidents",
|
|
1898
|
+
});
|
|
1899
|
+
}
|
|
1900
|
+
|
|
1901
|
+
function hasSecurityHeaderEvidence(evidence) {
|
|
1902
|
+
return !!(evidence && evidence.securityHeaders && evidence.securityHeaders.count > 0);
|
|
1903
|
+
}
|
|
1904
|
+
|
|
1905
|
+
function securityHeaderDetail(evidence) {
|
|
1906
|
+
const sh = evidence && evidence.securityHeaders;
|
|
1907
|
+
if (!sh) return "";
|
|
1908
|
+
if (sh.count === 0) {
|
|
1909
|
+
return " Payment-page security-header snapshot was supplied and contains no page rows.";
|
|
1910
|
+
}
|
|
1911
|
+
const bits = [];
|
|
1912
|
+
bits.push("Payment-page security-header " + securityHeaderFormatLabel(sh) + " snapshot covers " + sh.count + " page" + (sh.count === 1 ? "" : "s"));
|
|
1913
|
+
bits.push("CSP " + sh.withCspCount + "/" + sh.count);
|
|
1914
|
+
bits.push("script-src " + sh.withScriptSrcCount + "/" + sh.count);
|
|
1915
|
+
bits.push("frame-src " + sh.withFrameSrcCount + "/" + sh.count);
|
|
1916
|
+
if (sh.withReportEndpointCount > 0) bits.push("report endpoint " + sh.withReportEndpointCount + "/" + sh.count);
|
|
1917
|
+
if (sh.withMonitorCount > 0) bits.push("monitor " + sh.withMonitorCount + "/" + sh.count);
|
|
1918
|
+
if (sh.withAlertRouteCount > 0) bits.push("alert route " + sh.withAlertRouteCount + "/" + sh.count);
|
|
1919
|
+
if (sh.baselineMismatchCount > 0) bits.push(sh.baselineMismatchCount + " baseline mismatch");
|
|
1920
|
+
if (sh.baselineMissingCount > 0) bits.push(sh.baselineMissingCount + " baseline missing");
|
|
1921
|
+
if (sh.baselineMismatchCount === 0 && sh.baselineMissingCount === 0 && sh.baselineMatchCount > 0) bits.push(sh.baselineMatchCount + " baseline match");
|
|
1922
|
+
if (sh.reviewAssistant && sh.reviewAssistant.sourceFree) bits.push("source-free review assistant packet");
|
|
1923
|
+
const surfaces = formatCounts(sh.checkoutSurfaceCounts);
|
|
1924
|
+
const frames = formatCounts(sh.frameContextCounts);
|
|
1925
|
+
if (surfaces !== "none" || frames !== "none") {
|
|
1926
|
+
bits.push("surfaces " + surfaces + "; frame contexts " + frames);
|
|
1927
|
+
}
|
|
1928
|
+
if (sh.oldestObservedUtc && sh.newestObservedUtc) {
|
|
1929
|
+
bits.push("observed " + formatRange(sh.oldestObservedUtc, sh.newestObservedUtc));
|
|
1930
|
+
}
|
|
1931
|
+
return " " + bits.join("; ") + ".";
|
|
1932
|
+
}
|
|
1933
|
+
|
|
1934
|
+
function pushSecurityHeaderEvidence(evidenceRows, evidence) {
|
|
1935
|
+
const sh = evidence && evidence.securityHeaders;
|
|
1936
|
+
if (!sh) return;
|
|
1937
|
+
evidenceRows.push({
|
|
1938
|
+
artefact: "Payment-page security-header " + securityHeaderFormatLabel(sh) + " snapshot summary",
|
|
1939
|
+
location: sh.source + " (sha256=" + sh.sourceSha256.slice(0, 12) + "...)",
|
|
1940
|
+
citation: "jso-protector compliance pci-dss-v4 --payment-page-headers",
|
|
1941
|
+
});
|
|
1942
|
+
}
|
|
1943
|
+
|
|
1944
|
+
function runtimeIncidentFormatLabel(runtimeIncidents) {
|
|
1945
|
+
return runtimeIncidents && runtimeIncidents.sourceFormat === "json" ? "JSON" : "CSV";
|
|
1946
|
+
}
|
|
1947
|
+
|
|
1948
|
+
function securityHeaderFormatLabel(securityHeaders) {
|
|
1949
|
+
return securityHeaders && securityHeaders.sourceFormat === "json" ? "JSON" : "CSV";
|
|
1950
|
+
}
|
|
1951
|
+
|
|
1952
|
+
function formatRuntimeIncidentFilters(runtimeIncidents) {
|
|
1953
|
+
const filters = runtimeIncidents && runtimeIncidents.filters;
|
|
1954
|
+
if (!filters || typeof filters !== "object") return "none";
|
|
1955
|
+
const parts = [];
|
|
1956
|
+
if (filters.status) parts.push("status=" + filters.status);
|
|
1957
|
+
if (filters.severity) parts.push("severity=" + filters.severity);
|
|
1958
|
+
if (filters.buildId) parts.push("buildId=" + filters.buildId);
|
|
1959
|
+
return parts.length ? parts.join(", ") : "none";
|
|
1960
|
+
}
|
|
1961
|
+
|
|
1962
|
+
function formatRuntimeIncidentRouting(runtimeIncidents) {
|
|
1963
|
+
const routing = runtimeIncidents && runtimeIncidents.routing;
|
|
1964
|
+
if (!routing || typeof routing !== "object") return "none";
|
|
1965
|
+
const parts = [];
|
|
1966
|
+
if (routing.escalationLevel) parts.push("level=" + routing.escalationLevel);
|
|
1967
|
+
if (routing.recommendedQueue) parts.push("queue=" + routing.recommendedQueue);
|
|
1968
|
+
if (routing.preferredEvidence) parts.push("evidence=" + routing.preferredEvidence);
|
|
1969
|
+
if (routing.responseTargetLabel) parts.push("target=" + routing.responseTargetLabel);
|
|
1970
|
+
return parts.length ? parts.join(", ") : "none";
|
|
1971
|
+
}
|
|
1972
|
+
|
|
1973
|
+
function formatRuntimeIncidentResponseWindow(runtimeIncidents) {
|
|
1974
|
+
const window = runtimeIncidents && runtimeIncidents.responseWindow;
|
|
1975
|
+
if (!window || typeof window !== "object") return "none";
|
|
1976
|
+
const parts = [];
|
|
1977
|
+
if (window.windowState) parts.push("state=" + window.windowState);
|
|
1978
|
+
if (window.targetLabel) parts.push("target=" + window.targetLabel);
|
|
1979
|
+
if (window.responseDueUtc) parts.push("due=" + window.responseDueUtc);
|
|
1980
|
+
if (typeof window.overdue === "boolean") {
|
|
1981
|
+
parts.push("overdue=" + (window.overdue ? "yes" : "no"));
|
|
1982
|
+
} else if (window.responseDueUtc) {
|
|
1983
|
+
parts.push("overdue=not evaluated");
|
|
1984
|
+
}
|
|
1985
|
+
if (window.basis) parts.push("basis=" + window.basis);
|
|
1986
|
+
return parts.length ? parts.join(", ") : "none";
|
|
1987
|
+
}
|
|
1988
|
+
|
|
1989
|
+
function formatRuntimeIncidentActionPlan(runtimeIncidents) {
|
|
1990
|
+
const actionPlan = runtimeIncidents && runtimeIncidents.actionPlanSummary;
|
|
1991
|
+
if (!actionPlan || !actionPlan.incidentsWithActionPlan) return "none";
|
|
1992
|
+
const parts = ["plans=" + actionPlan.incidentsWithActionPlan];
|
|
1993
|
+
if (actionPlan.overdueCount) parts.push("overdue=" + actionPlan.overdueCount);
|
|
1994
|
+
if (actionPlan.acknowledgementRequiredCount) parts.push("acknowledgement-required=" + actionPlan.acknowledgementRequiredCount);
|
|
1995
|
+
const ownerCounts = formatCounts(actionPlan.nextOwnerCounts);
|
|
1996
|
+
if (ownerCounts !== "none") parts.push("owners " + ownerCounts);
|
|
1997
|
+
const escalationCounts = formatCounts(actionPlan.escalationCounts);
|
|
1998
|
+
if (escalationCounts !== "none") parts.push("levels " + escalationCounts);
|
|
1999
|
+
return parts.join("; ");
|
|
2000
|
+
}
|
|
2001
|
+
|
|
2002
|
+
function formatRuntimeIncidentAlertRoutingPlaybook(runtimeIncidents) {
|
|
2003
|
+
const routing = runtimeIncidents && runtimeIncidents.routing;
|
|
2004
|
+
const playbook = routing && routing.alertRoutingPlaybook;
|
|
2005
|
+
if (!Array.isArray(playbook) || playbook.length === 0) return "none";
|
|
2006
|
+
return playbook.map(function (step) {
|
|
2007
|
+
const id = normalizeCsvCell(step && step.id);
|
|
2008
|
+
const lane = normalizeCsvCell(step && step.lane);
|
|
2009
|
+
if (id && lane) return id + " (" + lane + ")";
|
|
2010
|
+
return id || lane;
|
|
2011
|
+
}).filter(Boolean).join(", ") || "none";
|
|
2012
|
+
}
|
|
2013
|
+
|
|
2014
|
+
function formatRuntimeIncidentDashboardActions(runtimeIncidents) {
|
|
2015
|
+
const actions = runtimeIncidents && runtimeIncidents.dashboardActions;
|
|
2016
|
+
if (!Array.isArray(actions) || actions.length === 0) return "none";
|
|
2017
|
+
return actions.map(function (action) {
|
|
2018
|
+
const id = normalizeCsvCell(action && action.id);
|
|
2019
|
+
const label = normalizeCsvCell(action && action.label);
|
|
2020
|
+
const enabled = action && action.enabled === true ? "enabled" : (action && action.enabled === false ? "not enabled" : "unknown");
|
|
2021
|
+
const openCount = Number.isFinite(action && action.matchingOpenIncidentCount) ? ", open=" + action.matchingOpenIncidentCount : "";
|
|
2022
|
+
const reviewingCount = Number.isFinite(action && action.matchingReviewingIncidentCount) ? ", reviewing=" + action.matchingReviewingIncidentCount : "";
|
|
2023
|
+
const name = id && label ? id + " (" + label + ")" : (id || label);
|
|
2024
|
+
return name ? name + " " + enabled + openCount + reviewingCount : "";
|
|
2025
|
+
}).filter(Boolean).join(", ") || "none";
|
|
2026
|
+
}
|
|
2027
|
+
|
|
2028
|
+
function formatRuntimeIncidentCorrelation(runtimeIncidents) {
|
|
2029
|
+
const correlation = runtimeIncidents && runtimeIncidents.correlation;
|
|
2030
|
+
if (!correlation || typeof correlation !== "object") return "none";
|
|
2031
|
+
const fingerprintCount = correlation.repeatedFingerprintGroupCount || 0;
|
|
2032
|
+
const reasonCount = correlation.repeatedReasonGroupCount || 0;
|
|
2033
|
+
const groups = [].concat(
|
|
2034
|
+
Array.isArray(correlation.topFingerprintGroups) ? correlation.topFingerprintGroups : [],
|
|
2035
|
+
Array.isArray(correlation.topReasonGroups) ? correlation.topReasonGroups : []
|
|
2036
|
+
);
|
|
2037
|
+
const top = groups.slice(0, 3).map(function (group) {
|
|
2038
|
+
const key = normalizeCsvCell(group.key);
|
|
2039
|
+
const label = normalizeCsvCell(group.groupBy) || "signal";
|
|
2040
|
+
return key ? label + "=" + key + " (" + group.count + "x)" : "";
|
|
2041
|
+
}).filter(Boolean);
|
|
2042
|
+
const prefix = "fingerprints=" + fingerprintCount + ", reasons=" + reasonCount;
|
|
2043
|
+
return top.length ? prefix + "; top " + top.join(", ") : prefix;
|
|
2044
|
+
}
|
|
2045
|
+
|
|
2046
|
+
function buildSummary(controls, evidence) {
|
|
2047
|
+
const total = controls.reduce(function (acc, c) { return acc + c.subRequirements.length; }, 0);
|
|
2048
|
+
let pass = 0, partial = 0, fail = 0, notInspected = 0;
|
|
2049
|
+
for (const c of controls) {
|
|
2050
|
+
for (const s of c.subRequirements) {
|
|
2051
|
+
if (s.status === "pass") pass++;
|
|
2052
|
+
else if (s.status === "partial") partial++;
|
|
2053
|
+
else if (s.status === "not_inspected") notInspected++;
|
|
2054
|
+
else fail++;
|
|
2055
|
+
}
|
|
2056
|
+
}
|
|
2057
|
+
const exitCode =
|
|
2058
|
+
evidence.signatureStatus.kind === "none" ? 2 :
|
|
2059
|
+
fail > 0 ? 1 :
|
|
2060
|
+
(partial > 0 || notInspected > 0) ? 1 :
|
|
2061
|
+
0;
|
|
2062
|
+
return {
|
|
2063
|
+
controls: controls.length,
|
|
2064
|
+
subRequirements: total,
|
|
2065
|
+
pass: pass,
|
|
2066
|
+
partial: partial,
|
|
2067
|
+
fail: fail,
|
|
2068
|
+
not_inspected: notInspected,
|
|
2069
|
+
signatureKind: evidence.signatureStatus.kind,
|
|
2070
|
+
signatureVerified: !!evidence.signatureStatus.verified,
|
|
2071
|
+
exitCode: exitCode,
|
|
2072
|
+
};
|
|
2073
|
+
}
|
|
2074
|
+
|
|
2075
|
+
function buildPciDssReviewAssistant(summary, controls, evidence) {
|
|
2076
|
+
summary = summary || {};
|
|
2077
|
+
controls = Array.isArray(controls) ? controls : [];
|
|
2078
|
+
evidence = evidence || {};
|
|
2079
|
+
const questions = [];
|
|
2080
|
+
const scriptInventory = evidence.scriptInventory;
|
|
2081
|
+
const scriptInventoryAudit = evidence.scriptInventoryAudit;
|
|
2082
|
+
const securityHeaders = evidence.securityHeaders;
|
|
2083
|
+
const runtimeIncidents = evidence.runtimeIncidents;
|
|
2084
|
+
|
|
2085
|
+
if ((summary.fail || 0) > 0 || (summary.partial || 0) > 0 || (summary.not_inspected || 0) > 0) {
|
|
2086
|
+
questions.push({
|
|
2087
|
+
topic: "Evidence gaps",
|
|
2088
|
+
prompt: "Review every failed, partial, or not-inspected PCI evidence row and decide which release owner must resolve it before checkout handoff.",
|
|
2089
|
+
ownerAction: "Attach the corrected evidence artifact or document the accepted customer-owned gap before reviewer delivery.",
|
|
2090
|
+
});
|
|
2091
|
+
}
|
|
2092
|
+
|
|
2093
|
+
if (!summary.signatureVerified) {
|
|
2094
|
+
questions.push({
|
|
2095
|
+
topic: "Signed release proof",
|
|
2096
|
+
prompt: "Confirm the checkout artifact was signed with the release key and verified against the same files that will ship.",
|
|
2097
|
+
ownerAction: "Regenerate the protected release with --sign-release and rerun the PCI report with --root before relying on the packet.",
|
|
2098
|
+
});
|
|
2099
|
+
}
|
|
2100
|
+
|
|
2101
|
+
if (!scriptInventory) {
|
|
2102
|
+
questions.push({
|
|
2103
|
+
topic: "Script authorization",
|
|
2104
|
+
prompt: "Confirm whether the checkout review needs a business-owned script inventory with authorization, justification, owner, risk, data-access, and approval-ticket fields.",
|
|
2105
|
+
ownerAction: "Attach --script-inventory evidence when reviewers need payment-page script authorization beyond the technical manifest.",
|
|
2106
|
+
});
|
|
2107
|
+
} else if ((scriptInventory.unauthorizedCount || 0) > 0 ||
|
|
2108
|
+
(scriptInventory.unknownAuthorizationCount || 0) > 0 ||
|
|
2109
|
+
(scriptInventory.missingJustificationCount || 0) > 0 ||
|
|
2110
|
+
(scriptInventory.withOwnerCount || 0) < (scriptInventory.count || 0)) {
|
|
2111
|
+
questions.push({
|
|
2112
|
+
topic: "Script authorization",
|
|
2113
|
+
prompt: "Review unauthorized, unknown-authorization, missing-justification, or owner-missing script inventory entries.",
|
|
2114
|
+
ownerAction: "Assign checkout owners and approval tickets before sharing the PCI packet.",
|
|
2115
|
+
});
|
|
2116
|
+
}
|
|
2117
|
+
|
|
2118
|
+
if (scriptInventoryAudit && (scriptInventoryAudit.blockingIssues || 0) > 0) {
|
|
2119
|
+
questions.push({
|
|
2120
|
+
topic: "Observed script drift",
|
|
2121
|
+
prompt: "Review unknown, unauthorized, missing, changed, late-injected, or runtime-violation scripts from the approved-vs-observed audit summary.",
|
|
2122
|
+
ownerAction: "Resolve blocking drift or document the approved provider/release change before QSA handoff.",
|
|
2123
|
+
});
|
|
2124
|
+
}
|
|
2125
|
+
|
|
2126
|
+
if (securityHeaders && (
|
|
2127
|
+
(securityHeaders.baselineMismatchCount || 0) > 0 ||
|
|
2128
|
+
(securityHeaders.baselineMissingCount || 0) > 0 ||
|
|
2129
|
+
(securityHeaders.withCspCount || 0) < (securityHeaders.count || 0) ||
|
|
2130
|
+
(securityHeaders.withScriptSrcCount || 0) < (securityHeaders.count || 0) ||
|
|
2131
|
+
(securityHeaders.withFrameSrcCount || 0) < (securityHeaders.count || 0) ||
|
|
2132
|
+
(securityHeaders.withReportEndpointCount || 0) < (securityHeaders.count || 0))) {
|
|
2133
|
+
questions.push({
|
|
2134
|
+
topic: "Header change evidence",
|
|
2135
|
+
prompt: "Review checkout pages or frames with security-header baseline drift, missing baselines, missing CSP coverage, or missing reporting routes.",
|
|
2136
|
+
ownerAction: "Attach the approved header change, provider notice, or remediation owner before reviewer delivery.",
|
|
2137
|
+
});
|
|
2138
|
+
}
|
|
2139
|
+
|
|
2140
|
+
if (!evidence.beaconUrl || !evidence.siemAdapter ||
|
|
2141
|
+
(runtimeIncidents && ((runtimeIncidents.unresolvedCount || 0) > 0 ||
|
|
2142
|
+
(runtimeIncidents.unresolvedHighCriticalCount || 0) > 0))) {
|
|
2143
|
+
questions.push({
|
|
2144
|
+
topic: "Runtime incident routing",
|
|
2145
|
+
prompt: "Confirm browser-side checkout events have a Runtime Defense beacon, customer-owned alert route, response target, and current incident status.",
|
|
2146
|
+
ownerAction: "Wire --beacon-url and --siem or attach the filtered Dashboard Monitoring export with response owner and status action.",
|
|
2147
|
+
});
|
|
2148
|
+
}
|
|
2149
|
+
|
|
2150
|
+
questions.push({
|
|
2151
|
+
topic: "QSA handoff boundary",
|
|
2152
|
+
prompt: "Confirm the packet is used as source-free evidence support, not as a Report on Compliance or a replacement for QSA-led assessment.",
|
|
2153
|
+
ownerAction: "Share only the generated packet and named attachments; keep raw source, protected output, raw incident rows, raw headers, card data, and secrets out of the handoff.",
|
|
2154
|
+
});
|
|
2155
|
+
|
|
2156
|
+
return {
|
|
2157
|
+
sourceFree: true,
|
|
2158
|
+
title: "PCI DSS Review Assistant",
|
|
2159
|
+
intendedUse: "Use with a BYO AI key or internal reviewer to turn PCI DSS v4 checkout evidence into owner actions without sending source code, protected output, raw script rows, raw response headers, runtime incident payloads, payment-card data, provider keys, customer data, or secrets.",
|
|
2160
|
+
reviewerPrompt: "Review this JSO PCI DSS v4 evidence packet. Use only source-free summary counts, control statuses, attachment names and SHA-256 values, build identity, signed-release status, payment-page script inventory summaries, script-drift summaries, security-header summaries, runtime incident summaries, response-window labels, and customer-owned out-of-scope notes. Produce checkout-owner actions without claiming this replaces a QSA-led assessment.",
|
|
2161
|
+
safeInputs: [
|
|
2162
|
+
"control IDs, statuses, and summary counts",
|
|
2163
|
+
"build label, BuildID, polymorphism fingerprint, and signing-key digest",
|
|
2164
|
+
"file names and SHA-256 prefixes already shown in the report",
|
|
2165
|
+
"script inventory summary counts, domains, checkout surfaces, frame context, and source SHA-256",
|
|
2166
|
+
"script inventory audit summary counts and source SHA-256",
|
|
2167
|
+
"security-header summary counts, domains, baseline states, and source SHA-256",
|
|
2168
|
+
"runtime incident summary counts, status/severity counts, BuildIDs, routing labels, response-window labels, and source SHA-256",
|
|
2169
|
+
"customer-owned out-of-scope notes",
|
|
2170
|
+
],
|
|
2171
|
+
doNotInclude: [
|
|
2172
|
+
"raw source code",
|
|
2173
|
+
"protected JavaScript output",
|
|
2174
|
+
"raw script inventory rows",
|
|
2175
|
+
"complete script URLs",
|
|
2176
|
+
"raw page URLs",
|
|
2177
|
+
"raw response headers",
|
|
2178
|
+
"cookies",
|
|
2179
|
+
"runtime incident payloads",
|
|
2180
|
+
"user agents",
|
|
2181
|
+
"IP addresses",
|
|
2182
|
+
"payment-card data",
|
|
2183
|
+
"customer personal data",
|
|
2184
|
+
"provider API keys",
|
|
2185
|
+
"collector tokens",
|
|
2186
|
+
"Web.config contents",
|
|
2187
|
+
"secrets",
|
|
2188
|
+
],
|
|
2189
|
+
questions: questions,
|
|
2190
|
+
};
|
|
2191
|
+
}
|
|
2192
|
+
|
|
2193
|
+
function redactUrl(u) {
|
|
2194
|
+
// Hide query string; keep scheme + host + path so the auditor knows
|
|
2195
|
+
// the destination class without leaking embedded tokens.
|
|
2196
|
+
try {
|
|
2197
|
+
const parsed = new URL(u);
|
|
2198
|
+
return parsed.protocol + "//" + parsed.host + parsed.pathname;
|
|
2199
|
+
} catch (x) { return "(unparseable URL)"; }
|
|
2200
|
+
}
|
|
2201
|
+
|
|
2202
|
+
function renderScriptInventoryMarkdown(out, scriptInventory) {
|
|
2203
|
+
const formatLabel = scriptInventoryFormatLabel(scriptInventory);
|
|
2204
|
+
out.push("## Payment-page script inventory evidence");
|
|
2205
|
+
out.push("");
|
|
2206
|
+
out.push("Payment-page script inventory " + formatLabel + " export is summarized below. Keep the export as the attachment named in the artifact row; the report includes its SHA-256 so reviewers can verify they are looking at the same file.");
|
|
2207
|
+
out.push("");
|
|
2208
|
+
out.push("| Metric | Value |");
|
|
2209
|
+
out.push("|---|---|");
|
|
2210
|
+
out.push("| Export format | " + formatLabel + " |");
|
|
2211
|
+
out.push("| Export artifact | `" + mdCell(scriptInventory.source) + "` |");
|
|
2212
|
+
out.push("| Export sha256 | `" + scriptInventory.sourceSha256 + "` |");
|
|
2213
|
+
out.push("| Scripts | " + scriptInventory.count + " |");
|
|
2214
|
+
out.push("| Authorized | " + scriptInventory.authorizedCount + " |");
|
|
2215
|
+
out.push("| Unauthorized | " + scriptInventory.unauthorizedCount + " |");
|
|
2216
|
+
out.push("| Unknown authorization | " + scriptInventory.unknownAuthorizationCount + " |");
|
|
2217
|
+
out.push("| With justification | " + scriptInventory.withJustificationCount + " |");
|
|
2218
|
+
out.push("| Missing justification | " + scriptInventory.missingJustificationCount + " |");
|
|
2219
|
+
out.push("| With owner | " + scriptInventory.withOwnerCount + " |");
|
|
2220
|
+
out.push("| With integrity reference | " + scriptInventory.withIntegrityReferenceCount + " |");
|
|
2221
|
+
out.push("| With risk rating | " + scriptInventory.withRiskRatingCount + " |");
|
|
2222
|
+
out.push("| With data-access scope | " + scriptInventory.withDataAccessCount + " |");
|
|
2223
|
+
out.push("| With approval ticket | " + scriptInventory.withApprovalTicketCount + " |");
|
|
2224
|
+
out.push("| With checkout surface | " + scriptInventory.withCheckoutSurfaceCount + " |");
|
|
2225
|
+
out.push("| With frame context | " + scriptInventory.withFrameContextCount + " |");
|
|
2226
|
+
out.push("| Iframe-scoped scripts | " + scriptInventory.iframeScopedCount + " |");
|
|
2227
|
+
out.push("| External / inline | " + scriptInventory.externalCount + " / " + scriptInventory.inlineCount + " |");
|
|
2228
|
+
out.push("| Categories | " + mdCell(formatCounts(scriptInventory.categoryCounts)) + " |");
|
|
2229
|
+
out.push("| Owners | " + mdCell(formatCounts(scriptInventory.ownerCounts)) + " |");
|
|
2230
|
+
out.push("| Risk ratings | " + mdCell(formatCounts(scriptInventory.riskCounts)) + " |");
|
|
2231
|
+
out.push("| Data access | " + mdCell(formatCounts(scriptInventory.dataAccessCounts)) + " |");
|
|
2232
|
+
out.push("| Checkout surfaces | " + mdCell(formatCounts(scriptInventory.checkoutSurfaceCounts)) + " |");
|
|
2233
|
+
out.push("| Frame contexts | " + mdCell(formatCounts(scriptInventory.frameContextCounts)) + " |");
|
|
2234
|
+
out.push("| Frame owners | " + mdCell(formatCounts(scriptInventory.frameOwnerCounts)) + " |");
|
|
2235
|
+
out.push("| Domains | " + mdCell(formatScriptDomains(scriptInventory)) + " |");
|
|
2236
|
+
out.push("| Review range | " + mdCell(formatRange(scriptInventory.oldestReviewedUtc, scriptInventory.newestReviewedUtc)) + " |");
|
|
2237
|
+
out.push("");
|
|
2238
|
+
}
|
|
2239
|
+
|
|
2240
|
+
function renderScriptInventoryAuditMarkdown(out, audit) {
|
|
2241
|
+
out.push("## Payment-page script inventory audit evidence");
|
|
2242
|
+
out.push("");
|
|
2243
|
+
out.push("Payment-page script inventory audit JSON is summarized below. Keep the JSON export as the attachment named in the artifact row; the report includes its SHA-256 so reviewers can verify they are looking at the same file.");
|
|
2244
|
+
out.push("");
|
|
2245
|
+
out.push("| Metric | Value |");
|
|
2246
|
+
out.push("|---|---|");
|
|
2247
|
+
out.push("| Export artifact | `" + mdCell(audit.source) + "` |");
|
|
2248
|
+
out.push("| Export sha256 | `" + audit.sourceSha256 + "` |");
|
|
2249
|
+
out.push("| Audit status | " + (audit.ok ? "PASS" : "NEEDS REVIEW") + " |");
|
|
2250
|
+
out.push("| Generated | " + mdCell(audit.generatedAt || "not available") + " |");
|
|
2251
|
+
out.push("| Approved inventory | " + mdCell(audit.approvedInventorySource || "not available") + " |");
|
|
2252
|
+
out.push("| Runtime snapshot | " + mdCell(audit.runtimeSnapshotSource || "not available") + " |");
|
|
2253
|
+
out.push("| Approved / observed scripts | " + audit.approvedScripts + " / " + audit.observedScripts + " |");
|
|
2254
|
+
out.push("| Unknown observed | " + audit.unknownObserved + " |");
|
|
2255
|
+
out.push("| Unauthorized observed | " + audit.unauthorizedObserved + " |");
|
|
2256
|
+
out.push("| Integrity mismatches | " + audit.integrityMismatches + " |");
|
|
2257
|
+
out.push("| Missing approved | " + audit.missingApproved + " |");
|
|
2258
|
+
out.push("| Late injected | " + audit.injectedAfterLoad + " |");
|
|
2259
|
+
out.push("| Runtime violations | " + audit.runtimeViolations + " |");
|
|
2260
|
+
out.push("| Inventory metadata gaps | " + audit.inventoryGaps + " |");
|
|
2261
|
+
out.push("| Review metadata gaps | " + audit.reviewMetadataGaps + " |");
|
|
2262
|
+
out.push("| Checkout surfaces | " + mdCell(formatCounts(audit.approvedCheckoutSurfaces)) + " approved / " + mdCell(formatCounts(audit.observedCheckoutSurfaces)) + " observed |");
|
|
2263
|
+
out.push("| Frame contexts | " + mdCell(formatCounts(audit.approvedFrameContexts)) + " approved / " + mdCell(formatCounts(audit.observedFrameContexts)) + " observed |");
|
|
2264
|
+
out.push("| Iframe-scoped scripts | " + audit.approvedIframeScopedScripts + " approved / " + audit.observedIframeScopedScripts + " observed |");
|
|
2265
|
+
out.push("| Risk ratings | " + audit.withRiskRating + " / " + audit.authorizedApprovedScripts + " |");
|
|
2266
|
+
out.push("| Data-access scopes | " + audit.withDataAccess + " / " + audit.authorizedApprovedScripts + " |");
|
|
2267
|
+
out.push("| Approval tickets | " + audit.withApprovalTicket + " / " + audit.authorizedApprovedScripts + " |");
|
|
2268
|
+
out.push("| Blocking issues | " + audit.blockingIssues + " |");
|
|
2269
|
+
out.push("");
|
|
2270
|
+
}
|
|
2271
|
+
|
|
2272
|
+
function renderSecurityHeaderMarkdown(out, securityHeaders) {
|
|
2273
|
+
const formatLabel = securityHeaderFormatLabel(securityHeaders);
|
|
2274
|
+
out.push("## Payment-page security-header evidence");
|
|
2275
|
+
out.push("");
|
|
2276
|
+
out.push("Payment-page security-header " + formatLabel + " snapshot is summarized below. Keep the snapshot as the attachment named in the artifact row; the report includes its SHA-256 so reviewers can verify they are looking at the same file.");
|
|
2277
|
+
out.push("");
|
|
2278
|
+
out.push("| Metric | Value |");
|
|
2279
|
+
out.push("|---|---|");
|
|
2280
|
+
out.push("| Export format | " + formatLabel + " |");
|
|
2281
|
+
out.push("| Export artifact | `" + mdCell(securityHeaders.source) + "` |");
|
|
2282
|
+
out.push("| Export sha256 | `" + securityHeaders.sourceSha256 + "` |");
|
|
2283
|
+
out.push("| Pages | " + securityHeaders.count + " |");
|
|
2284
|
+
out.push("| Status counts | " + mdCell(formatCounts(securityHeaders.statusCounts)) + " |");
|
|
2285
|
+
out.push("| With CSP | " + securityHeaders.withCspCount + " |");
|
|
2286
|
+
out.push("| CSP report-only | " + securityHeaders.withReportOnlyCspCount + " |");
|
|
2287
|
+
out.push("| With script-src/default-src | " + securityHeaders.withScriptSrcCount + " |");
|
|
2288
|
+
out.push("| With frame-src/child-src | " + securityHeaders.withFrameSrcCount + " |");
|
|
2289
|
+
out.push("| With connect-src/default-src | " + securityHeaders.withConnectSrcCount + " |");
|
|
2290
|
+
out.push("| With report endpoint | " + securityHeaders.withReportEndpointCount + " |");
|
|
2291
|
+
out.push("| With HSTS | " + securityHeaders.withHstsCount + " |");
|
|
2292
|
+
out.push("| With X-Frame-Options | " + securityHeaders.withXFrameOptionsCount + " |");
|
|
2293
|
+
out.push("| With Referrer-Policy | " + securityHeaders.withReferrerPolicyCount + " |");
|
|
2294
|
+
out.push("| With Permissions-Policy | " + securityHeaders.withPermissionsPolicyCount + " |");
|
|
2295
|
+
out.push("| With monitor | " + securityHeaders.withMonitorCount + " |");
|
|
2296
|
+
out.push("| With alert route | " + securityHeaders.withAlertRouteCount + " |");
|
|
2297
|
+
out.push("| Baseline coverage | " + mdCell(formatSecurityHeaderBaseline(securityHeaders)) + " |");
|
|
2298
|
+
out.push("| Checkout surfaces | " + mdCell(formatCounts(securityHeaders.checkoutSurfaceCounts)) + " |");
|
|
2299
|
+
out.push("| Frame contexts | " + mdCell(formatCounts(securityHeaders.frameContextCounts)) + " |");
|
|
2300
|
+
out.push("| Frame owners | " + mdCell(formatCounts(securityHeaders.frameOwnerCounts)) + " |");
|
|
2301
|
+
out.push("| Domains | " + mdCell(formatSecurityHeaderDomains(securityHeaders)) + " |");
|
|
2302
|
+
out.push("| Observed range | " + mdCell(formatRange(securityHeaders.oldestObservedUtc, securityHeaders.newestObservedUtc)) + " |");
|
|
2303
|
+
out.push("| Review assistant packet | " + (securityHeaders.reviewAssistant && securityHeaders.reviewAssistant.sourceFree ? "source-free" : "not included") + " |");
|
|
2304
|
+
out.push("");
|
|
2305
|
+
renderSecurityHeaderReviewAssistantMarkdown(out, securityHeaders.reviewAssistant);
|
|
2306
|
+
}
|
|
2307
|
+
|
|
2308
|
+
function renderSecurityHeaderReviewAssistantMarkdown(out, assistant) {
|
|
2309
|
+
if (!assistant) return;
|
|
2310
|
+
out.push("### Security Header Review Assistant");
|
|
2311
|
+
out.push("");
|
|
2312
|
+
out.push(mdCell(assistant.intendedUse));
|
|
2313
|
+
out.push("");
|
|
2314
|
+
out.push("**Reviewer prompt:** " + mdCell(assistant.reviewerPrompt));
|
|
2315
|
+
out.push("");
|
|
2316
|
+
out.push("Safe inputs:");
|
|
2317
|
+
for (const item of assistant.safeInputs || []) out.push("- " + mdCell(item));
|
|
2318
|
+
out.push("");
|
|
2319
|
+
out.push("Do not include:");
|
|
2320
|
+
for (const item of assistant.doNotInclude || []) out.push("- " + mdCell(item));
|
|
2321
|
+
out.push("");
|
|
2322
|
+
out.push("| Topic | Question | Owner action |");
|
|
2323
|
+
out.push("|---|---|---|");
|
|
2324
|
+
for (const item of assistant.questions || []) {
|
|
2325
|
+
out.push("| " + mdCell(item.topic) + " | " + mdCell(item.prompt) + " | " + mdCell(item.ownerAction) + " |");
|
|
2326
|
+
}
|
|
2327
|
+
out.push("");
|
|
2328
|
+
}
|
|
2329
|
+
|
|
2330
|
+
function renderRuntimeIncidentMarkdown(out, runtimeIncidents) {
|
|
2331
|
+
const formatLabel = runtimeIncidentFormatLabel(runtimeIncidents);
|
|
2332
|
+
out.push("## Runtime incident evidence");
|
|
2333
|
+
out.push("");
|
|
2334
|
+
out.push("Dashboard Monitoring " + formatLabel + " export is summarized below. Keep the export as the attachment named in the artifact row; the report includes its SHA-256 so reviewers can verify they are looking at the same file.");
|
|
2335
|
+
out.push("");
|
|
2336
|
+
out.push("| Metric | Value |");
|
|
2337
|
+
out.push("|---|---|");
|
|
2338
|
+
out.push("| Export format | " + formatLabel + " |");
|
|
2339
|
+
out.push("| Export artifact | `" + mdCell(runtimeIncidents.source) + "` |");
|
|
2340
|
+
out.push("| Export sha256 | `" + runtimeIncidents.sourceSha256 + "` |");
|
|
2341
|
+
out.push("| Filters | " + mdCell(formatRuntimeIncidentFilters(runtimeIncidents)) + " |");
|
|
2342
|
+
out.push("| Routing | " + mdCell(formatRuntimeIncidentRouting(runtimeIncidents)) + " |");
|
|
2343
|
+
out.push("| Repeated-signal correlation | " + mdCell(formatRuntimeIncidentCorrelation(runtimeIncidents)) + " |");
|
|
2344
|
+
out.push("| Alert routing playbook | " + mdCell(formatRuntimeIncidentAlertRoutingPlaybook(runtimeIncidents)) + " |");
|
|
2345
|
+
out.push("| Dashboard actions | " + mdCell(formatRuntimeIncidentDashboardActions(runtimeIncidents)) + " |");
|
|
2346
|
+
out.push("| Response window | " + mdCell(formatRuntimeIncidentResponseWindow(runtimeIncidents)) + " |");
|
|
2347
|
+
out.push("| Incident action plan | " + mdCell(formatRuntimeIncidentActionPlan(runtimeIncidents)) + " |");
|
|
2348
|
+
out.push("| Incidents | " + runtimeIncidents.count + " |");
|
|
2349
|
+
out.push("| Status counts | " + mdCell(formatCounts(runtimeIncidents.statusCounts)) + " |");
|
|
2350
|
+
out.push("| Severity counts | " + mdCell(formatCounts(runtimeIncidents.severityCounts)) + " |");
|
|
2351
|
+
out.push("| Open/reviewing | " + runtimeIncidents.unresolvedCount + " |");
|
|
2352
|
+
out.push("| Open/reviewing high-or-critical | " + runtimeIncidents.unresolvedHighCriticalCount + " |");
|
|
2353
|
+
out.push("| Build IDs | " + mdCell(formatBuildIds(runtimeIncidents)) + " |");
|
|
2354
|
+
out.push("| Received range | " + mdCell(formatRange(runtimeIncidents.oldestReceivedUtc, runtimeIncidents.newestReceivedUtc)) + " |");
|
|
2355
|
+
out.push("| Event range | " + mdCell(formatRange(runtimeIncidents.oldestEventUtc, runtimeIncidents.newestEventUtc)) + " |");
|
|
2356
|
+
out.push("");
|
|
2357
|
+
renderRuntimeIncidentActionPlanMarkdown(out, runtimeIncidents.actionPlanSummary);
|
|
2358
|
+
renderRuntimeIncidentDashboardActionsMarkdown(out, runtimeIncidents.dashboardActions);
|
|
2359
|
+
renderRuntimeIncidentAlertRoutingPlaybookMarkdown(out, runtimeIncidents);
|
|
2360
|
+
renderRuntimeIncidentResponseChecklistMarkdown(out, runtimeIncidents.responseChecklist);
|
|
2361
|
+
}
|
|
2362
|
+
|
|
2363
|
+
function renderRuntimeIncidentActionPlanMarkdown(out, actionPlan) {
|
|
2364
|
+
if (!actionPlan || !Array.isArray(actionPlan.topActions) || actionPlan.topActions.length === 0) return;
|
|
2365
|
+
out.push("### Runtime incident action plan");
|
|
2366
|
+
out.push("");
|
|
2367
|
+
out.push("These source-free row actions name the next owner, response due state, evidence packet, and status move for each exported incident.");
|
|
2368
|
+
out.push("");
|
|
2369
|
+
out.push("| Incident | Level | Next owner | Due | State | Status move | Evidence | Next action |");
|
|
2370
|
+
out.push("|---|---|---|---|---|---|---|---|");
|
|
2371
|
+
for (const row of actionPlan.topActions) {
|
|
2372
|
+
out.push("| " + [
|
|
2373
|
+
row.incidentId || "",
|
|
2374
|
+
row.escalationLevel || "",
|
|
2375
|
+
row.nextOwner || "",
|
|
2376
|
+
row.responseDueUtc || row.responseTargetLabel || "",
|
|
2377
|
+
row.windowState || "",
|
|
2378
|
+
row.statusTransition || "",
|
|
2379
|
+
row.evidence || "",
|
|
2380
|
+
row.nextAction || "",
|
|
2381
|
+
].map(mdCell).join(" | ") + " |");
|
|
2382
|
+
}
|
|
2383
|
+
out.push("");
|
|
2384
|
+
}
|
|
2385
|
+
|
|
2386
|
+
function renderRuntimeIncidentDashboardActionsMarkdown(out, actions) {
|
|
2387
|
+
if (!Array.isArray(actions) || actions.length === 0) return;
|
|
2388
|
+
out.push("### Runtime incident dashboard actions");
|
|
2389
|
+
out.push("");
|
|
2390
|
+
out.push("These actions are source-free dashboard workflow hints. They describe account-scoped status actions available in Dashboard Monitoring and do not replace the customer's long-term incident system.");
|
|
2391
|
+
out.push("");
|
|
2392
|
+
out.push("| Action | Enabled | Scope | Status change | Safety |");
|
|
2393
|
+
out.push("|---|---|---|---|---|");
|
|
2394
|
+
for (const action of actions) {
|
|
2395
|
+
const enabled = action.enabled === true ? "yes" : (action.enabled === false ? "no" : "n/a");
|
|
2396
|
+
const statusChange = (action.statusFrom || "") && (action.statusTo || "")
|
|
2397
|
+
? action.statusFrom + " -> " + action.statusTo
|
|
2398
|
+
: "";
|
|
2399
|
+
out.push("| " + mdCell(action.label || action.id) + " | " + mdCell(enabled) + " | " + mdCell(action.scope || action.filterContext || "") + " | " + mdCell(statusChange) + " | " + mdCell(action.safety || "") + " |");
|
|
2400
|
+
}
|
|
2401
|
+
out.push("");
|
|
2402
|
+
}
|
|
2403
|
+
|
|
2404
|
+
function renderRuntimeIncidentAlertRoutingPlaybookMarkdown(out, runtimeIncidents) {
|
|
2405
|
+
const playbook = runtimeIncidents && runtimeIncidents.routing && runtimeIncidents.routing.alertRoutingPlaybook;
|
|
2406
|
+
if (!Array.isArray(playbook) || playbook.length === 0) return;
|
|
2407
|
+
out.push("### Runtime incident alert routing playbook");
|
|
2408
|
+
out.push("");
|
|
2409
|
+
out.push("This playbook is source-free and customer-owned. It keeps Dashboard Monitoring as first-triage evidence while naming the owner, target, evidence, and boundary for each handoff lane.");
|
|
2410
|
+
out.push("");
|
|
2411
|
+
out.push("| Lane | Owner | Target | Evidence | Action | Boundary |");
|
|
2412
|
+
out.push("|---|---|---|---|---|---|");
|
|
2413
|
+
for (const step of playbook) {
|
|
2414
|
+
out.push("| " + mdCell(step.lane || step.id) + " | " + mdCell(step.owner) + " | " + mdCell(step.target) + " | " + mdCell(step.evidence) + " | " + mdCell(step.action) + " | " + mdCell(step.boundary) + " |");
|
|
2415
|
+
}
|
|
2416
|
+
out.push("");
|
|
2417
|
+
}
|
|
2418
|
+
|
|
2419
|
+
function renderRuntimeIncidentResponseChecklistMarkdown(out, checklist) {
|
|
2420
|
+
if (!checklist || !Array.isArray(checklist.steps) || checklist.steps.length === 0) return;
|
|
2421
|
+
out.push("### Runtime incident response checklist");
|
|
2422
|
+
out.push("");
|
|
2423
|
+
out.push("This checklist is source-free and customer-owned. It turns the export summary into reviewer and on-call actions without replacing a managed security-operations console.");
|
|
2424
|
+
out.push("");
|
|
2425
|
+
out.push("| Step | Owner | Target | Action |");
|
|
2426
|
+
out.push("|---|---|---|---|");
|
|
2427
|
+
for (const step of checklist.steps) {
|
|
2428
|
+
out.push("| " + mdCell(step.id) + " | " + mdCell(step.owner) + " | " + mdCell(step.target) + " | " + mdCell(step.action) + " |");
|
|
2429
|
+
}
|
|
2430
|
+
out.push("");
|
|
2431
|
+
}
|
|
2432
|
+
|
|
2433
|
+
function renderPciDssReviewAssistantMarkdown(out, assistant) {
|
|
2434
|
+
if (!assistant) return;
|
|
2435
|
+
out.push("## PCI DSS Review Assistant");
|
|
2436
|
+
out.push("");
|
|
2437
|
+
out.push(mdCell(assistant.intendedUse));
|
|
2438
|
+
out.push("");
|
|
2439
|
+
out.push("**Reviewer prompt:** " + mdCell(assistant.reviewerPrompt));
|
|
2440
|
+
out.push("");
|
|
2441
|
+
out.push("Safe inputs:");
|
|
2442
|
+
for (const item of assistant.safeInputs || []) out.push("- " + mdCell(item));
|
|
2443
|
+
out.push("");
|
|
2444
|
+
out.push("Do not include:");
|
|
2445
|
+
for (const item of assistant.doNotInclude || []) out.push("- " + mdCell(item));
|
|
2446
|
+
out.push("");
|
|
2447
|
+
out.push("| Topic | Question | Owner action |");
|
|
2448
|
+
out.push("|---|---|---|");
|
|
2449
|
+
for (const item of assistant.questions || []) {
|
|
2450
|
+
out.push("| " + mdCell(item.topic || "") + " | " + mdCell(item.prompt || "") + " | " + mdCell(item.ownerAction || "") + " |");
|
|
2451
|
+
}
|
|
2452
|
+
out.push("");
|
|
2453
|
+
}
|
|
2454
|
+
|
|
2455
|
+
function formatCounts(counts) {
|
|
2456
|
+
const keys = Object.keys(counts || {}).sort();
|
|
2457
|
+
if (keys.length === 0) return "none";
|
|
2458
|
+
return keys.map(function (k) { return k + ": " + counts[k]; }).join(", ");
|
|
2459
|
+
}
|
|
2460
|
+
|
|
2461
|
+
function formatBuildIds(runtimeIncidents) {
|
|
2462
|
+
if (!runtimeIncidents || runtimeIncidents.uniqueBuildIdCount === 0) return "none";
|
|
2463
|
+
const suffix = runtimeIncidents.uniqueBuildIdCount > runtimeIncidents.buildIds.length
|
|
2464
|
+
? " +" + (runtimeIncidents.uniqueBuildIdCount - runtimeIncidents.buildIds.length) + " more"
|
|
2465
|
+
: "";
|
|
2466
|
+
return runtimeIncidents.buildIds.join(", ") + suffix;
|
|
2467
|
+
}
|
|
2468
|
+
|
|
2469
|
+
function formatScriptDomains(scriptInventory) {
|
|
2470
|
+
if (!scriptInventory || scriptInventory.uniqueDomainCount === 0) return "none";
|
|
2471
|
+
const suffix = scriptInventory.uniqueDomainCount > scriptInventory.domains.length
|
|
2472
|
+
? " +" + (scriptInventory.uniqueDomainCount - scriptInventory.domains.length) + " more"
|
|
2473
|
+
: "";
|
|
2474
|
+
return scriptInventory.domains.join(", ") + suffix;
|
|
2475
|
+
}
|
|
2476
|
+
|
|
2477
|
+
function formatSecurityHeaderDomains(securityHeaders) {
|
|
2478
|
+
if (!securityHeaders || securityHeaders.uniqueDomainCount === 0) return "none";
|
|
2479
|
+
const suffix = securityHeaders.uniqueDomainCount > securityHeaders.domains.length
|
|
2480
|
+
? " +" + (securityHeaders.uniqueDomainCount - securityHeaders.domains.length) + " more"
|
|
2481
|
+
: "";
|
|
2482
|
+
return securityHeaders.domains.join(", ") + suffix;
|
|
2483
|
+
}
|
|
2484
|
+
|
|
2485
|
+
function formatSecurityHeaderBaseline(securityHeaders) {
|
|
2486
|
+
if (!securityHeaders || securityHeaders.baselineKnownCount === 0) return "none";
|
|
2487
|
+
const missing = securityHeaders.baselineMissingCount || 0;
|
|
2488
|
+
const unknown = Math.max(0, securityHeaders.baselineKnownCount - securityHeaders.baselineMatchCount - securityHeaders.baselineMismatchCount - missing);
|
|
2489
|
+
return securityHeaders.baselineMatchCount + " match, " +
|
|
2490
|
+
securityHeaders.baselineMismatchCount + " mismatch, " +
|
|
2491
|
+
missing + " missing, " +
|
|
2492
|
+
unknown + " not stated";
|
|
2493
|
+
}
|
|
2494
|
+
|
|
2495
|
+
function formatRange(oldest, newest) {
|
|
2496
|
+
if (!oldest || !newest) return "not available";
|
|
2497
|
+
return oldest === newest ? oldest : (oldest + " to " + newest);
|
|
2498
|
+
}
|
|
2499
|
+
|
|
2500
|
+
function mdCell(value) {
|
|
2501
|
+
return String(value == null ? "" : value)
|
|
2502
|
+
.replace(/\r?\n/g, " ")
|
|
2503
|
+
.replace(/\|/g, "\\|");
|
|
2504
|
+
}
|
|
2505
|
+
|
|
2506
|
+
function renderMarkdown(view) {
|
|
2507
|
+
const out = [];
|
|
2508
|
+
out.push("# PCI DSS v" + controlsRef._meta.version + " Compliance Evidence Report");
|
|
2509
|
+
out.push("");
|
|
2510
|
+
if (view.organizationName) out.push("**Organization:** " + view.organizationName);
|
|
2511
|
+
if (view.buildLabel) out.push("**Build label:** " + view.buildLabel);
|
|
2512
|
+
if (view.evidence.manifest.buildId) out.push("**Build ID:** `" + view.evidence.manifest.buildId + "`");
|
|
2513
|
+
if (view.evidence.manifest.polymorphismFingerprint) {
|
|
2514
|
+
out.push("**Polymorphism fingerprint:** `" + view.evidence.manifest.polymorphismFingerprint + "`");
|
|
2515
|
+
}
|
|
2516
|
+
if (view.evidence.publicKeyDigest) {
|
|
2517
|
+
out.push("**Signing-key SHA-256:** `" + view.evidence.publicKeyDigest + "`");
|
|
2518
|
+
}
|
|
2519
|
+
out.push("**Generated:** " + view.generatedAt);
|
|
2520
|
+
out.push("");
|
|
2521
|
+
out.push("## Summary");
|
|
2522
|
+
out.push("");
|
|
2523
|
+
out.push("| Metric | Value |");
|
|
2524
|
+
out.push("|---|---|");
|
|
2525
|
+
out.push("| Controls evaluated | " + view.summary.controls + " |");
|
|
2526
|
+
out.push("| Sub-requirements evaluated | " + view.summary.subRequirements + " |");
|
|
2527
|
+
out.push("| Pass | " + view.summary.pass + " |");
|
|
2528
|
+
out.push("| Partial | " + view.summary.partial + " |");
|
|
2529
|
+
out.push("| Fail | " + view.summary.fail + " |");
|
|
2530
|
+
out.push("| Not inspected | " + view.summary.not_inspected + " |");
|
|
2531
|
+
out.push("| Signature kind | " + view.summary.signatureKind + " |");
|
|
2532
|
+
out.push("| Signature verified | " + (view.summary.signatureVerified ? "yes" : "no") + " |");
|
|
2533
|
+
out.push("");
|
|
2534
|
+
out.push("Overall exit code: **" + view.summary.exitCode + "** ");
|
|
2535
|
+
out.push("(0 = fully evidenced; 1 = gaps; 2 = manifest unsigned)");
|
|
2536
|
+
out.push("");
|
|
2537
|
+
renderPciDssReviewAssistantMarkdown(out, view.reviewAssistant);
|
|
2538
|
+
if (view.evidence.scriptInventory) {
|
|
2539
|
+
renderScriptInventoryMarkdown(out, view.evidence.scriptInventory);
|
|
2540
|
+
}
|
|
2541
|
+
if (view.evidence.scriptInventoryAudit) {
|
|
2542
|
+
renderScriptInventoryAuditMarkdown(out, view.evidence.scriptInventoryAudit);
|
|
2543
|
+
}
|
|
2544
|
+
if (view.evidence.securityHeaders) {
|
|
2545
|
+
renderSecurityHeaderMarkdown(out, view.evidence.securityHeaders);
|
|
2546
|
+
}
|
|
2547
|
+
if (view.evidence.runtimeIncidents) {
|
|
2548
|
+
renderRuntimeIncidentMarkdown(out, view.evidence.runtimeIncidents);
|
|
2549
|
+
}
|
|
2550
|
+
out.push("## Controls");
|
|
2551
|
+
out.push("");
|
|
2552
|
+
for (const c of view.controls) {
|
|
2553
|
+
out.push("### " + c.id + " - " + c.title);
|
|
2554
|
+
out.push("");
|
|
2555
|
+
out.push("Overall status: **" + c.status.toUpperCase() + "**");
|
|
2556
|
+
out.push("");
|
|
2557
|
+
for (const s of c.subRequirements) {
|
|
2558
|
+
out.push("- **" + s.id + "** *(" + s.status + ")* - " + s.title);
|
|
2559
|
+
if (s.detail) out.push(" - " + s.detail);
|
|
2560
|
+
if (s.evidence && s.evidence.length > 0) {
|
|
2561
|
+
for (const e of s.evidence) {
|
|
2562
|
+
out.push(" - Evidence: " + e.artefact + " (" + e.location + ") - cite: " + e.citation);
|
|
2563
|
+
}
|
|
2564
|
+
}
|
|
2565
|
+
}
|
|
2566
|
+
out.push("");
|
|
2567
|
+
}
|
|
2568
|
+
out.push("## File inventory");
|
|
2569
|
+
out.push("");
|
|
2570
|
+
out.push("| File | sha256 | Watermark | On-disk |");
|
|
2571
|
+
out.push("|---|---|---|---|");
|
|
2572
|
+
for (const f of view.evidence.files) {
|
|
2573
|
+
const wm = !f.watermark.inspected
|
|
2574
|
+
? "(not inspected)"
|
|
2575
|
+
: (!f.watermark.present
|
|
2576
|
+
? "absent"
|
|
2577
|
+
: (f.watermark.valid === true
|
|
2578
|
+
? "valid"
|
|
2579
|
+
: (f.watermark.valid === false
|
|
2580
|
+
? "INVALID"
|
|
2581
|
+
: "present (unverified)")));
|
|
2582
|
+
const ondisk = f.ondiskMatches === true ? "match" :
|
|
2583
|
+
f.ondiskMatches === false ? "MISMATCH" :
|
|
2584
|
+
"(not inspected)";
|
|
2585
|
+
out.push("| `" + f.name + "` | `" + (f.sha256 || "").slice(0, 12) + "...` | " + wm + " | " + ondisk + " |");
|
|
2586
|
+
}
|
|
2587
|
+
out.push("");
|
|
2588
|
+
out.push("## Out-of-scope (customer-owned)");
|
|
2589
|
+
out.push("");
|
|
2590
|
+
for (const oos of controlsRef.out_of_scope_customer_owns) {
|
|
2591
|
+
out.push("- **" + oos.id + "**: " + oos.note);
|
|
2592
|
+
}
|
|
2593
|
+
out.push("");
|
|
2594
|
+
out.push("---");
|
|
2595
|
+
out.push("");
|
|
2596
|
+
out.push("Generated by `jso-protector compliance pci-dss-v4`. This report aggregates evidence that JSO directly contributes; it is not a Report on Compliance (ROC) and does not substitute for a QSA-led assessment. See [PCI DSS v" + controlsRef._meta.version + "](" + controlsRef._meta.spec_url + ") for the full standard.");
|
|
2597
|
+
out.push("");
|
|
2598
|
+
return out.join("\n");
|
|
2599
|
+
}
|
|
2600
|
+
|
|
2601
|
+
module.exports = {
|
|
2602
|
+
REPORT_SCHEMA_VERSION: REPORT_SCHEMA_VERSION,
|
|
2603
|
+
generateReport: generateReport,
|
|
2604
|
+
// Exposed for tests:
|
|
2605
|
+
_collectEvidence: collectEvidence,
|
|
2606
|
+
_collectScriptInventoryEvidence: collectScriptInventoryEvidence,
|
|
2607
|
+
_collectSecurityHeaderEvidence: collectSecurityHeaderEvidence,
|
|
2608
|
+
_collectRuntimeIncidentEvidence: collectRuntimeIncidentEvidence,
|
|
2609
|
+
_mapControls: mapControls,
|
|
2610
|
+
_renderMarkdown: renderMarkdown,
|
|
2611
|
+
_buildSummary: buildSummary,
|
|
2612
|
+
_buildPciDssReviewAssistant: buildPciDssReviewAssistant,
|
|
2613
|
+
};
|