cd /news/ai-tools/i-built-logicguard-a-diff-aware-tree… · home › topics › ai-tools › article
[ARTICLE · art-182041] src=dev.to ↗ pub= topic=ai-tools verified=true sentiment=↑ positive

I Built LogicGuard: A Diff-Aware Tree-sitter + LLM Scanner for Business-Logic Bugs

A developer has open sourced LogicGuard v0.1.0 under the MIT license, a diff-scoped security scanner that combines Tree-sitter AST analysis with LLM review to catch semantic business-logic bugs in Python, JavaScript, and TypeScript. The tool runs a git-diff pre-filter to extract structural risk candidates before invoking a model, supporting OpenRouter, Anthropic, local Ollama, and a pure-AST offline mode, and ships with five built-in rules including auth bypass, IDOR, TOCTOU races, silent exception handlers, and AI-hallucinated guards. It includes a GitHub Marketplace Action that emits SARIF 2.1.0 into Code Scanning PR reviews and separates exit codes so provider errors don't masquerade as security findings.

key takeaway

LogicGuard's two-stage pipeline runs Tree-sitter AST rules against only the git diff first, invoking an LLM only on structural risk candidates, and uses distinct exit codes (0 clean, 1 findings, 2 provider error) so flaky API calls don't read as security failures in CI.

by read2 min views6 publishedDec 4, 2026

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.

Instead of sending every changed line to a model, LogicGuard splits scanning into two distinct phases:

git diff and extracts structural risk candidates. If a PR touches clean code or non-matching logic, LogicGuard exits immediately with 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.

uvx logicguard rules

uvx logicguard diff --base main --offline-only

Or install globally via pipx install logicguard.

v0.1.0) auth_bypass — Mutating API routes missing authentication/authorization guardsidor_ownership — Object access or mutation without verifying resource ownershiprace_toctou — Check-then-act state updates (e.g., balances, inventory) without locking or atomic updatessilent_except — Broad exception handlers silently swallowing failures around state changesai_hallucinated_guard — Placeholder or no-op validation checks commonly introduced by coding assistants 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.)

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.

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.

── more in #ai-tools 4 stories · sorted by recency
── more on @logicguard 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/i-built-logicguard-a…] indexed:0 read:2min 2026-12-04 · —