Skip to content

add learned confidence classifier to cut generic-detector false positives#4

Merged
GravityHaxx merged 1 commit into
mainfrom
feat/learned-confidence-classifier
Jul 23, 2026
Merged

add learned confidence classifier to cut generic-detector false positives#4
GravityHaxx merged 1 commit into
mainfrom
feat/learned-confidence-classifier

Conversation

@doofzoff

Copy link
Copy Markdown
Collaborator

what

Adds an opt-in learned confidence refiner that cuts false positives from generic, format-agnostic detectors.

high_entropy catches unknown-format keys, but it also fires on benign high-entropy strings: UUIDs, git SHAs, digests, object ids, and slugs. This adds a small classifier that tells real secrets from look-alikes and nudges the confidence score. Paired with minConfidence, the noise drops out.

const noisy = 'id 9fceb02d0ae598e95dc970b74767f19372d61af8 tok Zx9Kq2Lm7Pv4Rt6Wy8Bn3Cf5Hj1Dg0As7Uv';

scan(noisy, { enable: ['high_entropy'] });
// git SHA and the unknown-format token both flagged at a flat 60%

scan(noisy, { enable: ['high_entropy'], refineConfidence: true, minConfidence: 0.5 });
// the SHA is gone; the token survives (refined up to 80%)

how

  • src/ml.ts + src/confidence-model.ts — logistic regression over cheap character features (Shannon entropy, character-class mix, structure, and nearby labels like api_key= or commit). Trained offline, shipped as fixed weights.
  • No new runtime dependency. Inference is one feature pass plus a dot product: synchronous, deterministic, safe on edge and in the browser. No model download, no native add-on.
  • scripts/train-confidence-model.mjs — the reproducible trainer (seeded PRNG). Re-running with --write reproduces src/confidence-model.ts byte for byte. Holdout: precision 99.05%, recall 98.55%, accuracy 98.80% (n=4000).
  • Integration is conservative. Only detectors marked refine are affected (currently just high_entropy); checksum-validated detectors (cards, IBANs, national ids) are never touched. refineConfidence is off by default, so existing behavior is unchanged.
  • Exposes secretProbability / extractFeatures from the package root and the new flare-redact/ml subpath, plus a --refine-confidence CLI flag.

scope / honesty

This is a linear model trained on synthetic data, not a silver bullet. It targets one concrete pain point (high-entropy noise) without pulling in an ML runtime, which keeps the zero-dependency guarantee intact.

tests

test/ml.test.mjs (9 cases) covers the model, the engine integration, the untouched checksum path, and the default-off behavior. Full suite: 162/162 passing. README and CHANGELOG updated.

…ives

generic matchers like high_entropy also fire on benign high-entropy
strings such as uuids, git shas, digests, object ids, and slugs. this adds
an opt-in confidence refiner: when refineConfidence is set, a small logistic
regression scores each match from a detector marked refine as a real secret
versus a look-alike and nudges its confidence. pair it with minConfidence to
drop the noise. checksum-validated detectors are never touched.

the model is character-level logistic regression trained offline by
scripts/train-confidence-model.mjs and shipped as fixed weights in
src/confidence-model.ts, so the runtime stays zero-dependency, synchronous,
and deterministic. secretProbability and the model are exported from the
package root and the new flare-redact/ml subpath, and the cli gains
--refine-confidence.
@GravityHaxx
GravityHaxx merged commit caa035f into main Jul 23, 2026
4 checks passed
umudhasanli pushed a commit that referenced this pull request Jul 24, 2026
… transform tests (#5)

* Release 1.2.0: learned confidence classifier, graph/vault benchmarks, transform tests

- Ship the secret-confidence classifier (PR #4) as 1.2.0's headline:
  opt-in refineConfidence scoring for generic detectors, exported via
  the new flare-redact/ml subpath and --refine-confidence in the CLI.
- Add bench/graph-vault.mjs (npm run benchmark:graph): redact() on flat
  strings and deep object graphs, and vault mint+restore round trips.
- Add direct unit tests for pseudonymize/surrogate (Luhn-valid card
  surrogates, keyed determinism) and mapGraph traversal (URL,
  URLSearchParams, Error prototypes, shared refs, sparse arrays,
  symbol keys, Map/Set). 162 -> 170 tests.

* Add national phone formats, GCP detectors, and official Bun/Deno smoke coverage

- phone (opt-in) now matches formatted national numbers ((555) 123-4567,
  +90 532 123 45 67, trunk-0 forms) with digit-count validation and a
  date guard; bare digit runs still never match.
- New default-on detectors: gcp_service_account (private_key_id in
  service-account JSON) and gcp_refresh_token (1// OAuth tokens).
- CI now smoke-tests the dependency-free core on Bun and Deno via
  scripts/runtime-smoke.mjs; publish depends on both passing.
- README: React/browser usage section. 170 -> 174 tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants