Commit 605fd5c
committed
fix(atr): highest-severity primary finding, and keep scanning off the event loop
Two of @lan17's review points.
max_severity reported findings[0], i.e. whichever rule happened to come
first in rules-file order. With a high-severity rule ahead of a critical
credential rule it reported 'high', exactly as described in review. It
now picks the primary finding by severity_rank, and the legacy
single-match mirror fields describe that same finding, so a caller
reading only those sees the worst thing detected. Ordering is stable:
max keeps the first of equal ranks, and the findings list stays in match
order.
Rule matching is CPU-bound synchronous regex work that ran inline in an
async evaluate(). Nothing awaited during the scan, so the engine's
asyncio.wait_for could not fire until the scan had already completed --
the timeout was not real. It now runs via asyncio.to_thread.
One consequence worth stating plainly rather than leaving to be
discovered: the per-condition budget is enforced with SIGALRM, which only
works on the main thread. _wall_clock_search already detects this and
falls back to a soft post-hoc check off the main thread, so moving the
scan into a worker converts that hard interrupt into a warning. The event
loop is no longer held, but a pathological pattern is no longer cut off
mid-search either. Raised in the PR thread for a decision rather than
resolved unilaterally.
31 passed.1 parent 7506855 commit 605fd5c
1 file changed
Lines changed: 16 additions & 2 deletions
Lines changed: 16 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| |||
316 | 317 | | |
317 | 318 | | |
318 | 319 | | |
319 | | - | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
320 | 327 | | |
321 | 328 | | |
322 | 329 | | |
| |||
349 | 356 | | |
350 | 357 | | |
351 | 358 | | |
352 | | - | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
353 | 364 | | |
354 | 365 | | |
355 | 366 | | |
356 | 367 | | |
357 | 368 | | |
358 | 369 | | |
359 | 370 | | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
360 | 374 | | |
361 | 375 | | |
362 | 376 | | |
| |||
0 commit comments