@openai/codex-security 0.8.1 → 0.8.2
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/README.md +8 -2
- package/_bundled_plugin/mcp/native/THIRD_PARTY_NOTICES.txt +4 -4
- package/_bundled_plugin/mcp/native/darwin-arm64/unix.node +0 -0
- package/_bundled_plugin/mcp/native/darwin-x64/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-arm64-gnu/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-arm64-musl/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-x64-gnu/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-x64-musl/unix.node +0 -0
- package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
- package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-002 +0 -0
- package/_bundled_plugin/scripts/workbench_coverage_receipts.py +0 -17
- package/_bundled_plugin/scripts/workbench_db.py +1 -3
- package/_bundled_plugin/scripts/workbench_saved_results.py +0 -66
- package/_bundled_plugin/scripts/workbench_target.py +0 -108
- package/_bundled_plugin/skills/publish-findings/SKILL.md +4 -0
- package/_bundled_plugin/skills/resolve-dependency-alert/SKILL.md +18 -0
- package/_bundled_plugin/skills/resolve-dependency-alert/agents/openai.yaml +4 -0
- package/_bundled_plugin/skills/threat-model-visualize/SKILL.md +83 -0
- package/_bundled_plugin/skills/threat-model-visualize/agents/openai.yaml +4 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/context-reference-overview.svg +366 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/context-reference-path.svg +558 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/control-effects.js +85 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/explorer.css +17 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/explorer.html +38 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/explorer.js +372 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/route-paths.js +71 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/source-roles.js +47 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/svg-layout.js +149 -0
- package/_bundled_plugin/skills/threat-model-visualize/references/context-explorer.md +21 -0
- package/_bundled_plugin/skills/threat-model-visualize/references/view-model.md +49 -0
- package/_bundled_plugin/skills/threat-model-visualize/scripts/build_explorer.py +563 -0
- package/dist/api.js +3 -3
- package/dist/api.js.map +1 -1
- package/dist/auth.js +1 -1
- package/dist/auth.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +27 -8
- package/dist/cli.js.map +1 -1
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +4 -4
- package/dist/contract.js.map +1 -1
- package/dist/custom-validation.js +2 -2
- package/dist/custom-validation.js.map +1 -1
- package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -1
- package/dist/deduplication/deduplication-reviewer.js +1 -1
- package/dist/deduplication/deduplication-reviewer.js.map +1 -1
- package/dist/deduplication/records-protocol.d.ts.map +1 -1
- package/dist/deduplication/records-protocol.js +36 -22
- package/dist/deduplication/records-protocol.js.map +1 -1
- package/dist/deduplication/records.d.ts +3 -1
- package/dist/deduplication/records.d.ts.map +1 -1
- package/dist/deduplication/records.js +12 -8
- package/dist/deduplication/records.js.map +1 -1
- package/dist/endor-findings.d.ts.map +1 -1
- package/dist/endor-findings.js +46 -61
- package/dist/endor-findings.js.map +1 -1
- package/dist/external-findings-import.d.ts.map +1 -1
- package/dist/external-findings-import.js +8 -6
- package/dist/external-findings-import.js.map +1 -1
- package/dist/external-findings-local.d.ts +3 -1
- package/dist/external-findings-local.d.ts.map +1 -1
- package/dist/external-findings-local.js +117 -36
- package/dist/external-findings-local.js.map +1 -1
- package/dist/external-findings-publish.d.ts +3 -1
- package/dist/external-findings-publish.d.ts.map +1 -1
- package/dist/external-findings-publish.js +51 -27
- package/dist/external-findings-publish.js.map +1 -1
- package/dist/external-findings-read.d.ts +2 -0
- package/dist/external-findings-read.d.ts.map +1 -1
- package/dist/external-findings-read.js +9 -0
- package/dist/external-findings-read.js.map +1 -1
- package/dist/external-findings.d.ts +11 -0
- package/dist/external-findings.d.ts.map +1 -1
- package/dist/external-findings.js +13 -1
- package/dist/external-findings.js.map +1 -1
- package/dist/external-import-models.d.ts +1 -1
- package/dist/external-import-models.d.ts.map +1 -1
- package/dist/external-import-models.js.map +1 -1
- package/dist/host-protocol.d.ts +5 -0
- package/dist/host-protocol.d.ts.map +1 -1
- package/dist/host-protocol.js +27 -3
- package/dist/host-protocol.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/inspector-findings.d.ts +9 -0
- package/dist/inspector-findings.d.ts.map +1 -0
- package/dist/inspector-findings.js +517 -0
- package/dist/inspector-findings.js.map +1 -0
- package/dist/patch-tui.d.ts +1 -1
- package/dist/patch-tui.d.ts.map +1 -1
- package/dist/patch-tui.js +4 -1
- package/dist/patch-tui.js.map +1 -1
- package/dist/runtime.d.ts +3 -2
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +15 -5
- package/dist/runtime.js.map +1 -1
- package/dist/scan-dashboard.d.ts.map +1 -1
- package/dist/scan-dashboard.js +25 -15
- package/dist/scan-dashboard.js.map +1 -1
- package/dist/scanner-import.d.ts +6 -1
- package/dist/scanner-import.d.ts.map +1 -1
- package/dist/scanner-import.js +14 -5
- package/dist/scanner-import.js.map +1 -1
- package/dist/semgrep-findings.d.ts.map +1 -1
- package/dist/semgrep-findings.js +39 -49
- package/dist/semgrep-findings.js.map +1 -1
- package/dist/snyk-findings.d.ts.map +1 -1
- package/dist/snyk-findings.js +78 -88
- package/dist/snyk-findings.js.map +1 -1
- package/docs/cli.md +14 -8
- package/docs/dedupe-records.md +17 -4
- package/package.json +3 -3
- package/schemas/external-findings.schema.json +1 -1
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// Pure path semantics shared by the portable renderer and its regression checks.
|
|
2
|
+
const ControlEffects = (() => {
|
|
3
|
+
function applicable(scenario, context = {}) {
|
|
4
|
+
return (scenario?.controls || []).filter(c =>
|
|
5
|
+
(!c.sourceIds || c.sourceIds.includes(context.sourceId)) &&
|
|
6
|
+
(!c.routeIds || c.routeIds.includes(context.routeId)));
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function selection(scenario, state, context = {}) {
|
|
10
|
+
const controls = applicable(scenario, context);
|
|
11
|
+
return {
|
|
12
|
+
control: controls.some(c => c.id === state.control) ? state.control : null,
|
|
13
|
+
proposal: controls.some(c => c.id === state.proposal && c.kind === 'proposed') ? state.proposal : null
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function active(scenario, proposal, context = {}) {
|
|
18
|
+
return applicable(scenario, context).filter(c => c.effect &&
|
|
19
|
+
(c.kind === 'existing' || c.id === proposal));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function resolve(scenario, proposal, context = {}) {
|
|
23
|
+
const controls = active(scenario, proposal, context);
|
|
24
|
+
// Compare step, then receipt: a prearrival block prevents an arrival check.
|
|
25
|
+
// Existing controls win only when both barriers act at the same point.
|
|
26
|
+
const blocker = controls.filter(c => c.effect.outcome === 'blocks' &&
|
|
27
|
+
c.effect.traffic !== 'continues' && c.effect.basis !== 'unverified' && Number.isInteger(c.effect.step))
|
|
28
|
+
.sort((a, b) => a.effect.step - b.effect.step ||
|
|
29
|
+
Number(a.effect.arrival === true) - Number(b.effect.arrival === true) ||
|
|
30
|
+
Number(a.kind === 'proposed') - Number(b.kind === 'proposed'))[0] || null;
|
|
31
|
+
return { controls, blocker, stop: blocker ? blocker.effect.step - 1 : -1 };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function caption(control) {
|
|
35
|
+
const e = control?.effect;
|
|
36
|
+
if (!e) return 'Effect not mapped';
|
|
37
|
+
if (e.outcome === 'blocks') {
|
|
38
|
+
const basis = control.kind === 'proposed' ? 'Would block' :
|
|
39
|
+
e.basis === 'verified' ? 'Blocks · verified in supplied evidence' : 'Blocks · if enforced';
|
|
40
|
+
return basis + (e.traffic === 'continues' ? ' · this effect leaves traffic open' :
|
|
41
|
+
e.arrival === true ? ' · decision after arrival' : '');
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
limits: control.kind === 'proposed' ? 'Would limit impact · path continues' : 'Limits impact · path continues',
|
|
45
|
+
detects: control.kind === 'proposed' ? 'Would detect activity · path continues' : 'Detects activity · path continues',
|
|
46
|
+
'does-not-block': control.kind === 'proposed' ? 'Would not block this path' : 'Does not block this path',
|
|
47
|
+
unknown: 'Effect not established'
|
|
48
|
+
}[e.outcome];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function basis(control) {
|
|
52
|
+
if (control.kind === 'proposed') return 'Proposed control';
|
|
53
|
+
return {
|
|
54
|
+
declared: 'DECLARED · IF ENFORCED',
|
|
55
|
+
verified: 'VERIFIED · SUPPLIED EVIDENCE',
|
|
56
|
+
unverified: 'EXISTING · EFFECT UNVERIFIED'
|
|
57
|
+
}[control.effect?.basis] || 'EXISTING · SOURCE-QUALIFIED';
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Split an authored polyline at a fraction of its length. The stop marker is
|
|
61
|
+
// perpendicular to the actual route, including routes with several corners.
|
|
62
|
+
function split(points, fraction) {
|
|
63
|
+
const lengths = points.slice(1).map((p, i) =>
|
|
64
|
+
Math.hypot(p[0] - points[i][0], p[1] - points[i][1]));
|
|
65
|
+
const total = lengths.reduce((sum, n) => sum + n, 0);
|
|
66
|
+
if (!total) throw new Error('A control needs a nonzero route.');
|
|
67
|
+
const target = Math.min(1, Math.max(0, fraction)) * total;
|
|
68
|
+
let distance = 0;
|
|
69
|
+
for (let i = 0; i < lengths.length; i++) {
|
|
70
|
+
const length = lengths[i];
|
|
71
|
+
if (!length) continue;
|
|
72
|
+
if (distance + length >= target || i === lengths.length - 1) {
|
|
73
|
+
const t = (target - distance) / length, a = points[i], b = points[i + 1];
|
|
74
|
+
const point = [a[0] + t * (b[0] - a[0]), a[1] + t * (b[1] - a[1])];
|
|
75
|
+
return {
|
|
76
|
+
before: [...points.slice(0, i + 1), point],
|
|
77
|
+
after: [point, ...points.slice(i + 1)],
|
|
78
|
+
point, normal: [-(b[1] - a[1]) / length, (b[0] - a[0]) / length]
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
distance += length;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return { applicable, selection, active, resolve, caption, basis, split };
|
|
85
|
+
})();
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
:root{--ink:#18313d;--muted:#647783;--line:#dce4e6;--paper:#f6f8f7;--teal:#167765;--orange:#bc541e;--purple:#78549a;font-family:Inter,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;color:var(--ink);background:var(--paper)}
|
|
2
|
+
*{box-sizing:border-box}body{margin:0}button{font:inherit;color:inherit;cursor:pointer;background:white;border:1px solid var(--line);border-radius:6px;padding:8px 10px}button:hover{border-color:#829d9f}button:disabled{opacity:.5;cursor:default}:focus-visible{outline:3px solid #5199bd;outline-offset:2px}header{padding:12px 22px;background:white;border-bottom:1px solid var(--line);display:flex;justify-content:space-between;align-items:center;gap:18px}.brand{font-weight:750;font-size:15px}.brand small{display:block;font-size:8px;letter-spacing:1.6px;color:var(--muted);margin-top:4px}main{max-width:1900px;margin:auto;padding:0 18px}h1{font-size:25px;letter-spacing:-.6px;font-weight:650;margin:0 0 5px}h2{font-size:17px;font-weight:650;margin:0 0 8px}h3{font-size:12px;margin:0 0 7px}p{line-height:1.55;margin:6px 0;color:var(--muted);font-size:12px}.eyebrow{font-size:9px;font-weight:750;letter-spacing:1px;color:var(--teal)}.intro{display:flex;justify-content:space-between;align-items:center;gap:24px;min-height:94px;padding:14px 2px}.intro p{margin:0;font-size:12px}.snapshot{border-left:2px solid #9abcb0;padding-left:14px;max-width:270px;font-size:11px;line-height:1.6;color:var(--muted)}
|
|
3
|
+
.workspace{display:grid;grid-template-columns:190px minmax(0,1fr) 300px;border:1px solid var(--line);border-radius:12px;overflow:hidden;background:white;height:calc(100dvh - 176px);min-height:530px;max-height:980px}.rail{padding:17px 10px;background:#fafbfa;border-right:1px solid var(--line);overflow:auto;scrollbar-width:thin}.rail h2{font-size:11px;padding:0 8px;margin-bottom:15px}.rail button{display:block;width:100%;text-align:left;margin-bottom:7px;border-color:transparent;background:none;padding:10px 8px;font-size:11px;line-height:1.4}.rail button.active{background:#fff;border-color:#aec7c8;box-shadow:0 2px 8px #18313d08}.rail button b{display:block;margin-bottom:6px}.rail button small{display:block;color:#647783;font-size:9px}.rail .id{font:10px ui-monospace,monospace;color:#637f85;margin-right:6px}.rail .help{font-size:10px;border-top:1px solid var(--line);padding:12px 8px}.map-column{min-width:0;display:flex;flex-direction:column}.toolbar{padding:15px 18px;display:flex;align-items:center;min-height:77px}.toolbar h2{font-size:16px;margin-bottom:5px}.toolbar p{font-size:11px;margin:0}.canvas{position:relative;background-color:#fbfcfb;background-image:radial-gradient(#cdd9d9 .7px,transparent .7px);background-size:17px 17px;border-block:1px solid #e9eeee;flex:1;min-height:260px;overflow:hidden}.canvas svg{display:block;width:100%;height:100%;touch-action:none}.zoom{position:absolute;bottom:12px;right:12px;display:flex;background:white;border:1px solid var(--line);border-radius:6px;overflow:hidden}.zoom button{border:0;border-right:1px solid var(--line);border-radius:0;font-size:12px;min-width:32px}.zoom button:last-child{border-right:0}.legend{display:flex;gap:9px 14px;flex-wrap:wrap;padding:12px 16px;font-size:9px;color:var(--muted)}.legend span:before{content:'';display:inline-block;width:18px;border-top:2px solid #9fb5be;margin-right:5px;vertical-align:middle}.legend .risk:before{border-color:var(--orange)}.legend .unknown:before{border-top-style:dashed}.legend .existing:before{border-color:var(--teal)}.legend .proposed:before{border-color:var(--purple);border-top-style:dashed}
|
|
4
|
+
.detail-panel{border-left:1px solid var(--line);overflow:auto;scrollbar-width:thin;padding:0 16px 18px;background:#fdfefd}.detail-heading{display:flex;justify-content:space-between;align-items:center;padding:15px 0 9px}.detail-heading h2{font-size:12px;margin:0}.detail-heading span{font:10px ui-monospace,monospace;color:var(--muted)}.trace-navigation{position:sticky;top:0;z-index:3;background:#fdfefdf7;padding:6px 0 12px;display:flex;gap:5px;border-bottom:1px solid var(--line);margin-bottom:14px}.trace-navigation button{font-size:10px;padding:7px;flex:1;white-space:nowrap}.trace-title{font-size:16px;line-height:1.35;letter-spacing:-.2px;margin:8px 0}.badge{display:inline-block;background:#eef3f2;color:#49676b;padding:5px 7px;font-size:9px;border-radius:4px;margin-bottom:3px;line-height:1.5}.steps{display:grid;gap:6px;margin:13px 0}.steps button{text-align:left;font-size:11px;line-height:1.4;background:#fff;padding:8px 9px;position:relative}.steps button.current{background:#fff1e6;border-color:#bc754e}.steps span{display:block;font:9px ui-monospace,monospace;color:var(--muted);margin-bottom:4px}.steps button.stop{border-left:3px solid var(--teal);color:var(--teal);background:#f0f8f4}.steps button.proposed{border-color:#a789bd;color:var(--purple);background:#f8f2fd}.steps button.unreached{border-style:dashed;background:#f5f7f6;color:#5e727a;opacity:.7}.step-description{font-size:11px;padding:10px;border-left:2px solid #bc754e;background:#fff8f1;margin-bottom:14px}.controls{border-top:1px solid var(--line);padding-top:14px;margin-top:14px}.controls h3{font-size:11px}.controls .group-label{font-size:9px;color:var(--muted);letter-spacing:.6px;margin:12px 0 5px}.controls button{width:100%;font-size:11px;text-align:left;margin:0 0 6px;padding:9px 10px;line-height:1.4}.controls button span{display:block;font-size:9px;color:var(--muted);margin-top:4px}.controls button.existing{border-left:3px solid #8cb6a8}.controls button.proposed{border-left:3px solid #b39acb}.controls button.active{border-color:#698e88;background:#eef6f2}.controls button.proposed.active{border-color:#a789bd;background:#f7f0fd}.controls button.proposed b:before{content:'+ ';font-weight:400}.controls button.proposed.active b:before{content:'− '}.effect-card{border:1px solid #b5d4c6;border-left:3px solid var(--teal);border-radius:6px;background:#f0f8f4;padding:11px;margin:12px 0}.effect-card.proposed{border-color:#c7b4da;border-left-color:var(--purple);background:#f8f3fc}.effect-card .eyebrow{font-size:8px;letter-spacing:.5px;color:var(--teal)}.effect-card.proposed .eyebrow{color:var(--purple)}.effect-card h3{font-size:13px;line-height:1.4;margin-top:7px}.effect-card p{font-size:11px;color:#49655f}.effect-card.proposed p{color:#695575}.effect-card .disposition{font-weight:650;margin-top:8px}.evidence{margin-top:9px;display:flex;gap:5px;flex-wrap:wrap}.evidence button{font:10px ui-monospace,monospace;background:#f2f5f5;text-align:left;overflow-wrap:anywhere;padding:6px 8px;max-width:100%}.detail-panel details{border-top:1px solid var(--line);padding-top:10px;margin-top:12px}.detail-panel summary{font-size:11px;font-weight:600;cursor:pointer;padding:3px 0}.detail-panel details p{font-size:11px}.detail-panel details h3{margin-top:12px;font-size:11px}.inspector{border-top:2px solid #698e97;margin-top:15px;padding-top:15px}.inspector .close{float:right;font-size:10px;padding:4px 6px}.inspector h2{font-size:15px;margin-top:9px}.inspector p{font-size:11px}
|
|
5
|
+
.metadata{margin-top:15px}.metadata summary{cursor:pointer;font-size:12px;font-weight:650;padding:10px 0}.metadata pre{white-space:pre-wrap;overflow-wrap:anywhere;font:11px/1.65 ui-monospace,monospace;background:white;padding:18px;border:1px solid var(--line);border-radius:8px}dialog{width:min(850px,92vw);max-height:88vh;overflow:auto;border:1px solid #bbcdce;border-radius:12px;padding:25px;color:var(--ink);box-shadow:0 30px 100px #0d293e45}dialog::backdrop{background:#102c3b80}dialog blockquote{margin:18px 0;background:#f2f6f4;border-left:3px solid #86a99a;padding:17px;white-space:pre-wrap;overflow-wrap:anywhere;line-height:1.65;font-size:13px}dialog .close{float:right}footer{font-size:10px;color:var(--muted);padding:18px 0;line-height:1.6}.actions{display:flex;gap:6px}.actions button{font-size:10px}.hidden{display:none!important}
|
|
6
|
+
@media(min-width:1700px){.workspace{grid-template-columns:215px minmax(0,1fr) 330px}.rail button{font-size:12px}.detail-panel p{font-size:12px}.steps button,.controls button{font-size:12px}}
|
|
7
|
+
@media(max-width:1150px){main{padding:0 10px}.snapshot{display:none}.workspace{grid-template-columns:155px minmax(0,1fr) 265px}.detail-panel{padding-inline:12px}.rail{padding-inline:5px}.toolbar{padding:12px}.toolbar h2{font-size:14px}.legend{gap:8px;padding:10px}.intro{min-height:85px}.workspace{height:calc(100dvh - 165px)}}
|
|
8
|
+
@media(max-width:850px){.workspace{grid-template-columns:minmax(0,1fr) 250px;grid-template-rows:auto minmax(0,1fr);min-height:620px}.rail{grid-column:1/-1;display:flex;gap:5px;padding:8px;overflow-x:auto;overflow-y:hidden;border-right:0;border-bottom:1px solid var(--line)}.rail h2,.rail .help{display:none}.rail button{min-width:145px;max-width:175px;margin:0;font-size:10px}.rail button small{display:none}.rail button b{margin:0}.intro h1{font-size:22px}.canvas svg{min-height:0}.toolbar{min-height:70px}.map-column{min-height:0}}
|
|
9
|
+
@media(max-width:600px){header{padding:10px}.brand{font-size:12px}.actions button{font-size:9px;padding:6px}.intro{min-height:85px}.workspace{display:flex;flex-direction:column;height:auto}.rail{flex:none;min-height:68px}.map-column{min-height:450px}.canvas{min-height:330px}.detail-panel{max-height:520px;border-left:0;border-top:1px solid var(--line)}.snapshot{display:none}}
|
|
10
|
+
.trace-navigation[hidden]{display:none}.panel-tabs{display:flex;gap:6px;margin:12px 0}.panel-tabs button{flex:1;font-size:10px;padding:7px}.panel-tabs button[aria-selected=true]{background:#18313d;border-color:#18313d;color:white}.inspect-control{font-size:10px;background:transparent;border:0;border-bottom:1px solid #9ab8ab;border-radius:0;padding:3px 0;margin-top:5px}.control-hint,.earlier-block{font-size:10px!important}.controls:first-child{margin-top:0}
|
|
11
|
+
@media(min-width:601px){.map-column{min-height:0}.canvas{flex:1 1 0;min-height:0}}
|
|
12
|
+
.rail,.detail-panel{overscroll-behavior:contain}
|
|
13
|
+
.toolbar #edge-context{margin-left:auto;white-space:nowrap;font-size:10px}
|
|
14
|
+
.source-choice-label{display:block;font-size:10px;font-weight:650;margin-bottom:6px}#source-select{font:inherit;font-size:11px;line-height:1.4;width:100%;padding:8px;color:var(--ink);background:#fff;border:1px solid #aec7c8;border-radius:6px}
|
|
15
|
+
.source-context{margin:10px 0}.detail-panel .source-card{border:0;border-left:3px solid var(--source-ink);border-radius:5px;background:var(--source-fill);padding:8px 10px;margin:7px 0}.source-card summary{color:var(--source-ink);line-height:1.4;list-style:none}.source-card summary:after{content:'Details +';display:block;font-size:9px;font-weight:400;margin-top:3px}.source-card[open] summary:after{content:'Details −'}.source-card summary small{display:block;font-size:9px;font-weight:500;margin-bottom:3px}.source-card summary strong{font-size:12px}.source-card p{color:var(--ink)}.source-unmapped{display:block;font-size:9px;font-weight:400;margin-top:5px}.source-gap{font-size:10px!important}.source-inspect{padding:8px;background:var(--source-fill);border-left:3px solid var(--source-ink)}#source-legend{display:contents}.legend #source-legend:before,.legend .source-key:before{content:none}.source-key i{display:inline-block;width:18px;height:10px;border:1px solid;border-radius:2px;vertical-align:middle;margin-right:5px}
|
|
16
|
+
.route-picker{margin:12px 0;padding-bottom:10px;border-bottom:1px solid var(--line)}.route-picker label{display:block;font-size:10px;font-weight:650;margin-bottom:6px}.route-picker select{font-family:inherit;font-size:11px;line-height:1.4;color:var(--ink);width:100%;padding:8px;background:white;border:1px solid #aec7c8;border-radius:6px}.route-key{font-size:10px!important;line-height:1.5}.route-picker .evidence{margin:6px 0 0}.route-picker .evidence button{font-size:9px;padding:4px 5px}.legend .transit:before,.legend .focus:before{height:10px;border:1px solid #b5c9cd;border-radius:2px;background:#fff0d5}.legend .focus:before{border:2px solid var(--orange)}
|
|
17
|
+
@media(min-width:851px) and (max-width:1350px){.workspace{grid-template-columns:155px minmax(0,1fr) 265px}.detail-panel{padding-inline:12px}.rail{padding-inline:5px}.toolbar{padding:12px}.toolbar h2{font-size:14px}}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
|
5
|
+
<title>Threat model explorer</title>
|
|
6
|
+
<style>__EXPLORER_CSS__</style>
|
|
7
|
+
</head>
|
|
8
|
+
<body>
|
|
9
|
+
<header><div class="brand" id="brand"></div><div class="actions"><button id="svg-download">Download map SVG</button><button id="html-download">Download HTML</button></div></header>
|
|
10
|
+
<main>
|
|
11
|
+
<section class="intro"><div><h1 id="title"></h1><p id="subtitle"></p></div><div class="snapshot" id="snapshot"></div></section>
|
|
12
|
+
<section class="workspace" aria-label="Threat model workbench">
|
|
13
|
+
<nav class="rail" aria-label="Threat scenarios" id="rail"></nav>
|
|
14
|
+
<div class="map-column">
|
|
15
|
+
<div class="toolbar"><div><h2 id="map-title"></h2><p id="map-description"></p></div><button id="edge-context" hidden aria-pressed="false">More connections</button></div>
|
|
16
|
+
<div class="canvas"><svg id="map" role="group" aria-label="Interactive architecture map"></svg><div class="zoom"><button id="out" aria-label="Zoom out">−</button><button id="in" aria-label="Zoom in">+</button><button id="fit">Fit</button></div></div>
|
|
17
|
+
<div class="legend"><span id="source-legend"></span><span class="risk">Selected route</span><span class="transit">On route · normal outline</span><span class="focus">Scenario focus</span><span class="existing">Existing control</span><span class="proposed">Proposed control</span><span class="unknown">Conditional / unreached</span></div>
|
|
18
|
+
</div>
|
|
19
|
+
<aside class="detail-panel" aria-label="Path and controls">
|
|
20
|
+
<div class="detail-heading"><h2>Path & controls</h2><span id="trace-position"></span></div>
|
|
21
|
+
<div class="trace-navigation" id="trace-navigation"></div>
|
|
22
|
+
<section id="trace" aria-live="polite"></section>
|
|
23
|
+
<section id="inspector" class="inspector hidden" aria-live="polite"></section>
|
|
24
|
+
</aside>
|
|
25
|
+
</section>
|
|
26
|
+
<section class="metadata"><details><summary>Source & deployment context</summary><div id="metadata"></div></details><details><summary>Full supplied assessment</summary><p>The supplied assessment is preserved in full, including its qualifications.</p><pre id="assessment"></pre></details></section>
|
|
27
|
+
<footer id="footer"></footer>
|
|
28
|
+
</main>
|
|
29
|
+
<dialog id="dialog" aria-labelledby="evidence-title"><button class="close" id="close-dialog" aria-label="Close evidence">×</button><div id="dialog-content"></div></dialog>
|
|
30
|
+
<script id="model-data" type="application/json">__MODEL_JSON__</script>
|
|
31
|
+
<script id="assessment-data" type="application/json">__ASSESSMENT_JSON__</script>
|
|
32
|
+
<script>__CONTROL_EFFECTS_JS__</script>
|
|
33
|
+
<script>__ROUTE_PATHS_JS__</script>
|
|
34
|
+
<script>__SOURCE_ROLES_JS__</script>
|
|
35
|
+
<script>__SVG_LAYOUT_JS__</script>
|
|
36
|
+
<script>__EXPLORER_JS__</script>
|
|
37
|
+
</body>
|
|
38
|
+
</html>
|
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const M = JSON.parse(document.getElementById('model-data').textContent);
|
|
3
|
+
const assessment = JSON.parse(document.getElementById('assessment-data').textContent);
|
|
4
|
+
const $ = id => document.getElementById(id);
|
|
5
|
+
const esc = v => String(v ?? '').replace(/[&<>"']/g, c => ({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]));
|
|
6
|
+
const textMeasureCache = new Map();
|
|
7
|
+
const mapLayoutCache = new Map();
|
|
8
|
+
function measureSvgText(text, size, weight = 400) {
|
|
9
|
+
const family = typeof getComputedStyle === 'function' ? getComputedStyle($('map')).fontFamily : 'Arial,sans-serif';
|
|
10
|
+
const key = JSON.stringify([text,size,weight,family]);
|
|
11
|
+
if (textMeasureCache.has(key)) return textMeasureCache.get(key);
|
|
12
|
+
let measured = SvgLayout.fallback(text,size);
|
|
13
|
+
if (document.createElementNS && $('map').appendChild) {
|
|
14
|
+
const node = document.createElementNS('http://www.w3.org/2000/svg','text');
|
|
15
|
+
node.textContent = text; node.setAttribute('font-size',size); node.setAttribute('font-weight',weight);
|
|
16
|
+
node.setAttribute('font-family',family); node.setAttribute('visibility','hidden'); $('map').appendChild(node);
|
|
17
|
+
try { const box = node.getBBox(); if (box.width > 0) measured = {w:box.width,ascent:Math.max(size*.8,-box.y),descent:Math.max(size*.2,box.y+box.height)}; }
|
|
18
|
+
finally { node.remove(); }
|
|
19
|
+
}
|
|
20
|
+
textMeasureCache.set(key,measured); return measured;
|
|
21
|
+
}
|
|
22
|
+
function captionSvg(p, color, region = null) {
|
|
23
|
+
if (!p) return '';
|
|
24
|
+
const x = p.x+p.w/2, y = p.y+4+p.ascent;
|
|
25
|
+
let leader = '';
|
|
26
|
+
if(region){
|
|
27
|
+
const cy=p.y+p.h/2,rx=Math.max(region.x,Math.min(x,region.x+region.w)),ry=Math.max(region.y,Math.min(cy,region.y+region.h));
|
|
28
|
+
const sides=[[region.x,ry],[region.x+region.w,ry],[rx,region.y],[rx,region.y+region.h]];
|
|
29
|
+
sides.sort((a,b)=>Math.hypot(a[0]-x,a[1]-cy)-Math.hypot(b[0]-x,b[1]-cy));
|
|
30
|
+
const targetFor=a=>[Math.max(p.x,Math.min(a[0],p.x+p.w)),Math.max(p.y,Math.min(a[1],p.y+p.h))];
|
|
31
|
+
const anchor=sides.find(a=>!M.nodes.some(n=>SvgLayout.segmentIntersectsRect(a,targetFor(a),SvgLayout.padded(n,2)))) || sides[0],target=targetFor(anchor);
|
|
32
|
+
if(Math.hypot(target[0]-anchor[0],target[1]-anchor[1])>2)leader=`<path data-caption-leader="true" d="M${esc(anchor[0])} ${esc(anchor[1])} L${esc(target[0])} ${esc(target[1])}" fill="none" stroke="${color}" stroke-width="1" opacity=".6"/>`;
|
|
33
|
+
}
|
|
34
|
+
if(p.edge){const anchor=SvgLayout.sample(p.edge.points,SvgLayout.nearestOffset(p.edge.points,[x,p.y+p.h/2]));
|
|
35
|
+
const target=[Math.max(p.x,Math.min(anchor[0],p.x+p.w)),Math.max(p.y,Math.min(anchor[1],p.y+p.h))];
|
|
36
|
+
if(Math.hypot(target[0]-anchor[0],target[1]-anchor[1])>12)leader=`<path data-caption-leader="true" d="M${esc(anchor[0])} ${esc(anchor[1])} L${esc(target[0])} ${esc(target[1])}" fill="none" stroke="${color}" stroke-width="1" stroke-dasharray="2 3" opacity=".6"/>`;
|
|
37
|
+
}
|
|
38
|
+
return `<g data-caption="${esc(p.id)}" data-caption-kind="${p.kind}" data-layout-unresolved="${p.conflicts>0}" data-connector-crossings="${p.connectorCrossings||0}"><title>${esc(p.text)}</title>${leader}<text text-anchor="middle" font-size="${p.size}" font-weight="${p.weight}" fill="${color}" paint-order="stroke" stroke="#fbfcfb" stroke-width="5" stroke-linejoin="round">${p.lines.map((line,i)=>`<tspan x="${esc(x)}" y="${esc(y+i*p.lineHeight)}">${esc(line)}</tspan>`).join('')}</text></g>`;
|
|
39
|
+
}
|
|
40
|
+
const state = {scenario:null, route:null, source:null, step:-1, node:null, control:null, proposal:null, tab:'path', context:false, zoom:1, x:0, y:0};
|
|
41
|
+
const hypothesis = () => M.scenarios.find(s => s.id === state.scenario);
|
|
42
|
+
const evidence = id => M.evidence.find(e => e.id === id);
|
|
43
|
+
const controlContext = () => ({routeId:state.route, sourceId:sourceState().selected?.id});
|
|
44
|
+
const applicableControls = () => ControlEffects.applicable(hypothesis(), controlContext());
|
|
45
|
+
const selectedControl = () => applicableControls().find(c => c.id === state.control);
|
|
46
|
+
const refs = ids => `<div class="evidence">${(ids || []).map(id => `<button data-evidence="${esc(id)}">${esc(evidence(id).label)} ↗</button>`).join('')}</div>`;
|
|
47
|
+
const effectState = () => ControlEffects.resolve(hypothesis(), state.proposal, controlContext());
|
|
48
|
+
const routeState = () => RoutePaths.resolve(M, hypothesis(), state.route, effectState().stop, effectState().blocker?.effect.arrival === true);
|
|
49
|
+
const sourceState = () => SourceRoles.resolve(M, hypothesis(), state.route, state.source);
|
|
50
|
+
const controlColor = c => c?.kind === 'proposed' ? '#78549a' : '#167765';
|
|
51
|
+
const pointsText = points => esc(points.map(p => p.join(',')).join(' '));
|
|
52
|
+
|
|
53
|
+
function hash() {
|
|
54
|
+
const q = new URLSearchParams();
|
|
55
|
+
if (state.scenario) q.set('scenario', state.scenario);
|
|
56
|
+
if (state.route) q.set('route', state.route);
|
|
57
|
+
if (state.source) q.set('source', state.source);
|
|
58
|
+
if (state.step >= 0) q.set('step', state.step + 1);
|
|
59
|
+
if (state.node) q.set('node', state.node);
|
|
60
|
+
if (state.control) q.set('control', state.control);
|
|
61
|
+
if (state.proposal) q.set('preview', state.proposal);
|
|
62
|
+
if (state.tab !== 'path') q.set('panel', state.tab);
|
|
63
|
+
if (state.context && Array.isArray(M.overviewEdges)) q.set('context', '1');
|
|
64
|
+
history.replaceState(null, '', '#' + q);
|
|
65
|
+
}
|
|
66
|
+
function readHash() {
|
|
67
|
+
const q = new URLSearchParams(location.hash.slice(1));
|
|
68
|
+
state.scenario = M.scenarios.some(s => s.id === q.get('scenario')) ? q.get('scenario') : null;
|
|
69
|
+
const s = hypothesis();
|
|
70
|
+
state.route = q.get('route');
|
|
71
|
+
state.source = q.get('source');
|
|
72
|
+
state.step = s && Number.isInteger(Number(q.get('step'))) && Number(q.get('step')) > 0 ? Math.min(s.steps.length - 1, Number(q.get('step')) - 1) : -1;
|
|
73
|
+
state.node = M.nodes.some(n => n.id === q.get('node')) ? q.get('node') : null;
|
|
74
|
+
state.control = q.get('control');
|
|
75
|
+
state.proposal = q.get('preview') || state.control;
|
|
76
|
+
state.tab = q.get('panel') === 'controls' ? 'controls' : 'path';
|
|
77
|
+
state.context = Array.isArray(M.overviewEdges) && q.get('context') === '1';
|
|
78
|
+
render();
|
|
79
|
+
}
|
|
80
|
+
function focusTarget() {
|
|
81
|
+
const el = document.activeElement;
|
|
82
|
+
if (!el) return null;
|
|
83
|
+
for (const key of ['data-scenario','data-step','data-node','data-control','data-control-inspect','data-panel'])
|
|
84
|
+
if (el.hasAttribute(key)) return '[' + key + '="' + CSS.escape(el.getAttribute(key)) + '"]';
|
|
85
|
+
return el.id ? '#' + CSS.escape(el.id) : null;
|
|
86
|
+
}
|
|
87
|
+
function restoreFocus(selector) {
|
|
88
|
+
if (!selector) return;
|
|
89
|
+
let target = document.querySelector(selector);
|
|
90
|
+
if (target?.disabled) target = document.querySelector('[data-step="' + state.step + '"]');
|
|
91
|
+
if (!target) target = document.querySelector('#rail button.active');
|
|
92
|
+
target?.focus({preventScroll:true});
|
|
93
|
+
}
|
|
94
|
+
function limitStep() {
|
|
95
|
+
const {stop} = effectState();
|
|
96
|
+
if (stop >= 0 && state.step > stop) state.step = stop;
|
|
97
|
+
if (!hypothesis()?.steps.length) state.step = -1;
|
|
98
|
+
}
|
|
99
|
+
function effectCard(c, compact = false) {
|
|
100
|
+
if (!c) return '';
|
|
101
|
+
const e = c.effect;
|
|
102
|
+
if (!e) return `<div class="effect-card ${esc(c.kind)}"><div class="eyebrow">${c.kind === 'proposed' ? 'Proposed control' : 'EXISTING · SOURCE-QUALIFIED'}</div><h3>${esc(c.title)}</h3><p>${esc(c.description)}</p><p>Effect not mapped. This annotation does not stop the trace.</p>${refs(c.evidence)}</div>`;
|
|
103
|
+
const duplicate = c.description === e.reason;
|
|
104
|
+
return `<div class="effect-card ${esc(c.kind)}" data-effect-outcome="${esc(e.outcome)}"><div class="eyebrow">${esc(ControlEffects.basis(c))}</div><h3>${esc(e.label)}</h3>${compact ? '' : `<p><strong>${esc(c.title)}:</strong> ${esc(c.description)}</p>`}${compact || !duplicate ? `<p>${esc(e.reason)}</p>` : ''}<p class="disposition">${esc(ControlEffects.caption(c))}</p><p><strong>Applies when:</strong> ${esc(e.conditions)}</p><p><strong>What remains:</strong> ${esc(e.residual)}</p>${compact ? `<button class="inspect-control" data-control-inspect="${esc(c.id)}">Description & evidence ↗</button>` : refs(c.evidence)}</div>`;
|
|
105
|
+
}
|
|
106
|
+
function renderControls(s) {
|
|
107
|
+
const {blocker} = effectState(), selected = selectedControl() || blocker;
|
|
108
|
+
const group = kind => applicableControls().filter(c => c.kind === kind).map(c => {
|
|
109
|
+
const chosen = c.kind === 'proposed' ? state.proposal === c.id : selected?.id === c.id;
|
|
110
|
+
return `<button data-control="${esc(c.id)}" class="${kind} ${chosen ? 'active' : ''}" aria-pressed="${chosen}"><b>${esc(c.title)}</b><span>${esc(c.effect ? ControlEffects.caption(c) : 'Effect not mapped')}</span></button>`;
|
|
111
|
+
}).join('');
|
|
112
|
+
return `<div class="controls"><h3>Controls on this path</h3>${applicableControls().some(c => c.kind === 'existing') ? `<p class="group-label">EXISTING · AS DESCRIBED IN THE ASSESSMENT</p>${group('existing')}` : ''}${applicableControls().some(c => c.kind === 'proposed') ? `<p class="group-label">Proposed controls</p>${group('proposed')}<p class="control-hint">Select a proposed control to preview its effect; select it again to restore the assessed path.</p>` : ''}</div>${selected ? effectCard(selected) : '<p>Select a control to see where and why it acts.</p>'}${selectedControl()?.nodes?.length ? '<p>C marks the selected control locus; it does not establish enforcement.</p>' : ''}${blocker && selected && blocker.id !== selected.id ? `<p class="earlier-block"><strong>First barrier:</strong> ${esc(blocker.title)} ${blocker.kind === 'proposed' ? 'would stop' : 'stops'} this path at step ${esc(blocker.effect.step)}, under its stated conditions.${selected.effect?.traffic === 'continues' ? ' It may stop the flow before the selected effect occurs.' : ''}</p>` : ''}`;
|
|
113
|
+
}
|
|
114
|
+
function sourceContext(s) {
|
|
115
|
+
const {sources, allSources, selected, jointRequirement} = sourceState();
|
|
116
|
+
if (!sources.length) return s.sourceNote || s.sources?.length ? `<p class="source-gap">${esc(s.sourceNote || 'No supplied starting position is mapped to this documented flow.')}</p>` : '';
|
|
117
|
+
const selector = selected && allSources.length > 1 ? `<label class="source-choice-label" for="source-select">Alternative starting positions · choose one</label><select id="source-select">${allSources.map(source => `<option value="${esc(source.id)}" ${source.id === selected.id ? 'selected' : ''}>${esc(source.label)}</option>`).join('')}</select><p class="source-gap">These are alternative starting positions. ${selected.relatedEdges ? 'Highlighted relationships are supplied for this source.' : 'Relationship highlights retain the scenario set unless a documented flow is selected.'}</p>` : '';
|
|
118
|
+
return `<section class="source-context" aria-label="Threat sources">${selector}${jointRequirement ? `<p class="source-gap">${esc(jointRequirement)}</p>` : ''}${sources.map(source => {
|
|
119
|
+
const p = SourceRoles.palette[source.kind];
|
|
120
|
+
return `<details class="source-card" data-source-id="${esc(source.id)}" style="--source-fill:${p.fill};--source-ink:${p.ink}"><summary><small>${esc(p.label)} · ${source.basis === 'scenario-assumption' ? 'assumed' : source.basis === 'assessment-observed' ? 'source-observed' : 'uncertain'}</small><strong>${esc(source.label)}</strong>${source.node === null ? '<span class="source-unmapped">Source not mapped to a component in this view</span>' : ''}</summary><p>${esc(source.description)}</p><p><strong>Starting authority:</strong> ${esc(source.authority)}</p><p>${esc(SourceRoles.basis[source.basis])}. Scenario status remains ${esc(s.status)}.</p>${refs(source.evidence)}</details>`;
|
|
121
|
+
}).join('')}${s.sourceNote ? `<p class="source-gap">${esc(s.sourceNote)}</p>` : ''}</section>`;
|
|
122
|
+
}
|
|
123
|
+
function branchEvidence(routing, scenario) {
|
|
124
|
+
if (!routing?.branchStates.length) return '';
|
|
125
|
+
const edges = new Map(M.edges.map(edge => [edge.id, edge]));
|
|
126
|
+
const nodes = new Map(M.nodes.map(node => [node.id, node]));
|
|
127
|
+
return `<details class="branch-evidence"><summary>Branch evidence · ${routing.branchStates.length}</summary>${routing.branchStates.map(({branch, active, reached}, index) => {
|
|
128
|
+
const chain = branch.edges.map(id => edges.get(id));
|
|
129
|
+
const path = [chain[0].from, ...chain.map(edge => edge.to)].map(id => nodes.get(id).title).join(' → ');
|
|
130
|
+
const step = branch.beforeStep ?? branch.afterStep;
|
|
131
|
+
const timing = step === undefined ? 'No occurrence order supplied.' :
|
|
132
|
+
`${branch.beforeStep === undefined ? 'After successful' : 'Before'} step ${step}: ${scenario.steps[step - 1].title}.`;
|
|
133
|
+
const reach = active ? 'Active in this view.' : reached ? `Partially reached in this view (${reached} of ${chain.length} connections).` : 'Not reached in this view.';
|
|
134
|
+
return `<section data-route-branch="${index}" data-path-state="${active ? 'active' : reached ? 'partial' : 'unreached'}"><h3>${esc(path)}</h3><p>${reach} ${esc(timing)}</p>${refs(branch.evidence)}</section>`;
|
|
135
|
+
}).join('')}</details>`;
|
|
136
|
+
}
|
|
137
|
+
function renderTrace(s) {
|
|
138
|
+
if (!s) return `<h2 class="trace-title">${esc(M.overviewTitle)}</h2><p>${esc(M.overview)}</p><h3 style="margin-top:18px">Evidence boundary</h3><p>${esc(M.evidenceBoundary)}</p><p>Select a scenario to keep its map, steps and controls in this workspace.</p>`;
|
|
139
|
+
const {blocker, stop} = effectState();
|
|
140
|
+
const continuing = effectState().controls.filter(c => c.effect.outcome === 'blocks' && c.effect.traffic === 'continues');
|
|
141
|
+
const resolvedRoute = routeState(), route = resolvedRoute?.route;
|
|
142
|
+
const routing = route ? `<div class="route-picker">${s.routes.length > 1 ? `<label for="route-select">Documented flow · choose an alternative</label><select id="route-select">${s.routes.map(r => `<option value="${esc(r.id)}" ${r.id === route.id ? 'selected' : ''}>${esc(r.label)}</option>`).join('')}</select>` : `<p class="group-label">${esc(route.label)}</p>`}<p class="route-key">Filled components carry this route. Normal outlines indicate transit; orange outlines mark the scenario focus, subject to its stated confidence.</p>${refs(route.evidence)}${branchEvidence(resolvedRoute, s)}</div>` : '';
|
|
143
|
+
const context = `<details><summary>Conditions, impact & source evidence</summary><h3>Required conditions</h3><p>${esc(s.prerequisites)}</p><h3>Potential impact</h3><p>${esc(s.impact)}</p><h3>Severity & confidence</h3><p>${esc(s.calibration)}</p>${s.pathNote ? `<p><strong>Path scope:</strong> ${esc(s.pathNote)}</p>` : ''}${refs(s.evidence)}</details>`;
|
|
144
|
+
const tabs = `<div class="panel-tabs" role="tablist" aria-label="Inspector view"><button role="tab" data-panel="path" aria-selected="${state.tab === 'path'}">Path trace</button><button role="tab" data-panel="controls" aria-selected="${state.tab === 'controls'}">Controls · ${applicableControls().length}</button></div>`;
|
|
145
|
+
const steps = `<div class="steps" aria-label="Ordered path">${s.steps.map((t, i) => {
|
|
146
|
+
const stopped = i === stop, unreached = stop >= 0 && i > stop;
|
|
147
|
+
return `<button data-step="${i}" class="${state.step === i ? 'current ' : ''}${stopped ? 'stop ' + esc(blocker.kind) : ''}${unreached ? 'unreached' : ''}" aria-pressed="${state.step === i}" ${unreached ? 'disabled' : ''}><span>${stopped ? blocker.kind === 'proposed' ? 'Proposed control · would stop at ' : 'CONTROL · STOP AT ' : unreached ? 'NOT REACHED · ' : ''}${String(i + 1).padStart(2, '0')}</span>${esc(stopped ? blocker.effect.label : t.title)}</button>`;
|
|
148
|
+
}).join('')}</div>`;
|
|
149
|
+
const stepText = state.step >= 0 ? `<div class="step-description">${state.step === stop ? esc(blocker.effect.reason) : esc(s.steps[state.step].description)}</div>` : '';
|
|
150
|
+
const rating = (s.priority ? ' · ' + esc(s.priority) + ' review priority' : '') +
|
|
151
|
+
(s.severity ? ' · ' + esc(s.severity) + ' severity' : '');
|
|
152
|
+
return `<span class="badge">${esc(s.status)}${rating}</span><h2 class="trace-title">${esc(s.title)}</h2>${tabs}${state.tab === 'controls' ? renderControls(s) : `${sourceContext(s)}${routing}<p>${applicableControls().some(c => c.effect?.outcome === 'blocks' && c.effect.traffic === 'continues') ? '<strong>Assessment context:</strong> ' : ''}${esc(s.summary)}</p>${blocker ? effectCard(blocker, true) : ''}${blocker && continuing.length ? '<p>A separate barrier may stop the flow before another effect occurs.</p>' : ''}${continuing.map(c => effectCard(c, true)).join('')}${steps}${stepText}${!s.steps.length ? `<p>${esc(s.pathNote || 'Affected components only; an ordered path is not established.')}</p>` : ''}`}${context}`;
|
|
153
|
+
}
|
|
154
|
+
function render() {
|
|
155
|
+
const focus = focusTarget(), s = hypothesis(), panel = document.querySelector('.detail-panel'), scroll = panel.scrollTop;
|
|
156
|
+
state.route = hypothesis()?.routes?.find(r => r.id === state.route)?.id || hypothesis()?.routes?.[0]?.id || null;
|
|
157
|
+
state.source = sourceState().selected?.id || null;
|
|
158
|
+
Object.assign(state, ControlEffects.selection(s, state, controlContext()));
|
|
159
|
+
limitStep();
|
|
160
|
+
const {stop} = effectState();
|
|
161
|
+
$('rail').innerHTML = `<h2>${esc(M.scenarioLabel || 'Threat scenarios')} · ${M.scenarios.length}</h2><button data-scenario="" class="${!s ? 'active' : ''}">⊞ System overview</button>` + M.scenarios.map(h => `<button data-scenario="${esc(h.id)}" class="${s === h ? 'active' : ''}" aria-pressed="${s === h}"><b><span class="id">${esc(h.id)}</span>${esc(h.title)}</b><small>${esc(h.status)}</small></button>`).join('') + '<p class="help">Select a scenario to inspect its relationships and controls. Step through an ordered path when supplied.</p>';
|
|
162
|
+
$('map-title').textContent = s ? s.title : M.mapTitle;
|
|
163
|
+
$('map-description').textContent = s ? `${s.id} · ${s.status}${routeState() ? ' · ' + routeState().route.label : ''}` : M.mapDescription;
|
|
164
|
+
if (Array.isArray(M.overviewEdges) && !state.context)
|
|
165
|
+
$('map-description').textContent += s ? ' · Architecture context retained' : ' · Primary relationships';
|
|
166
|
+
$('edge-context').textContent = state.context ? 'Fewer connections' : 'More connections';
|
|
167
|
+
$('edge-context').setAttribute('aria-pressed', String(state.context));
|
|
168
|
+
$('trace-position').textContent = s?.steps.length ? state.step >= 0 ? `Step ${state.step + 1} / ${s.steps.length}` : 'All steps shown' : '';
|
|
169
|
+
$('trace-navigation').hidden = !s?.steps.length;
|
|
170
|
+
const last = stop >= 0 ? stop : (s?.steps.length || 0) - 1;
|
|
171
|
+
$('trace-navigation').innerHTML = `<button id="previous" aria-label="Previous path step" ${state.step <= 0 ? 'disabled' : ''}>← Previous</button><button id="next" aria-label="Next path step" ${!s?.steps.length || state.step >= last ? 'disabled' : ''}>Next →</button><button id="full" title="Clear the step highlight; keep the selected route and architecture visible" ${state.step < 0 ? 'disabled' : ''}>Clear step</button>`;
|
|
172
|
+
$('trace').innerHTML = renderTrace(s);
|
|
173
|
+
renderMap(); renderInspector(); hash(); panel.scrollTop = scroll; restoreFocus(focus);
|
|
174
|
+
}
|
|
175
|
+
function renderInspector() {
|
|
176
|
+
const n = M.nodes.find(n => n.id === state.node), s = hypothesis();
|
|
177
|
+
$('inspector').classList.toggle('hidden', !n);
|
|
178
|
+
if (!n) return;
|
|
179
|
+
const role = sourceState().nodes.get(n.id);
|
|
180
|
+
$('inspector').innerHTML = `<button class="close" id="close-inspector">Close</button><div class="eyebrow">COMPONENT</div><h2>${esc(n.title)}</h2>${role ? `<p class="source-inspect" style="--source-fill:${role.fill};--source-ink:${role.ink}"><strong>${esc(role.label)}</strong>${role.items.map(item => `<br>${esc(item.label)}${item.authority ? `: ${esc(item.authority)}` : ''}`).join('')}</p>${refs([...new Set(role.items.flatMap(item => item.evidence))])}` : ''}<p>${esc(n.description)}</p>${s ? `<p><strong>${esc(s.id)} remains selected.</strong> ${esc(s.prerequisites)}</p>` : ''}${refs(n.evidence)}`;
|
|
181
|
+
}
|
|
182
|
+
function markerSvg(c, isBarrier, placement) {
|
|
183
|
+
const e = c.effect, marker = e?.marker;
|
|
184
|
+
if (!marker) return '';
|
|
185
|
+
const edge = M.edges.find(x => x.id === e.edge), split = ControlEffects.split(edge.points, marker.at);
|
|
186
|
+
const [px, py] = isBarrier && e.arrival ? edge.points.at(-1) : split.point, [nx, ny] = split.normal, color = controlColor(c);
|
|
187
|
+
const {x,y,w,h} = placement, label = placement.lines;
|
|
188
|
+
const center = [Math.max(x + 12, Math.min(px, x + w - 12)), Math.max(y, Math.min(py, y + h))];
|
|
189
|
+
return `<g data-control-inspect="${esc(c.id)}" data-barrier="${isBarrier}" data-arrival="${isBarrier && e.arrival === true}" tabindex="0" role="button" aria-label="Inspect ${esc(c.title)}: ${esc(ControlEffects.caption(c))}" style="cursor:pointer"><title>${esc(ControlEffects.caption(c))}. ${esc(e.reason)} ${esc(e.conditions)}</title><path d="M${esc(px)} ${esc(py)} L${esc(center[0])} ${esc(center[1])}" stroke="${color}" stroke-width="1.2" stroke-dasharray="4 4" fill="none"/>${isBarrier && !e.arrival ? `<path d="M${esc(px - nx * 14)} ${esc(py - ny * 14)} L${esc(px + nx * 14)} ${esc(py + ny * 14)}" stroke="${color}" stroke-width="5"/><circle cx="${esc(px)}" cy="${esc(py)}" r="9" fill="${color}" stroke="white" stroke-width="2"/><path d="M${esc(px - 4)} ${esc(py)} h8" stroke="white" stroke-width="2"/>` : `<circle cx="${esc(px)}" cy="${esc(py)}" r="7" fill="white" stroke="${color}" stroke-width="2"/>`}<rect data-caption="${esc(placement.id)}" data-caption-kind="control" data-layout-unresolved="${placement.conflicts>0}" x="${esc(x)}" y="${esc(y)}" width="${esc(w)}" height="${esc(h)}" rx="7" fill="${c.kind === 'proposed' ? '#f7efff' : '#eaf6ef'}" stroke="${color}" stroke-width="1.5" ${c.kind === 'proposed' ? 'stroke-dasharray="5 3"' : ''}/><text x="${esc(x + 12)}" y="${esc(y + 18)}" fill="${color}" font-size="10" font-weight="700">${esc(ControlEffects.basis(c))}</text>${label.map((t, i) => `<text x="${esc(x + 12)}" y="${esc(y + 40 + i * placement.lineHeight)}" fill="${color}" font-size="16" font-weight="600">${esc(t)}</text>`).join('')}</g>`;
|
|
190
|
+
}
|
|
191
|
+
function renderMap() {
|
|
192
|
+
const focus = focusTarget(), s = hypothesis(), {blocker, stop} = effectState();
|
|
193
|
+
const inspected = selectedControl();
|
|
194
|
+
const selected = inspected || (!blocker ? applicableControls().find(c => c.kind === 'existing' && c.effect?.marker) : null);
|
|
195
|
+
const routing = routeState();
|
|
196
|
+
const roles = sourceState();
|
|
197
|
+
const path = s?.steps || [], edgesOnPath = new Map(path.map((t, i) => [t.edge, i]));
|
|
198
|
+
const arrived = blocker?.effect.arrival === true;
|
|
199
|
+
const visibleSteps = s ? state.step < 0 ? path.filter((t, i) => stop < 0 || i <= stop) : [path[state.step]] : [];
|
|
200
|
+
const activeEdges = routing?.activeEdges || new Set([...visibleSteps.filter(Boolean).map(t => t.edge), ...(!path.length ? roles.relatedEdges : [])]);
|
|
201
|
+
const activeNodes = routing?.activeNodes || new Set([...visibleSteps.filter(Boolean).flatMap(t => t === path[stop] && !arrived ? [t.from] : [t.from, t.to]), ...(!path.length ? roles.relatedNodes : [])]);
|
|
202
|
+
const downstream = routing?.unreachedNodes || new Set(stop >= 0 ? path.slice(stop + (arrived ? 1 : 0)).map(t => t.to) : []);
|
|
203
|
+
const selectedEdges = new Set([...activeEdges, ...(routing?.unreachedEdges || []),
|
|
204
|
+
...path.map(t => t.edge), ...(selected?.edges || []),
|
|
205
|
+
...[selected?.effect?.edge, blocker?.effect?.edge].filter(Boolean)]);
|
|
206
|
+
const primaryEdges = new Set(M.overviewEdges || M.edges.map(e => e.id));
|
|
207
|
+
$('edge-context').hidden = !M.edges.some(e => !primaryEdges.has(e.id) && !selectedEdges.has(e.id));
|
|
208
|
+
const visibleEdges = M.edges.filter(e => state.context || primaryEdges.has(e.id) || selectedEdges.has(e.id));
|
|
209
|
+
const edgeStates = new Map(visibleEdges.map(e => {
|
|
210
|
+
const index=edgesOnPath.get(e.id), active=activeEdges.has(e.id);
|
|
211
|
+
const controlAssociated=!!(selected?.edges?.includes(e.id) || selected?.effect?.edge===e.id);
|
|
212
|
+
const stopped=!!blocker && !arrived && index===stop;
|
|
213
|
+
const unreached=routing ? routing.unreachedEdges.has(e.id) : stop>=0 && index>stop;
|
|
214
|
+
const highlighted=stopped || (!unreached && (active || controlAssociated));
|
|
215
|
+
const split=stopped ? ControlEffects.split(e.points,blocker.effect.marker.at) : null;
|
|
216
|
+
return [e.id,{index,active,controlAssociated,stopped,unreached,highlighted,split}];
|
|
217
|
+
}));
|
|
218
|
+
const markerControls = [...(blocker ? [{c:blocker,barrier:true}] : []), ...(selected?.effect?.marker && selected.id!==blocker?.id && (selected.effect.outcome!=='blocks' || selected.effect.traffic==='continues') ? [{c:selected,barrier:false}] : [])];
|
|
219
|
+
const captionItems = [
|
|
220
|
+
...markerControls.map(({c})=>({id:'control:'+c.id,kind:'control',priority:0,text:c.effect.label,size:16,weight:600,widths:[...new Set([c.effect.marker.w,Math.min(300,c.effect.marker.w+60),Math.max(160,c.effect.marker.w-40)].map(w=>Math.max(w,measureSvgText(ControlEffects.basis(c),10,700).w+24)-24))],cardWidth:c.effect.marker.w,anchor:[c.effect.marker.x+c.effect.marker.w/2,c.effect.marker.y+36]})),
|
|
221
|
+
...visibleEdges.filter(e=>e.label).map(e=>({id:'edge:'+e.id,kind:'edge',priority:edgeStates.get(e.id).highlighted?1:3,text:e.label,size:13,weight:400,widths:[180,140,220,100],edge:e,anchor:[e.labelX,e.labelY-4]})),
|
|
222
|
+
...(M.regions||[]).map(r=>({id:'region:'+r.id,kind:'region',priority:2,text:r.title,size:14,weight:600,widths:[...new Set([Math.max(40,r.w-24),Math.min(420,r.w+96),...[360,220,160,120,90].map(w=>Math.max(40,Math.min(w,r.w-24)))])],region:r,anchor:[r.x+12+Math.min(measureSvgText(r.title,14,600).w,r.w-24)/2,r.y+17]}))
|
|
223
|
+
];
|
|
224
|
+
const layoutEdges=visibleEdges.map(e=>{
|
|
225
|
+
const {highlighted,split}=edgeStates.get(e.id);
|
|
226
|
+
return {...e,layoutActive:highlighted,layoutActivePoints:split ? split.before : e.points};
|
|
227
|
+
});
|
|
228
|
+
const layoutKey=JSON.stringify([captionItems,M.nodes.map(n=>[n.x,n.y,n.w,n.h]),layoutEdges.map(e=>[e.id,e.points,e.layoutActive,e.layoutActivePoints]),M.canvas,typeof getComputedStyle==='function'?getComputedStyle($('map')).fontFamily:'Arial,sans-serif']);
|
|
229
|
+
let layout=mapLayoutCache.get(layoutKey);
|
|
230
|
+
if(!layout){
|
|
231
|
+
layout=SvgLayout.plan(captionItems,M.nodes,layoutEdges,M.canvas,measureSvgText);
|
|
232
|
+
if(mapLayoutCache.size>=64)mapLayoutCache.delete(mapLayoutCache.keys().next().value);
|
|
233
|
+
mapLayoutCache.set(layoutKey,layout);
|
|
234
|
+
}
|
|
235
|
+
const layoutIssues=[...layout.values()].filter(p=>p.conflicts>0).map(p=>({id:p.id,kind:p.kind,conflicts:p.conflicts}));
|
|
236
|
+
const heads=SvgLayout.heads(visibleEdges.filter(e=>{
|
|
237
|
+
const {stopped,unreached}=edgeStates.get(e.id);
|
|
238
|
+
return !stopped && !unreached;
|
|
239
|
+
}),e=>edgeStates.get(e.id).highlighted?1:0);
|
|
240
|
+
const arrowId = head => 'arrow-'+String(head.size).replace('.','_');
|
|
241
|
+
const markerSizes=[...new Set([...heads.values()].map(h=>h.size))];
|
|
242
|
+
const defs='<defs>'+markerSizes.map(size=>`<marker id="${arrowId({size})}" markerUnits="userSpaceOnUse" viewBox="0 0 8 6" refX="8" refY="3" markerWidth="${size}" markerHeight="8" preserveAspectRatio="none" orient="auto"><path d="M0 0L8 3L0 6Z" fill="context-stroke"/></marker>`).join('')+'</defs>';
|
|
243
|
+
const regions=(M.regions||[]).map(r=>`<rect x="${esc(r.x)}" y="${esc(r.y)}" width="${esc(r.w)}" height="${esc(r.h)}" rx="12" fill="#eef4f2" fill-opacity=".5" stroke="#afc8bf" stroke-dasharray="5 5"/>${captionSvg(layout.get('region:'+r.id),'#607e76',r)}`).join('');
|
|
244
|
+
// Visibility includes unreached paths; paint priority follows actual highlighting.
|
|
245
|
+
const mutedEdges = [], highlightedEdges = [];
|
|
246
|
+
visibleEdges.forEach(e => {
|
|
247
|
+
const {index,active,controlAssociated,stopped,unreached,highlighted,split} = edgeStates.get(e.id);
|
|
248
|
+
const color = controlAssociated && !stopped ? controlColor(selected) : active ? '#bc541e' : '#9db2bc';
|
|
249
|
+
let body;
|
|
250
|
+
if (stopped) {
|
|
251
|
+
mutedEdges.push(`<g data-edge-tail="${esc(e.id)}" data-path-state="unreached" aria-hidden="true"><polyline data-route-part="unreached" points="${pointsText(split.after)}" fill="none" stroke="#a8b6bd" stroke-width="1.6" stroke-dasharray="5 6" opacity=".5"/></g>`);
|
|
252
|
+
body = `<polyline data-route-part="before" points="${pointsText(split.before)}" fill="none" stroke="#bc541e" stroke-width="3" ${e.conditional ? 'stroke-dasharray="7 5"' : ''}/>`;
|
|
253
|
+
} else body = `<polyline points="${pointsText(SvgLayout.clean(e.points))}" fill="none" stroke="${color}" stroke-width="${active && state.step >= 0 && index === state.step ? 4.5 : active || controlAssociated ? 3 : 1.6}" ${e.conditional || unreached ? 'stroke-dasharray="6 5"' : ''} ${heads.get(e.id)?.visible ? `marker-end="url(#${arrowId(heads.get(e.id))})"` : ''}/>`;
|
|
254
|
+
const layer = highlighted ? highlightedEdges : mutedEdges;
|
|
255
|
+
layer.push(`<g data-edge="${esc(e.id)}" data-path-state="${stopped ? 'stopped' : unreached ? 'unreached' : active ? 'active' : 'context'}" opacity="${stopped ? 1 : unreached ? .35 : s && !active && !controlAssociated ? .65 : 1}">${body}<title>${esc(e.label || e.id)}: ${esc(e.from)} → ${esc(e.to)}${heads.get(e.id)?.shared>1 ? ' · shared destination arrow' : ''}</title>${captionSvg(layout.get('edge:'+e.id),active ? '#995122' : '#647e87')}</g>`);
|
|
256
|
+
});
|
|
257
|
+
const edges = `<g data-edge-layer="muted">${mutedEdges.join('')}</g><g data-edge-layer="highlighted">${highlightedEdges.join('')}</g>`;
|
|
258
|
+
const nodes = M.nodes.map(n => {
|
|
259
|
+
const a = activeNodes.has(n.id), co = selected?.nodes?.includes(n.id), muted = downstream.has(n.id) && !a;
|
|
260
|
+
const role = roles.nodes.get(n.id);
|
|
261
|
+
const focused = a && !!s?.focusNodes?.includes(n.id), transit = a && !focused;
|
|
262
|
+
const transport = transit && !!(routing || path.length);
|
|
263
|
+
const relation = focused ? 'focus' : transit ? (transport ? 'transit' : 'related') : 'context';
|
|
264
|
+
const stroke = transport ? '#b5c9cd' : state.node === n.id ? '#326d83' : co ? controlColor(selected) : focused ? '#bc541e' : '#b5c9cd';
|
|
265
|
+
const nums = path.flatMap((t, i) => t.to === n.id && (stop < 0 || i < stop) ? [i + 1] : []);
|
|
266
|
+
const roleText = role ? `, ${role.label}: ${role.items.map(item => item.label).join('; ')}` : '';
|
|
267
|
+
const badge = role?.kind === 'compromised-component' && role.items.every(item => item.basis === 'scenario-assumption') ? 'ASSUMED COMPROMISE' : role?.badge;
|
|
268
|
+
const owner = inspected?.nodes?.includes(n.id);
|
|
269
|
+
const ownerText = owner ? `, selected control locus: ${inspected.title}` : '';
|
|
270
|
+
const ownerBadge = owner ? `<g data-control-owner="${esc(inspected.id)}"><title>Selected control locus: ${esc(inspected.title)}</title><circle cx="${esc(n.x + n.w - 11)}" cy="${esc(n.y + n.h - 11)}" r="9" fill="${controlColor(inspected)}" stroke="white" stroke-width="1.5"/><text x="${esc(n.x + n.w - 11)}" y="${esc(n.y + n.h - 8)}" fill="white" text-anchor="middle" font-size="9" font-weight="700">C</text></g>` : '';
|
|
271
|
+
const nodeText=SvgLayout.nodeRows(n,role ? badge : null,measureSvgText);
|
|
272
|
+
if(nodeText.overflow)layoutIssues.push({id:'node:'+n.id,kind:'node-text',conflicts:1});
|
|
273
|
+
const textRows=nodeText.rows.map(row=>`<text data-node-text="${row.key}" x="${esc(n.x+10)}" y="${esc(row.y)}" fill="${row.key==='role'?role.ink:row.key==='title'?'#24414c':'#68818a'}" font-size="${row.size}" font-weight="${row.weight}">${esc(row.text)}</text>`).join('');
|
|
274
|
+
return `<g data-node="${esc(n.id)}" data-source-kind="${role?.source ? esc(role.kind) : ''}" data-participant-role="${role && !role.source ? esc(role.kind) : ''}" data-route-role="${relation}" data-path-state="${muted ? 'unreached' : a ? 'active' : 'context'}" tabindex="0" role="button" aria-label="Inspect ${esc(n.title)}${esc(roleText)}${esc(ownerText)}${transport ? ', transit on selected route' : transit ? ', related component; order unestablished' : focused ? ', scenario focus' : ''}" style="cursor:pointer" opacity="${muted ? .4 : s && !a && !co && !role?.source ? .7 : 1}"><title>${esc(n.description)}${esc(roleText)}${esc(ownerText)}${role?.source ? ' This role is the selected scenario’s starting condition, not a newly verified compromise.' : ''}${transport ? ' Traversed by the selected route; no weakness is attributed by this highlight.' : transit ? ' Related to the scenario; no traversal order or weakness is attributed by this highlight.' : ''}</title><rect x="${esc(n.x)}" y="${esc(n.y)}" width="${esc(n.w)}" height="${esc(n.h)}" rx="8" fill="${role?.fill || (a ? '#fff0d5' : n.kind === 'asset' ? '#edf4f6' : n.kind === 'actor' ? '#f2f6f4' : '#fff')}" stroke="${stroke}" stroke-width="${transport ? 1.4 : focused || co || state.node === n.id ? 2.4 : 1.4}" ${co && !transport && selected.kind === 'proposed' ? 'stroke-dasharray="5 3"' : ''}/>${textRows}${ownerBadge}${nums.length ? `<circle cx="${esc(n.x + n.w - 2)}" cy="${esc(n.y)}" r="11" fill="#bc541e" stroke="white" stroke-width="2"/><text x="${esc(n.x + n.w - 2)}" y="${esc(n.y + 4)}" text-anchor="middle" font-size="11" font-weight="700" fill="white">${nums.join(',')}</text>` : ''}</g>`;
|
|
275
|
+
}).join('');
|
|
276
|
+
const markers = markerControls.map(({c,barrier})=>markerSvg(c,barrier,layout.get('control:'+c.id))).join('');
|
|
277
|
+
$('map').setAttribute('data-layout-status',layoutIssues.length?'unresolved':'clear');
|
|
278
|
+
$('map').setAttribute('data-layout-issues',JSON.stringify(layoutIssues));
|
|
279
|
+
$('map').setAttribute('viewBox', `0 0 ${M.canvas.width} ${M.canvas.height}`);
|
|
280
|
+
$('map').setAttribute('aria-label', `${M.title}${s ? ' — ' + s.title : ''}${blocker ? ' — ' + ControlEffects.caption(blocker) : ''}`);
|
|
281
|
+
$('map').innerHTML = defs + `<g id="viewport">${regions}${edges}${nodes}${markers}</g>`;
|
|
282
|
+
const legendRoles = [...new Set([...roles.sources.map(source => source.kind), ...[...roles.nodes.values()].filter(role => !role.source).map(role => role.kind)])];
|
|
283
|
+
$('source-legend').innerHTML = legendRoles.map(kind => `<span class="source-key"><i style="background:${SourceRoles.palette[kind].fill};border-color:${SourceRoles.palette[kind].ink}"></i>${esc(SourceRoles.palette[kind].label)}</span>`).join('');
|
|
284
|
+
document.querySelector('.legend .risk').textContent = s && !routing && !path.length ? 'Scenario relationships' : 'Selected route';
|
|
285
|
+
document.querySelector('.legend .transit').textContent = s && !routing && !path.length ? 'Related component · normal outline' : 'On route · normal outline';
|
|
286
|
+
transform(); restoreFocus(focus);
|
|
287
|
+
}
|
|
288
|
+
function transform() { $('viewport').setAttribute('transform', `translate(${state.x} ${state.y}) scale(${state.zoom})`); }
|
|
289
|
+
function showEvidence(id) {
|
|
290
|
+
const e = evidence(id);
|
|
291
|
+
$('dialog-content').innerHTML = `<div class="eyebrow">SUPPLIED ASSESSMENT EVIDENCE</div><h2 id="evidence-title">${esc(e.label)}</h2><p>Exact quotation from the supplied assessment${e.startLine ? ` · lines ${esc(e.startLine)}–${esc(e.endLine)}` : ''}.</p><blockquote>${esc(e.quote)}</blockquote>${e.paths?.length ? `<h3>Paths cited by the assessment</h3><p>${e.paths.map(esc).join('<br>')}</p>` : ''}<p>The explorer preserves the assessment’s attribution. It adds no independent code or runtime verification.</p>`;
|
|
292
|
+
$('dialog').showModal();
|
|
293
|
+
}
|
|
294
|
+
document.addEventListener('click', event => {
|
|
295
|
+
const t = event.target.closest('button,[data-node],[data-control-inspect]');
|
|
296
|
+
if (!t) return;
|
|
297
|
+
if (t.hasAttribute('data-scenario')) {
|
|
298
|
+
state.scenario = t.dataset.scenario || null; state.route = null; state.source = null; state.step = -1; state.control = null; state.proposal = null; state.node = null; state.tab = 'path';
|
|
299
|
+
document.querySelector('.detail-panel').scrollTop = 0; render();
|
|
300
|
+
} else if (t.hasAttribute('data-step')) { state.step = Number(t.dataset.step); render(); }
|
|
301
|
+
else if (t.hasAttribute('data-panel')) { state.tab = t.dataset.panel; render(); }
|
|
302
|
+
else if (t.hasAttribute('data-control-inspect')) { state.control = t.dataset.controlInspect; state.tab = 'controls'; document.querySelector('.detail-panel').scrollTop = 0; render(); }
|
|
303
|
+
else if (t.hasAttribute('data-control')) {
|
|
304
|
+
const c = applicableControls().find(c => c.id === t.dataset.control);
|
|
305
|
+
if (!c) return;
|
|
306
|
+
if (c.kind === 'proposed') {
|
|
307
|
+
const turnOff = state.proposal === c.id;
|
|
308
|
+
state.proposal = turnOff ? null : c.id; state.control = turnOff ? null : c.id; state.step = -1;
|
|
309
|
+
} else state.control = state.control === c.id ? null : c.id;
|
|
310
|
+
render();
|
|
311
|
+
} else if (t.hasAttribute('data-node')) {
|
|
312
|
+
state.node = t.dataset.node; render(); $('inspector').scrollIntoView({block:'nearest'});
|
|
313
|
+
} else if (t.hasAttribute('data-evidence')) showEvidence(t.dataset.evidence);
|
|
314
|
+
else if (t.id === 'previous') { state.step--; render(); }
|
|
315
|
+
else if (t.id === 'next') { state.step++; render(); }
|
|
316
|
+
else if (t.id === 'full') { state.step = -1; state.tab = 'path'; render(); }
|
|
317
|
+
else if (t.id === 'edge-context') { state.context = !state.context; render(); }
|
|
318
|
+
else if (t.id === 'close-inspector') { state.node = null; render(); }
|
|
319
|
+
});
|
|
320
|
+
document.addEventListener('change', event => {
|
|
321
|
+
if (event.target.id === 'route-select') {
|
|
322
|
+
state.route = event.target.value; state.source = null; state.step = -1; state.node = null;
|
|
323
|
+
render();
|
|
324
|
+
} else if (event.target.id === 'source-select') {
|
|
325
|
+
state.source = event.target.value; state.node = null;
|
|
326
|
+
render();
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
$('map').addEventListener('keydown', e => {
|
|
330
|
+
if ((e.key === 'Enter' || e.key === ' ') && (e.target.dataset.node || e.target.dataset.controlInspect)) {
|
|
331
|
+
e.preventDefault(); e.target.dispatchEvent(new MouseEvent('click', {bubbles:true}));
|
|
332
|
+
}
|
|
333
|
+
});
|
|
334
|
+
$('close-dialog').onclick = () => $('dialog').close();
|
|
335
|
+
$('fit').onclick = () => { state.zoom = 1; state.x = state.y = 0; transform(); };
|
|
336
|
+
function zoom(k) { const z = Math.max(.5, Math.min(3, state.zoom * k)), r = z / state.zoom; state.x = M.canvas.width / 2 - (M.canvas.width / 2 - state.x) * r; state.y = M.canvas.height / 2 - (M.canvas.height / 2 - state.y) * r; state.zoom = z; transform(); }
|
|
337
|
+
$('in').onclick = () => zoom(1.2); $('out').onclick = () => zoom(1 / 1.2);
|
|
338
|
+
let drag = null;
|
|
339
|
+
$('map').onpointerdown = e => { if (e.target.closest('[data-node],[data-control-inspect]')) return; drag = {x:e.clientX, y:e.clientY, px:state.x, py:state.y}; $('map').setPointerCapture(e.pointerId); };
|
|
340
|
+
$('map').onpointermove = e => { if (!drag) return; const r = $('map').getBoundingClientRect(), scale = Math.min(r.width / M.canvas.width, r.height / M.canvas.height); state.x = drag.px + (e.clientX - drag.x) / scale; state.y = drag.py + (e.clientY - drag.y) / scale; transform(); };
|
|
341
|
+
$('map').onpointerup = $('map').onpointercancel = () => drag = null;
|
|
342
|
+
function download(data, type, name) { const a = document.createElement('a'), url = URL.createObjectURL(new Blob([data], {type})); a.href = url; a.download = name; a.click(); setTimeout(() => URL.revokeObjectURL(url), 1000); }
|
|
343
|
+
function exportMapSvg() {
|
|
344
|
+
const clone = $('map').cloneNode(true), s = hypothesis(), {blocker, controls} = effectState(), c = selectedControl() || blocker || controls.find(item => item.effect.outcome === 'blocks' && item.effect.traffic === 'continues');
|
|
345
|
+
clone.querySelector('#viewport').removeAttribute('transform');
|
|
346
|
+
const qualifiedCaption = control => `${ControlEffects.basis(control)} · ${ControlEffects.caption(control)}`;
|
|
347
|
+
const foot = [s ? `${s.id}: ${s.title} · ${s.status}` : M.title,
|
|
348
|
+
Array.isArray(M.overviewEdges) && !state.context ? 'Primary architecture connections remain visible; additional connections are available in the HTML.' : '',
|
|
349
|
+
s && !routeState() && !s.steps.length ? 'Amber fill: related components; order unestablished · orange outline: scenario focus · teal: existing control · purple: proposed control' : 'Amber fill: on selected route · normal outline: transit · orange outline: scenario focus · teal: existing control · purple: proposed control',
|
|
350
|
+
[...new Set([...sourceState().nodes.values()].map(role => role.kind))].length ? 'Role fills: ' + [...new Set([...sourceState().nodes.values()].map(role => role.kind))].map(kind => `${SourceRoles.palette[kind].colorName}: ${SourceRoles.palette[kind].label}`).join(' · ') : '',
|
|
351
|
+
sourceState().jointRequirement,
|
|
352
|
+
...sourceState().sources.map(source => `Threat source: ${source.label} (${SourceRoles.palette[source.kind].label}; ${SourceRoles.basis[source.basis]}${source.node === null ? '; not mapped on diagram' : ''}). Starting authority: ${source.authority}`),
|
|
353
|
+
routeState() ? `Documented flow: ${routeState().route.label}` : s && !s.steps.length ? (sourceState().selected?.relatedNodes ? 'Related components: supplied for selected starting position; order unestablished.' : 'Related components: shared scenario set; order unestablished.') : '',
|
|
354
|
+
s && applicableControls().some(item => item.effect?.outcome === 'blocks' && item.effect.traffic === 'continues') ? `Assessment context: ${s.summary}` : '',
|
|
355
|
+
selectedControl()?.nodes?.length ? `C badge: selected control locus for ${selectedControl().title}; not proof of enforcement.` : '',
|
|
356
|
+
blocker ? `${qualifiedCaption(blocker)}: ${blocker.effect.label}. ${blocker.effect.conditions} ${blocker.effect.residual}` : '',
|
|
357
|
+
...controls.filter(item => item.effect.outcome === 'blocks' && item.effect.traffic === 'continues').map(item => `${qualifiedCaption(item)}: ${item.effect.label}. ${item.effect.conditions} ${item.effect.residual}${blocker ? ' A separate barrier may stop the flow before this effect occurs.' : ''}`),
|
|
358
|
+
c && c.id !== blocker?.id && !controls.some(item => item.id === c.id && item.effect.traffic === 'continues') ? `${qualifiedCaption(c)}: ${c.title}${c.effect ? `. ${c.effect.conditions} ${c.effect.residual}` : ''}` : '',
|
|
359
|
+
!blocker && !c ? M.exportNote || 'Assessment evidence; no runtime validation implied.' : ''];
|
|
360
|
+
const lines = foot.filter(Boolean).flatMap(line => SvgLayout.lines(line, M.canvas.width - 40, 14, 400, measureSvgText));
|
|
361
|
+
const height = lines.length * 22 + 30;
|
|
362
|
+
clone.setAttribute('xmlns', 'http://www.w3.org/2000/svg'); clone.setAttribute('viewBox', `0 0 ${M.canvas.width} ${M.canvas.height + height}`); clone.setAttribute('width', M.canvas.width); clone.setAttribute('height', M.canvas.height + height); clone.setAttribute('style', `font-family:${typeof getComputedStyle === 'function' ? getComputedStyle($('map')).fontFamily : 'Arial,sans-serif'};background:#fbfcfb`);
|
|
363
|
+
clone.insertAdjacentHTML('beforeend', `<rect x="0" y="${esc(M.canvas.height)}" width="${esc(M.canvas.width)}" height="${height}" fill="#fbfcfb"/>${lines.map((line, i) => `<text x="20" y="${esc(M.canvas.height + 25 + i * 22)}" font-size="14" fill="#49616b">${esc(line)}</text>`).join('')}`);
|
|
364
|
+
return new XMLSerializer().serializeToString(clone);
|
|
365
|
+
}
|
|
366
|
+
$('svg-download').onclick = () => download(exportMapSvg(), 'image/svg+xml', 'threat-model-map.svg');
|
|
367
|
+
$('html-download').onclick = () => { const clone = document.documentElement.cloneNode(true); clone.querySelector('dialog').removeAttribute('open'); download('<!doctype html>\n' + clone.outerHTML, 'text/html', 'threat-model-explorer.html'); };
|
|
368
|
+
$('brand').innerHTML = esc(M.brand) + '<small>THREAT MODEL EXPLORER</small>';
|
|
369
|
+
$('title').textContent = M.title; $('subtitle').textContent = M.subtitle; $('snapshot').textContent = M.snapshotLabel;
|
|
370
|
+
$('assessment').textContent = assessment; $('metadata').innerHTML = (M.metadata || []).map(m => `<h3>${esc(m.label)}</h3><p>${esc(m.value)}</p>`).join('');
|
|
371
|
+
$('footer').textContent = M.footer; document.title = M.title;
|
|
372
|
+
window.addEventListener('hashchange', readHash); readHash();
|