Skip to content
SlateGitOrgPublic

About

Time-to-remediate from weekly scans that treats each fix date as interval-censored between scans (Turnbull), keeps open findings and regressions in, and reports SLA compliance as bounds.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

scangap

CI

scangap

scangap computes time to remediate and SLA compliance from periodic vulnerability scans without pretending that a fix happened on the day a scan noticed it. Each fix date is only known to lie between the last scan that still saw the finding and the first authenticated scan that did not, so scangap treats it as an interval-censored observation, keeps open findings in as right-censored, merges regressions back into the episode they belong to, and estimates the fix-time distribution with the Turnbull NPMLE. SLA compliance comes out as bounds, not a single false-precision number. The scan data is synthetic and comes from a seeded generator that also writes the true fix times, so every figure can be checked against the truth.

The problem

A regional bank reports mean time to remediate (MTTR) and SLA compliance (critical within 15 days, high within 30, medium within 90) to its audit committee. The figures come from weekly authenticated scans and are computed as "first scan without the finding minus first detection" over closed findings only. That recipe has four faults:

  • Findings that are still open are dropped, so long-lived findings vanish from the mean and compliance looks better than it is.
  • Every fix is dated at the scan that noticed it, which adds up to a week of scan lag to each one.
  • A host that missed a scan or failed authentication looks like a host where the finding was fixed.
  • A finding that comes back after a rollback is counted as two fast fixes.

The reported MTTR is wrong in a direction nobody can state. scangap rebuilds the same numbers from the same scans with the censoring handled explicitly and shows the naive and midpoint figures next to the estimate.

How it works

flowchart LR
    A["Weekly scan snapshots<br/>scans.csv + observations.csv"] --> B["Per scan and finding:<br/>present / absent / unknown"]
    B --> C["Interval-censored episodes (L, R]<br/>regressions merged, open ones right-censored"]
    C --> D["Turnbull EM<br/>innermost intervals, NPMLE masses"]
    D --> E["SLA compliance bounds<br/>median and RMST bounds"]
    C --> F["Asset-level cluster bootstrap<br/>unit vs rest of fleet"]
    G["Generator truth.json<br/>true fix times, injected events"] -. checks .-> C
    G -. checks .-> E
    G -. checks .-> F
Loading
  1. Observations. A scan of an asset either reports the finding (present), is authenticated and does not report it (absent), or tells us nothing (unknown: no scan that week, or auth_ok is false).
  2. Episodes (scangap.episodes). Findings are keyed by (asset, vuln, package). An episode closes at the first authenticated absence, so the fix time since first detection lies in (L, R], where L is the last present scan and R the first authenticated absence. A finding present again within --reopen-days (default 90) of its closure voids that closure and the episode continues. Episodes open at the end of the window are right-censored (L, inf). Findings already present at the asset's first authenticated scan are excluded from estimation, because their age is unknown (length-biased sampling), and are counted separately.
  3. Turnbull NPMLE (scangap.turnbull). The innermost intervals of the (L, R] endpoints carry all the mass; a self-consistency EM on the distinct (L, R) pairs with multiplicities finds the masses, stopping when the largest mass change is below 1e-10 (at most 20,000 iterations). Inside an innermost interval the NPMLE is not unique, so F(t) is reported as F_low(t), the mass of intervals wholly at or below t, and F_high(t), the mass of intervals starting below t. The restricted mean time to remediate up to 180 days (RMST180) is bounded by putting each interval's mass at its right end (conservative) or left end (optimistic).
  4. Comparators on the same episodes: naive (closed episodes only, fix time = R) and midpoint (closed only, (L + R) / 2).
  5. Comparison across units (scangap.compare). A cluster bootstrap resamples assets, because fixes on one host are correlated, and gives a percentile interval at level 1 - 0.05/k (Bonferroni over k units) for each unit's RMST90 difference from the rest of the fleet. By default this is a step-down procedure (see the design notes); --no-stepdown gives the plain difference from the rest.

Quick start

python -m venv .venv && . .venv/bin/activate
pip install -e ".[dev]"

scangap generate --seed 11 --out data/              # assets.csv, scans.csv, observations.csv, truth.json
scangap episodes --data data/                       # episode counts per severity
scangap sla --by severity --data data/ --truth data/truth.json
scangap sla --by severity --cadence weekly --data data/ --truth data/truth.json
scangap compare --data data/ --by business_unit --severity high --metric rmst90 --boot 200 --seed 5
scangap audit --data data/ --limit 3
pytest -q

sla, compare, audit and episodes take --format json for machine-readable output. All dates are calendar dates from the CSVs; nothing reads the clock.

Example output

All of this is real output of the commands above on seed 11. The data is synthetic: 400 assets in 5 business units (20% scanned daily by an agent, 80% weekly on a per-asset weekday), 26 weeks ending 2026-10-31. True fix times from first detection are Weibull (shape 1.3, median 12 days) for critical, Weibull (shape 1.1, median 28 days) for high and lognormal (median 60 days, sigma 0.8) for medium; payments-core high-severity fixes take twice as long. Injected: 3% of weekly scans missing, 5% of scans with auth_ok = false, one asset whose credentials fail for four consecutive weeks, 40 regressions where a fixed finding returns 7 to 28 days later, and findings already present at the first scan. New findings do not arrive uniformly: the arrival density decays over the window (the time remaining until the end is Beta(1.9, 1) distributed, so arrivals are front-loaded), which is what puts about 15% of episodes still open at the end; uniform arrivals with these laws leave about 28% open.

$ scangap generate --seed 11 --out data/
wrote data: 400 assets, 22659 scans, 81822 observations, 6093 episodes (952 open), 307 already present at the first scan, 40 regressions
$ scangap episodes --data data/
Reopen window: 90 days

| severity | episodes | closed | open | prevalent excluded | voided closures |
|---|---|---|---|---|---|
| critical | 1479 | 1450 | 29 | 88 | 4 |
| high | 2473 | 2137 | 336 | 114 | 16 |
| medium | 2141 | 1554 | 587 | 105 | 20 |

SLA compliance and time to remediate, with the truth from truth.json beside the naive, midpoint and Turnbull figures:

$ scangap sla --by severity --data data/ --truth data/truth.json
### SLA compliance (share of findings fixed within the SLA)

| severity | SLA days | episodes | open | prevalent excluded | naive | midpoint | Turnbull bounds | truth |
|---|---|---|---|---|---|---|---|---|
| critical | 15 | 1479 | 29 | 88 | 59.2% | 62.1% | 61.8% | 60.4% |
| high | 30 | 2473 | 336 | 114 | 51.5% | 53.0% | 48.2% | 48.3% |
| medium | 90 | 2141 | 587 | 105 | 84.7% | 87.8% | 71.2% | 69.4% |

### Time to remediate (days since first detection)

| severity | naive mean | midpoint mean | median bounds | RMST180 bounds | truth RMST180 |
|---|---|---|---|---|---|
| critical | 17.4 | 14.1 | 11.0 - 12.0 | 13.7 - 14.7 | 14.7 |
| high | 38.3 | 35.0 | 31.0 - 32.0 | 43.6 - 44.9 | 43.7 |
| medium | 55.1 | 51.7 | 56.0 - 57.0 | 72.1 - 73.0 | 74.5 |

Because 20% of the fleet is scanned daily, every integer day is an interval endpoint and the Turnbull bounds at an integer SLA collapse to one value (scangap prints a single figure when low equals high). On the weekly-only assets the data really cannot say where inside a week a fix happened, and the bounds open up; the truth stays inside them:

$ scangap sla --by severity --cadence weekly --data data/ --truth data/truth.json
### SLA compliance (share of findings fixed within the SLA)

| severity | SLA days | episodes | open | prevalent excluded | naive | midpoint | Turnbull bounds | truth |
|---|---|---|---|---|---|---|---|---|
| critical | 15 | 1161 | 22 | 74 | 58.6% | 62.2% | 60.4% - 78.0% | 60.4% |
| high | 30 | 1992 | 289 | 87 | 51.8% | 53.7% | 46.3% - 54.2% | 48.3% |
| medium | 90 | 1698 | 472 | 82 | 84.6% | 88.5% | 68.6% - 72.3% | 69.4% |

### Time to remediate (days since first detection)

| severity | naive mean | midpoint mean | median bounds | RMST180 bounds | truth RMST180 |
|---|---|---|---|---|---|
| critical | 18.1 | 14.1 | 7.0 - 14.0 | 10.7 - 17.7 | 14.7 |
| high | 38.1 | 34.0 | 28.0 - 35.0 | 40.4 - 47.5 | 43.7 |
| medium | 55.8 | 51.6 | 56.0 - 63.0 | 67.9 - 75.4 | 74.5 |

The naive column is the audit-committee recipe as far as scangap can reproduce it from episodes: closed findings only, fix dated at the first scan without the finding. It is computed on the episodes after regressions are merged and prevalent findings excluded, so it shows the first two faults above (open findings dropped, scan lag) but not the regression double count or the prevalent-finding bias. It overstates critical MTTR (17.4 days against a true 14.7) through scan lag and flatters medium compliance (84.7% against a true 69.4%) because open findings are dropped.

Which business unit is slower, payments-core having been given twice the high-severity fix time:

$ scangap compare --data data/ --by business_unit --severity high --metric rmst90 --boot 200 --seed 5
| business_unit | assets | episodes | RMST90 | rest | difference | 99.00% interval | flag |
|---|---|---|---|---|---|---|---|
| corporate-it | 80 | 507 | 35.0 | 35.0 (w/o payments-core) | -0.1 | [-3.3, +3.9] |  |
| lending | 80 | 559 | 34.7 | 35.1 (w/o payments-core) | -0.4 | [-4.0, +3.6] |  |
| payments-core | 80 | 462 | 57.6 | 35.0 | +22.6 | [+18.7, +27.1] | FLAG |
| retail-banking | 120 | 753 | 35.5 | 34.8 (w/o payments-core) | +0.7 | [-2.1, +3.3] |  |
| treasury | 40 | 192 | 34.3 | 35.1 (w/o payments-core) | -0.8 | [-6.1, +4.1] |  |

high severity, 200 asset-cluster bootstrap replicates (seed 5), Bonferroni over k=5 groups. Step-down: units after the first round are compared with a reference that omits the flagged unit(s) and keep the per-test level; that round is not alpha-corrected for the sequence, so the family-wise guarantee does not hold.

An excerpt of the audit (the full lists come with --limit or --format json):

$ scangap audit --data data/ --limit 3
### Voided closures: findings back within 90 days (40)

| asset | vuln | package | last present | closed | present again | days |
|---|---|---|---|---|---|---|
| A0369 | SYN-2026-0095 | openssh | 2026-05-18 | 2026-05-19 | 2026-06-07 | 19 |
| A0258 | SYN-2026-0111 | openjdk | 2026-05-25 | 2026-05-26 | 2026-06-09 | 14 |
| A0143 | SYN-2026-0204 | python3 | 2026-05-28 | 2026-06-04 | 2026-06-18 | 14 |

... 37 more

### Deferred closures: an unauthenticated scan sat between last present and first absent (542)

| asset | vuln | package | last present | closed | unauthenticated scans | closure |
|---|---|---|---|---|---|---|
| A0187 | SYN-2026-0186 | samba | 2026-05-12 | 2026-05-14 | 2026-05-13 | kept |
| A0250 | SYN-2026-0097 | bind9 | 2026-05-15 | 2026-05-17 | 2026-05-16 | kept |
| A0149 | SYN-2026-0280 | python3 | 2026-05-04 | 2026-05-18 | 2026-05-11 | kept |

... 539 more

### Assets with more than 21 days between authenticated scans (4)

| asset | from | to | days |
|---|---|---|---|
| A0023 | 2026-07-03 | 2026-08-07 | 35 |
| A0251 | 2026-08-10 | 2026-09-07 | 28 |
| A0131 | 2026-08-22 | 2026-09-19 | 28 |

... 1 more

Design decisions

  • Bounds instead of a curve. The NPMLE of interval-censored data is only determined up to the innermost intervals, so reporting one F(t) would claim precision the scans do not carry. A median bound printed as 56.0 - open-ended means the median lies beyond the last observed fix (too many findings still open to say); it is not missing data. The cost is a wider statement for fleets scanned weekly; the benefit is that the truth lies inside the bounds in the tests (within a 0.04 tolerance for F at the SLA, and within 3 days for RMST180).
  • Open findings stay in; prevalent findings go out. Dropping open findings biases the mean down; keeping findings that were already present at the first scan biases it up (long-lived findings are more likely to be present at any given time). Right-censoring handles the first, exclusion the second, and the excluded count is printed per group.
  • A fixed finding that returns inside 90 days is one episode. A rollback is not two fast fixes. The window is an option (--reopen-days); with 0, each of the 40 injected regressions becomes two episodes, and a test asserts the resulting count. The 90 days is a policy choice, not an estimated quantity.
  • Unauthenticated scans are unknown, not absent. A closure waits for the first authenticated scan without the finding, so a four-week credential outage defers the fix of everything on that host to the first good scan afterwards. audit lists those deferred closures and the assets with more than 21 days between authenticated scans.
  • The bootstrap resamples assets, within their unit, and steps down. One patch run fixes many findings on a host, so findings are not independent. A unit that is much slower also drags the "rest of the fleet" average up and makes every other unit look fast; without correction all five units are flagged on this data, four of them in the wrong direction (--no-stepdown shows it, and a test checks that the others get flagged). By default the unit with the largest flagged difference is removed from the reference and the others are tested again against what is left. The interval keeps the per-test Bonferroni level 1 - 0.05/k for the original k units, but the second round is not alpha-corrected for the sequence of tests: the family-wise guarantee holds for the first round and for --no-stepdown, not for the step-down result. The four unflagged rows then report a different reference (the fleet without the flagged unit, shown as w/o ...).
  • compare works with one RMST number per fit. Each unit's RMST, the rest-of-fleet RMST and every difference use the midpoint of the Turnbull RMST bounds, because a percentile interval needs a single value per replicate; sla reports the bounds. The bootstrap fits stop at 1e-7 and 5,000 iterations, and compare reports how many EM fits hit the iteration cap (non_converged_fits in JSON, a warning in Markdown); sla warns in Markdown, and shows converged in JSON, when a fit did not converge.
  • The bootstrap stops EM at 1e-7, the headline fit at 1e-10. The bootstrap refits a few thousand models; the looser tolerance keeps compare at seconds while the headline fit follows the exact stopping rule.
  • Assumption. Scan timing is independent of the fix time. The generator satisfies it; a real fleet where scans are triggered by patching would not.

Testing

pytest -q

83 tests, under a minute. They cover hand-computed Turnbull fixtures (including the Kaplan-Meier case with exact and right-censored data), the episode state machine on small scan calendars, the generator's determinism and injected events, and recovery of the generator's truth: episode counts, right-censored counts, the 40 voided closures, deferred closures and every episode's (L, R] equal to the truth file; the true F at each SLA inside the Turnbull bounds; the true RMST180 inside its bounds widened by 3 days; the naive mean overstating critical by more than 2 days and understating medium by more than 10; compare flagging payments-core only, and identical output for the same seed; the credential outage deferring closures to the next authenticated scan; and the CLI output in both formats.

Project layout

src/scangap/
  cli.py          Typer commands: generate, episodes, sla, compare, audit
  generator.py    seeded fleet generator and truth.json
  laws.py         true fix-time laws (Weibull, lognormal) and their CDFs
  constants.py    SLA days, laws, business units, defaults
  dataio.py       CSV loading and validation
  episodes.py     present/absent/unknown walk, episodes, voided and deferred closures
  turnbull.py     innermost intervals, EM, F bounds, RMST and median bounds
  comparators.py  naive and midpoint figures
  sla.py          per-group SLA and time-to-remediate summaries
  compare.py      asset-cluster bootstrap across business units
  audit.py        voided closures, deferred closures, coverage gaps
  report.py       Markdown and JSON rendering
tests/            pytest suite
.github/workflows/ci.yml

License

MIT, see LICENSE.

About

Time-to-remediate from weekly scans that treats each fix date as interval-censored between scans (Turnbull), keeps open findings and regressions in, and reports SLA compliance as bounds.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages