National Cyber Warfare Foundation (NCWF)login

regextokens for sourced, offline-proven OAuth and API secret scanning


0 user ratings
2026-10-23 21:27:08
milo
Red Team (CNA)
"regextokens

A Python scanner that detects leaked OAuth and API tokens using sourced, tested, ReDoS-checked regex patterns with checksum-based offline proof, built for CI gating on repositories you own.








Toolodomojuli/regextokens — sourced, tested, offline-proving scanner for OAuth / API tokens and secrets
CategorySecret scanning / regex pattern catalog
Primary UseScanning your own codebases, diffs, and CI pipelines for leaked credentials via regextokens scan, with SARIF output and pre-commit gating
Safe UseFor authorized security assessments, internal code audits, and defensive CI hygiene on repositories and systems you own or are contracted to test
Telemetry NotePurely local: no network calls, no issuer API contact, secrets redacted in output by default, baselines store only sha256 fingerprints — defenders can safely run it anywhere

odomojuli/regextokens is a Python secret scanner that takes an unusually disciplined approach to a problem most tools handle sloppily: how do you know a regex hit is actually a credential and not a placeholder, a public identifier, or a truncated example? The project ships a catalog of 109 patterns covering 64 providers — generated 2026-07-02 according to the README — where every entry is sourced from primary provider documentation, tested against positive and negative samples, and proven RE2-compatible with ReDoS checks. The result is not just a detector but an argument about what pattern quality should look like in this space.


Architecturally, the interesting decision is the single source of truth. Everything derives from the DATA structure inside build_patterns.py, and both patterns.json and the README's pattern index are generated artifacts you are explicitly told never to hand-edit. Running python build_patterns.py regenerates the catalog and documentation together, which eliminates the classic drift problem where a scanner's docs, its machine-readable pattern file, and its tests quietly disagree. The repo commits its own baseline covering the synthetic samples used in testing, and CI self-scans against it — the tool dogfoods itself, which is always a good signal.


Installation is the standard pip install -e ., which gives you both the regextokens console script and an importable package. Usage centers on regextokens scan PATH... to walk files and directories, with flags that matter for real workflows: -m verified restricts output to offline-proven findings, -f sarif emits SARIF suitable for GitHub code scanning, and regextokens list dumps the catalog. Exit codes are deliberately CI-friendly — 0 for clean, 1 for findings at or above the requested tier, 2 for error — so wiring it as a merge gate is a one-liner in most pipeline systems.


What genuinely differentiates the engine is the confidence model, which the README frames around offline proof rather than shape matching. A verified-offline finding means a checksum or decoder locally proves structural authenticity — the README cites CRC32 validation for GitHub and npm tokens, empirically validated against real revoked tokens. Below that sits probable, where structure is combined with a Shannon-entropy check on the token body consistent with a real secret, and low, which is a shape match only and may be a placeholder or public identifier. Critically, the tool also defines a rejected tier: a ghp_ or npm_ string with a valid prefix and length but a bad checksum is dropped with certainty. That kills the largest false-positive class for the highest-value providers before it ever reaches a human.


The tool is honest about its limits: offline proof never claims a key is live, because that would require calling the issuer's API, which this scanner never does. All verification is local computation — no network, no telemetry to third parties, no accidental validation oracle against a provider. That property matters for defenders running scans in sensitive environments and for anyone worried that a naive liveness check would itself leak the token to the issuer's logs.


For CI adoption, the baseline and allowlist system is where the engineering effort went. regextokens scan . --write-baseline .regextokens-baseline.json snapshots current findings, and a subsequent --baseline run subtracts them so the gate only fails on new secrets. The baseline stores fingerprints — sha256 of the pattern ID plus a hashed secret body — never the secrets themselves, making it safe to commit. Matching is line-independent, so edits above an accepted finding don't un-suppress it, while the same token appearing in a different file is treated as a new exposure and reported. A hand-edited allow section carries policy as fnmatch path globs and pattern IDs.


Distribution is well covered: a pre-commit hook configured via .pre-commit-hooks.yaml at rev v0.2.0, and a composite GitHub Action in action.yml with a min-confidence input defaulting to probable. The README explains why the default is not low: that tier includes public identifiers and placeholders that would make a commit gate unusable from the noise alone. The Action's SARIF output can be fed to github/codeql-action/upload-sarif@v3 for code-scanning integration, and releases go to PyPI via tag-triggered trusted publishing.


The pattern conventions reveal deep familiarity with scanner failure modes. Patterns are written RE2-compatible — usable by gitleaks and Go engines — with no lookbehind or backreferences, and tuned for re.search semantics with a note to anchor with ^/$ if you need validators instead. Each entry carries a strategy tag: prefix patterns are reliable alone, structure patterns match a fixed shape, keyword patterns must be gated on a nearby keyword, identifier marks public non-secrets, and encoding entries are format checks. The catalog even documents why, as with the AWS secret access key — a 40-character base64 body with no fixed prefix and low entropy — keyword gating is the only viable approach.


Coverage spans the expected cloud providers (Amazon Web Services, Google, Microsoft Azure, Cloudflare, DigitalOcean, HashiCorp Vault, Okta, Tailscale), source and CI systems (GitHub, GitLab, CircleCI, npm, PyPI), a notably broad AI section (OpenAI, Anthropic, Mistral AI, Groq, Hugging Face, xAI, Perplexity), payments including Stripe and Square, comms like Slack and Twilio, and productivity tools from Notion to Sentry. Every entry includes a src: citation to primary documentation — the Google section, for example, distinguishes the current GOCSPX- client secret format from the older unprefixed one and documents that refresh tokens now begin 1// rather than 1/.


If you don't want the engine, the catalog stands alone: the README shows loading patterns.json directly and compiling entries with Python's re module, so you can graft the patterns into your own tooling. Supporting materials include sniffer-audit.md, an audit of how other secret scanners build and verify their patterns with benchmark data, plus a references.bib bibliography with lineage tracing to Meli et al.'s NDSS 2019 study on secret leakage in GitHub repositories. The test suite (test_patterns.py, test_engine.py) validates every pattern for compilation, matching, RE2 compatibility, and ReDoS safety, plus engine behavior end to end.


In an authorized workflow, regextokens fits naturally as pre-commit hygiene, a CI merge gate, and a triage instrument during code review or post-incident review of your own repositories. Because example tokens in the catalog are synthetic filler rather than live credentials, and output redacts secrets by default, it is safe to run in shared CI logs. For red teams doing repo audits under contract, the confidence tiers turn a flood of regex hits into a prioritized shortlist; for blue teams, it's a defensible, offline, no-phone-home way to keep credentials out of the codebase in the first place. With an MIT license, Python implementation, and 293 stars at time of writing, it's a young but rigorously engineered entrant in a crowded category.



Official project repository for odomojuli/regextokens.

Download Tool

Educational analysis for authorized security professionals. Use only in controlled, authorized environments.






Source: OffensiveSec
Source Link: https://www.offsecblog.com/2026/10/regextokens-for-sourced-offline-proven.html


Comments
new comment
Nobody has commented yet. Will you be the first?
 
Forum
Red Team (CNA)



Copyright 2012 through 2026 - National Cyber Warfare Foundation - All rights reserved worldwide.