Traditional SAST tools and linters are great at catching syntax issues and known taint patterns (eval, hardcoded secrets, basic SQLi). Where they struggle is semantic business-logic bugs a newly added /admin route missing an auth decorator, a TOCTOU check-then-act race condition on a balance transfer, a bare except Exception: pass swallowing a failed DB write, or an AI-generated security guard that doesn't actually enforce anything.
On the other end, dumping an entire repository into an LLM on every pull request is slow, expensive, and noisy.
I just open sourced LogicGuard v0.1.0 (MIT) to bridge the two with a diff-scoped, two-stage pipeline for Python, JavaScript, and TypeScript.
How the Two-Stage Pipeline Works
Instead of sending every changed line to a model, LogicGuard splits scanning into two distinct phases:
- Stage 1 — Tree-sitter AST Pre-Filter (~3ms): Parses only the functions modified in your
git diffand extracts structural risk candidates. If a PR touches clean code or non-matching logic, LogicGuard exits immediately with zero LLM calls. - Stage 2 — Structured LLM Verification (Pydantic v2): Evaluates only the matched candidates to filter false positives, pinpoint exact line ranges, and output concrete remediation.
It supports OpenRouter (works with openrouter/free for $0 CI runs), Anthropic, local Ollama models, and a pure-AST --offline-only mode for private or air-gapped repos.
Try It Locally (No Install Required)
# List the 5 built-in rules uvx logicguard rules # Run pure Tree-sitter AST checks against your current git diff uvx logicguard diff --base main --offline-only Or install globally via pipx install logicguard.
Built-in Rules (v0.1.0)
-
auth_bypass— Mutating API routes missing authentication/authorization guards -
idor_ownership— Object access or mutation without verifying resource ownership -
race_toctou— Check-then-act state updates (e.g., balances, inventory) without locking or atomic updates -
silent_except— Broad exception handlers silently swallowing failures around state changes -
ai_hallucinated_guard— Placeholder or no-op validation checks commonly introduced by coding assistants
GitHub Actions + SARIF 2.1.0
LogicGuard ships with a GitHub Marketplace Action that emits SARIF 2.1.0 inline directly into GitHub Code Scanning PR reviews and separates exit codes (0 clean, 1 findings, 2 provider/config error) so a flaky API doesn't masquerade as a security failure:
name: LogicGuard Security Diff Scan on: pull_request: branches: [main] permissions: contents: read security-events: write jobs: logicguard: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - uses: Aviation3006/logicguard@v0.1.0 env: OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }} (Swap in provider: ollama or offline-only: true if your codebase cannot touch external APIs.)
Links & Contributing
Every rule follows a self-contained 2-file contract (src/logicguard/rules/<name>.py + tests/rules/test_<name>.py), and I've opened 8 good first issue rule specs (#2–#9) covering JWT none alg, SSRF, mass assignment, missing rate limits, open redirects, SQL string interpolation, insecure cookie flags, and upload path traversal.
- GitHub: https://github.com/Aviation3006/logicguard
- PyPI: https://pypi.org/project/logicguard/
- GitHub Marketplace: https://github.com/marketplace/actions/logicguard-security-diff-scan
- Docs: https://logicguard.me
If you try it on a repo or have strong opinions on AST pre-filter heuristics and false-positive handling in CI I'd love to hear your feedback in the comments or issues.