Skip to content

feat: PTSZI graph risk model (W formula)#1

Merged
velvetway merged 15 commits into
mainfrom
feat/graph-risk-model
Apr 17, 2026
Merged

feat: PTSZI graph risk model (W formula)#1
velvetway merged 15 commits into
mainfrom
feat/graph-risk-model

Conversation

@velvetway
Copy link
Copy Markdown
Owner

Summary

Replaces the ad-hoc Impact × Likelihood heuristic with a formal PTSZI model:

S (источник) → ST (угроза) → VL (уязвимое звено) → DA (деструктивное действие)
                                    ▲
                                   └─ controls (asset_controls)

Formula: W_i = (Q^threat + q^severity + (1 - Q^reaction)) / 3 · Z, где Z ∈ {0.5, 0.75, 1.0} — коэффициент контура.

What changed

  • DB (migrations 007-010): 2 dictionary tables (threat_sources, destructive_actions), 4 junction tables, 2 new columns on threats (q_threat, q_severity) + heuristic seed edges.
  • Go domain: ThreatSource, DestructiveAction, AttackPath, VLNode, ControlCoverage.
  • Repositories: ThreatSourceRepository, DestructiveActionRepository, RiskGraphRepository with a CTE-based JSON-aggregation SQL for VL coverage.
  • Service: new Service.AssembleAttackPath, ListThreatSources, ListDestructiveActions. Overview rewritten to use W while keeping legacy impact/likelihood/score for back-compat with the matrix UI.
  • Calculator v2: CalculateW, LevelFromW, QReactionFromVLs, ZFromAsset with 14 new unit tests, all green; no regression in 15 existing risk tests.
  • API (3 new):
    • GET /api/risk/graph/:asset_id/:threat_id
    • GET /api/threat-sources
    • GET /api/destructive-actions
  • Frontend: d3-sankey component + RiskGraphPage with 5-stat breakdown (W, Q^th, q^sev, Q^re, Z). Click any dot on the risk matrix → opens the attack path.
  • Docs: docs/risk-model.md with full formula explanation, linked from README.

Test plan

  • go test ./internal/service/... ./internal/domain/... -count=1 — all pass
  • CI=true npm run build in frontend/ — compiles clean
  • curl /api/threat-sources returns 4 rows
  • curl /api/destructive-actions returns 7 rows
  • curl /api/risk/graph/1/1 returns JSON with w, q_threat, level
  • Risk matrix click-through opens Sankey graph
  • W formula components match spec: (Q^threat + q + (1-Q^reaction))/3 * Z

🤖 Generated with Claude Code

velvetway and others added 15 commits April 17, 2026 18:25
Implements W = (Q_threat + q_severity + (1 - Q_reaction)) / 3 * Z
alongside the existing Impact x Likelihood calculator. Introduces:
  - CalculateW: clamped formula over Q/Z inputs
  - LevelFromW: thresholds 0.25/0.50/0.75 -> low/medium/high/critical
  - QReactionFromVLs: share of VLs covered by >=1 non-zero control
  - ZFromAsset: contour coefficient (isolated 0.5, prod 1.0, stage 0.75,
    otherwise 0.5)

14 new unit tests, full risk suite green (29/29). Existing calculator.go
is untouched; the service switches to CalculateW in task 8.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@velvetway velvetway merged commit a92f2c5 into main Apr 17, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant