1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
//! # Security and Vulnerability Management Metrics
//!
//! Security debt is measured the same way technical debt is measured (see
//! [`crate::technical_debt`]): by severity and by how long it is carried.
//! For every discovered vulnerability, the primary metric is time from
//! discovery to genuine remediation — a deployed fix, not a closed ticket or
//! an unmerged patch — tracked against an explicit target that varies by
//! severity, commonly days for critical issues and weeks for lower-severity
//! ones.
//!
//! ## Formula
//!
//! ```text
//! Time to remediate = remediated at − discovered at
//! Within target when time to remediate ≤ remediation target for severity
//! ```
//!
//! ## Why it matters
//!
//! Using a standardized external scoring system, such as CVSS, as the
//! primary basis for severity classification resists the same lenient-drift
//! risk that inconsistent, purely internal judgement invites elsewhere in
//! this book: an externally anchored score is harder to quietly redefine
//! downward than a purely internal one. Building a genuinely non-punitive
//! disclosure culture matters just as much as the metric itself — an
//! engineer or researcher who reports a vulnerability is providing a
//! valuable service, and punishing disclosure reliably drives real risk
//! underground rather than into a managed remediation process.
//!
//! ## Example
//!
//! ```rust
//! use software_engineering::vulnerability_management::{
//! VulnerabilitySeverity, remediation_target_days, time_to_remediate_days,
//! is_remediated_within_target,
//! };
//!
//! // A critical vulnerability discovered on day 100, remediated on day 105.
//! let elapsed = time_to_remediate_days(100.0, 105.0);
//! assert_eq!(elapsed, 5.0);
//! assert_eq!(remediation_target_days(VulnerabilitySeverity::Critical), 7.0);
//! assert!(is_remediated_within_target(VulnerabilitySeverity::Critical, elapsed));
//!
//! // The same 5 days would miss no severity's target, but 10 days misses
//! // Critical's 7-day target.
//! assert!(!is_remediated_within_target(VulnerabilitySeverity::Critical, 10.0));
//! ```
//!
//! ## Pitfalls
//!
//! - **Measuring remediation to ticket-closed rather than genuinely
//! deployed** — overstates how quickly real risk was actually reduced.
//! - **Tracking a raw, unweighted vulnerability count** instead of
//! time-to-remediate by severity — hides whether the highest-risk items
//! are being fixed fastest.
//! - **Relying entirely on internal, inconsistent severity judgement**
//! instead of a standardized external scale like CVSS where one is
//! available.
//! - **Punishing vulnerability disclosure**, internally or externally —
//! discourages exactly the reporting the entire management system depends
//! on.
//! - **Letting accepted-risk vulnerabilities disappear** into an invisible
//! status instead of the same visible, quantified technical debt backlog
//! used elsewhere.
//!
//! ## Sources
//!
//! - Chapter 6.4, Security and vulnerability management metrics.
//! - FIRST.org, *Common Vulnerability Scoring System (CVSS)*.
//!
//! Topic doc: software-engineering-metrics/locales/en-001/chapters/06-04-security-and-vulnerability-management-metrics.md
/// A vulnerability severity level, following a CVSS-like scale.
/// A common, documented remediation-time target for a severity level, in
/// days.
///
/// `Critical = 7.0`, `High = 30.0`, `Medium = 90.0`, `Low = 180.0` — days for
/// critical issues, weeks-equivalent for lower severities, per the chapter's
/// guidance. These are a common industry convention, not a universal
/// standard; adapt them to your own risk tolerance and, where applicable,
/// contractual or regulatory requirements.
///
/// # Arguments
///
/// * `severity` — the vulnerability's severity level.
///
/// # Returns
///
/// The target number of days to remediate.
///
/// # Examples
///
/// ```rust
/// use software_engineering::vulnerability_management::{
/// VulnerabilitySeverity, remediation_target_days,
/// };
///
/// assert_eq!(remediation_target_days(VulnerabilitySeverity::Critical), 7.0);
/// assert_eq!(remediation_target_days(VulnerabilitySeverity::Low), 180.0);
/// ```
/// Time from discovery to genuine remediation — a deployed fix, not a
/// closed ticket or an unmerged patch.
///
/// `remediated_at_days − discovered_at_days`.
///
/// # Arguments
///
/// * `discovered_at_days` — the day the vulnerability was discovered, on any
/// consistent scale.
/// * `remediated_at_days` — the day the fix was genuinely deployed, on the
/// same scale.
///
/// # Returns
///
/// The elapsed remediation time, in days.
///
/// # Examples
///
/// ```rust
/// use software_engineering::vulnerability_management::time_to_remediate_days;
///
/// assert_eq!(time_to_remediate_days(100.0, 105.0), 5.0);
/// ```
/// Whether an actual remediation time met the target for its severity.
///
/// `actual_days_to_remediate ≤ `[`remediation_target_days`]`(severity)`.
///
/// # Arguments
///
/// * `severity` — the vulnerability's severity level.
/// * `actual_days_to_remediate` — the actual elapsed remediation time, in
/// days (typically from [`time_to_remediate_days`]).
///
/// # Returns
///
/// `true` if the actual time is at or under the target, `false` otherwise.
///
/// # Examples
///
/// ```rust
/// use software_engineering::vulnerability_management::{
/// VulnerabilitySeverity, is_remediated_within_target,
/// };
///
/// assert!(is_remediated_within_target(VulnerabilitySeverity::Critical, 5.0));
/// assert!(!is_remediated_within_target(VulnerabilitySeverity::Critical, 10.0));
/// ```