feat: PTSZI graph risk model (W formula)#1
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces the ad-hoc
Impact × Likelihoodheuristic with a formal PTSZI model:Formula:
W_i = (Q^threat + q^severity + (1 - Q^reaction)) / 3 · Z, гдеZ ∈ {0.5, 0.75, 1.0}— коэффициент контура.What changed
threat_sources,destructive_actions), 4 junction tables, 2 new columns onthreats(q_threat,q_severity) + heuristic seed edges.ThreatSource,DestructiveAction,AttackPath,VLNode,ControlCoverage.ThreatSourceRepository,DestructiveActionRepository,RiskGraphRepositorywith a CTE-based JSON-aggregation SQL for VL coverage.Service.AssembleAttackPath,ListThreatSources,ListDestructiveActions.Overviewrewritten to use W while keeping legacyimpact/likelihood/scorefor back-compat with the matrix UI.CalculateW,LevelFromW,QReactionFromVLs,ZFromAssetwith 14 new unit tests, all green; no regression in 15 existing risk tests.GET /api/risk/graph/:asset_id/:threat_idGET /api/threat-sourcesGET /api/destructive-actionsd3-sankeycomponent +RiskGraphPagewith 5-stat breakdown (W, Q^th, q^sev, Q^re, Z). Click any dot on the risk matrix → opens the attack path.docs/risk-model.mdwith full formula explanation, linked from README.Test plan
go test ./internal/service/... ./internal/domain/... -count=1— all passCI=true npm run buildinfrontend/— compiles cleancurl /api/threat-sourcesreturns 4 rowscurl /api/destructive-actionsreturns 7 rowscurl /api/risk/graph/1/1returns JSON withw,q_threat,level(Q^threat + q + (1-Q^reaction))/3 * Z🤖 Generated with Claude Code