Skip to content
tritsystemPublic

About

A two-stage assay for bugs in Python/C code: cheap AST nomination, then a dynamic confirm() probe. 40 detectors, real merged findings across kornia/celery/spikingjelly/ultralytics/DeepSpeed/peft/timm/x-transformers.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Reagent

A two-stage assay for bugs in Python (and some C) code, with detectors tuned for ML/scientific-Python but most of them general-purpose.

  • check() adds the cheap reagent -- an AST pattern -> a nomination.
  • confirm() runs the reaction -- import the module, construct an instance, feed domain-aware inputs, probe -> confirmed / not-confirmed / unreachable.

40 detectors: 32 Python (tNN_* directories, t01-t33; six of them -- mutable defaults, swallowed errors, iterator-state leaks, invariant drift, prompt injection, plus the whole web-security tranche T25-T33 -- have nothing to do with ML and run on any Python codebase) + 8 C (cNN_*, memory-safety classes: use-after-free, format string, TOCTOU, alloc-size overflow, ...). Each has a PRE_REGISTRATION.md, a bench.py with synthetic ground truth (recall 1/1, FP 0), and a FINDINGS.md with honest limits. Shared plumbing in bftools/ (discover.py loads a detector by directory; profile.py decides which detectors apply to a given target; gate.py is the learned confirm() gate). Discipline: the gbranaa4-hue method -- pre-register, matched baselines, honest negatives reported like positives, reproduce red/green. NIT severity = "reported for transparency, explicitly not a candidate".

Every detector here needs a NAMED bug shape to look for. For the two ways this toolset finds bugs it doesn't already have a name for -- property checks (bftools/pressure.py, bftools/invariants.py) and minting a new detector via a philosophical distinction -- see METHOD.md.

Track record (real, merged or filed, not a benchmark score)

kornia #4210 #4299 #4303 #4319 #4337 (6 MERGED), celery #10571 (MERGED), spikingjelly #743 #744 (MERGED), ultralytics #26075 (MERGED), DeepSpeed #8565, huggingface/peft #3783, huggingface/pytorch-image-models #2794, lucidrains/x-transformers #362. Reported honestly either way -- most sweeps against a fresh set of repos come back with zero new genuine findings after triage; that's the false-positive rate being driven down, not a failure to look. (A private security-disclosure ledger is kept separately and is not part of this repo -- reagent sec findings are held for coordinated disclosure, never published here before a vendor fix ships.)

Requirements and install

Python 3.10+. No hard dependencies for the core tool -- reagent selftest, static check()-only scans, and every general-purpose detector (mutable defaults, swallowed errors, the whole web-security tranche, ...) run on the standard library alone. This is verified, not assumed: reagent selftest passes ALL GREEN even with torch forcibly blocked from importing.

torch/numpy are only needed for two things: confirm()ing a finding against a real PyTorch codebase (confirm() imports the target's own modules in-process, so if the target imports torch, reagent's environment needs it too), and the learned --gate (hunt/sweep's optional flag).

git clone https://github.com/tritsystem/reagent
cd reagent
pip install -e .            # core tool only
pip install -e ".[ml]"      # + torch/numpy, for confirm() against real ML repos and --gate

This installs the reagent command. Without installing, python cli.py <cmd> works identically from inside the cloned directory.

Quickstart

Start with the self-test -- it validates every detector against its own synthetic fixtures before you point it at anything real:

$ reagent selftest
loaded 32 scaffolds
...
ALL GREEN

Now point hunt at a real target. hunt (unlike scan, see below) is profile-aware: it looks at the repo's imports and only runs the detectors that apply (bftools/profile.py's pick()), so a plain Flask app doesn't pay for the six torch-only detectors, and a PyTorch repo gets them. Real output, against a small Flask app with a few real bugs planted in it, on this machine, right now:

$ reagent hunt ./my-flask-app --no-ledger
======================================================================
my-flask-app
======================================================================
profile: py   23 detectors
  t19_unsafe_load                  nom=  0 confirmed= 0 unreach/no-div=  1    0.0s
  t21_mutable_default              nom=  1 confirmed= 0 unreach/no-div=  0    0.0s
  t29_xss                          nom=  0 confirmed= 1 unreach/no-div=  0    0.0s  <<< CONFIRMED
      app.py:18  delete_user
        delete_user: returns an HTML string embedding request-derived `user_id` unescaped
        -> security: reflected-html - request-derived, unescaped
  t31_unbounded_resource           nom=  0 confirmed= 1 unreach/no-div=  0    0.0s  <<< CONFIRMED
      app.py:12  load_config
        load_config: request.data reads the whole request body; no size cap found
        -> resource: unbounded-body - client-controlled, no ceiling
  t33_authz_inventory              nom=  2 confirmed= 0 unreach/no-div=  0    0.0s
  ... (18 more rows, all nom=0 confirmed=0 -- clean)

(other detectors' rows omitted above for length; a real run prints all 23)

Reading that output

Every row is one detector's pass over the whole repo:

  • nom=N -- static check() nominations: an AST pattern matched. This is the cheap stage; a nomination is a lead, not a finding.
  • confirmed=N / <<< CONFIRMED -- confirm() ran (imported the code, drove it, or re-affirmed the static taint verdict) and the bug shape held up. This is what you act on.
  • unreach/no-div=N -- confirm() ran and the nomination did NOT hold up: the code path was unreachable, or (for the ML numerical detectors) the fp16/fp32 outputs didn't actually diverge. This is the false-positive rate being measured, not hidden -- t19_unsafe_load above nominated something and then correctly ruled it unreachable in this run.
  • A row with nom=0 confirmed=0 unreach/no-div=0 and no <<< line means that detector found nothing here. Most rows on most repos look like this -- see "Track record" above on why a clean sweep is the common case, not a failure of the tool.
  • t33_authz_inventory's nom=2 confirmed=0 is by design, not a bug: its confirm() runs but always explicitly returns confirmed=None -- it's inventory-grade, not finding-grade (see its row in the table below) -- it lists routed handlers for a human to look at, it never claims to have proven a missing check.

Choosing a command

You want to... Run
Validate the tool itself before trusting it reagent selftest
Run every detector, unfiltered, against one target (e.g. to see what a specific torch-only detector does on a non-torch repo, or debug a detector) reagent scan <repo> [--confirm]
The normal case: scan one repo with the right detector subset reagent hunt <repo>
Scan many repos, unattended, safely (hang-proof, resumable) reagent sweep --repos-file repos.txt
Go deep on one repo/subdirectory, with an optional LLM triage pass reagent audit <repo> [--focus path/] [--judge]
Only the security-relevant detectors (unsafe deserialization, untrusted I/O, prompt injection, OS command/SQL injection), findings held for coordinated disclosure rather than proposed as a public PR reagent sec <repo>
Check whether a repo's actual public API matches what it claims to support reagent scope <repo> [--probe]
Review past findings you've already triaged reagent ledger stats | list | review

Commands (full reference)

reagent selftest                                    every detector's synthetic fixtures -> GREEN
reagent scan   <repo> [--confirm]                    every detector, unfiltered, rendered report
reagent hunt   <repo> [<repo>...] [--gate] [--no-ledger] [--judge]
                                                      profile-applicable detectors + confirm, triage summary
reagent sweep  <repo>... | --repos-file f.txt [--workers N] [--timeout S] [--resume|--force]
                                                      MASSIVE SCALE: every applicable detector, one
                                                      isolated subprocess per (repo, detector) with a
                                                      hard timeout, many repos in parallel, resumable --
                                                      a killed or crashed sweep picks back up where it
                                                      left off instead of re-doing finished work
reagent audit  <repo> [--focus path/] [--sec] [--judge]   deep single-target audit
reagent sec    <repo>                                security-only audit, disclosure-held
reagent scope  <repo> [--probe]                      does the public API match the declared scope?
reagent gate   collect <repo>... | bench | fit        the confirm() gate (see GATE_*.md)
reagent ledger stats | list [label] | review          the triaged-findings memory

--gate (on hunt/sweep) loads a small trained classifier (bftools/catalyst.py + raf_gate_weights.json) that can SKIP a nomination it predicts won't confirm, to speed up a large scan -- it can never ADD a finding, and its own live-validated recall is documented in GATE_PRE_REGISTRATION.md; treat it as a speed optimization, not a precision one.

What happens when a detector finds something

Nothing gets filed or published automatically. hunt/sweep/audit print the finding and (unless --no-ledger) record it in your local findings_ledger.jsonl so a re-run recognizes an already-triaged false-positive instead of reprinting it every time (reagent ledger stats to see what's in there). Filing a real bug against someone else's project is a manual, deliberate step you take after reading the finding yourself -- the security-relevant detectors' own PRE_REGISTRATION.md (e.g. t19_unsafe_load, t20_untrusted_io, t26_os_command_injection, t27_sql_injection) each state the same discipline this tool is built around under their own "Disclosure" section: a confirmed exploitable finding is held for coordinated disclosure, never a public PR for a live vulnerability before the vendor has a fix (reagent sec runs only those detectors, for exactly this case).

Why sweep, and not just hunt in a loop

hunt runs every detector for one repo, in-process, with no timeout -- a single detector wedged on one bad repo (an import that blocks on network, an infinite loop the detector's own probe triggers) hangs the whole run forever, and a crash partway through a long multi-repo list loses every result that hadn't been printed yet. sweep runs each (repo, detector) pair as its own subprocess with a hard wall-clock timeout, many repos at once, and writes every result to disk the moment it's known -- so a sweep across hundreds of repos survives a bad repo, survives a crash, and a rerun of the exact same command resumes instead of starting over. A (repo, detector) pair that times out twice is permanently marked skipped for that repo rather than retried forever on every future resume.

What is measured, and what is not

  • Deterministic first. A rubric, recall, or code execution decides; models (the LLM judge, the LLM-nominate detector) only explain or triage.
  • Every detector's bench.py is validated on synthetic ground truth before it's trusted on a real repo: the planted bug must be caught, the clean sibling must not.
  • NIT findings are reported for transparency; they are explicitly not candidates and don't count toward any "found N bugs" number.

Files

cli.py (entry point) · run_all.py/hunt.py/sweep.py/scope.py/audit.py (the commands) · bftools/ (shared Python-detector plumbing) · cbftools/ (shared C-detector plumbing) · tNN_*/ (Python detectors) · cNN_*/ (C detectors) · findings_ledger.jsonl (triaged-finding memory, see reagent ledger) · METHOD.md (how to mint a new detector) · GATE_*.md (the confirm() gate's own pre-registration and bench results).

Honest limits

  • Do not file from the tritsystem GitHub account while it remains flagged -- check its current status before filing anything new.
  • The confirm() gate (--gate) can only skip a nomination, never add one; it is a speed optimization for hunt/sweep on large repos, not a precision improvement. Its own live-validated recall is in GATE_PRE_REGISTRATION.md.
  • sweep's per-repo parallelism is thread-based dispatch of subprocesses, not a distributed job queue -- it scales to "run this over a machine's worth of CPU cores across a list of repos," not to a multi-machine cluster.
  • Matched-baseline recall numbers (ruff/existing linters vs each detector) are only computed for the detectors listed in the table below; the rest are honestly marked --.
id dir class matched baseline proven-by
T1 t01_autodiff_consistency static-nominate + gradcheck probe lib's own gradcheck coverage pytorch#196170
T2 t02_shape_dtype_ir shape/dtype/device abstract interpreter ruff / grep / PyTea (shape-only) rotary#50, kornia#4336
T3 t03_docstring_contract numpydoc invariant -> Hypothesis test Ghostwriter w/o doc mining --
T4 t04_low_precision_sweeper fp32-vs-fp16 max|delta| probe lib's half-precision CI xfail list dtype record
T5 t05_inter_repo_clone_diff fix -> clone-detect -> recheck GitHub code search lucidrains SinusoidalPosEmb x3
T6 t06_llm_nominate_confirm LLM nominate -> deterministic confirm arch-finder AST nomination E1 pipeline
T7 t07_mr_miner_fix_history mine MRs from merged fix PRs metamorph-audit's 5 fixed MRs --
T8 t08_state_registration_audit "register via API X vs raw assign", multi-framework each framework's own linter kornia buffer PRs
T9 t09_serialization_roundtrip save->load->behavioral-equivalence -- --
T10 t10_config_flag_sweeper t-way covering array + "flag had no effect" oracle -- ultralytics#26075 (shape)
T11 t11_cross_version_diff lib==N vs N-1 behavioral diff the changelog --
T12 t12_nan_inf_reachability static NaN/Inf sites + fault-input gen DEBAR published recall --
T13 t13_inplace_alias_detector stored-then-mutated caller arg ruff B006/B008 (defaults only) ansible#87503
T14 t14_gradient_flow_audit graph-breakers on input->output path lib's gradcheck tests --
T15 t15_rng_seed_hygiene eager RNG / GPU-nondeterminism / global-state project seed fixtures kornia eager-RNG audit
T17 t17_cache_key_completeness key free-vars vs result-affecting inputs none (labelled hand-audit) ultralytics#26075
T18 t18_capability_sonar metamorphic/boundary probes on array-taking callables -> a capability fingerprint checked against the callable's own docstring and its siblings -- --
T19 t19_unsafe_load unsafe deserialization (pickle/torch.load/yaml.load) reachability bandit S301/S506 --
T20 t20_untrusted_io unvalidated archive extraction (path traversal) + untrusted-input-built URL/path reaching an I/O sink ruff S310 covers only the URL-fetch half; no baseline for archive-extraction path traversal held for coordinated disclosure
T21 t21_mutable_default mutable default arg actually mutated in the body ruff B006 (flags all, not just real ones) --
T22 t22_swallowed_error broad+silent except around real work, not an import guard -- --
T23 t23_iterator_state_leak shared iterator/generator state leaking across calls -- --
T24 t24_invariant_drift a container attribute mutated by a method that doesn't also update its paired counter attribute -- --
T25 t25_indirect_prompt_injection untrusted content reaching an LLM prompt unsanitized -- --
T26 t26_os_command_injection untrusted input reaching a shell/subprocess call bandit S602-S609 --
T27 t27_sql_injection untrusted input reaching a raw SQL string bandit S608 --
T28 t28_code_injection untrusted input reaching eval/exec/similar ruff S307/S102 --
T29 t29_xss untrusted input reaching an unescaped HTML/template sink ruff S701/S704 --
T30 t30_unrestricted_upload file upload without extension/type/size validation -- --
T31 t31_unbounded_resource untrusted input controlling an unbounded loop/allocation/request -- --
T32 t32_info_exposure an error path that leaks internals (stack trace, path, secret) to the caller -- --
T33 t33_authz_inventory inventory-grade (not finding-grade): routed handlers with no visible auth/CSRF check, for a human to look at -- AST can't see gateway/router-level/ORM-level checks, so a hit is a T0 lead, never proof of a missing check -- --

C detectors (cNN_*, no Python equivalent needed -- these are memory-safety classes): C01 banned buffer copy, C02 use-after-free, C03 format string, C04 TOCTOU check-then-use, C05 memory leak, C06 alloc-size overflow, C07 null deref on unchecked alloc, C08 OS command injection.

About

A two-stage assay for bugs in Python/C code: cheap AST nomination, then a dynamic confirm() probe. 40 detectors, real merged findings across kornia/celery/spikingjelly/ultralytics/DeepSpeed/peft/timm/x-transformers.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages