{"slug": "i-built-logicguard-a-diff-aware-tree-sitter-llm-scanner-for-business-logic-bugs", "title": "I Built LogicGuard: A Diff-Aware Tree-sitter + LLM Scanner for Business-Logic Bugs", "summary": "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.", "body_md": "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.\n\nOn the other end, dumping an entire repository into an LLM on every pull request is slow, expensive, and noisy.\n\nI just open sourced **LogicGuard v0.1.0** (MIT) to bridge the two with a diff-scoped, two-stage pipeline for **Python, JavaScript, and TypeScript**.\n\nInstead of sending every changed line to a model, LogicGuard splits scanning into two distinct phases:\n\n`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.\n\n```\n# List the 5 built-in rules\nuvx logicguard rules\n\n# Run pure Tree-sitter AST checks against your current git diff\nuvx logicguard diff --base main --offline-only\n```\n\nOr install globally via `pipx install logicguard`.\n\n`v0.1.0`)\n`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\nLogicGuard 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:\n\n```\nname: LogicGuard Security Diff Scan\non:\n  pull_request:\n    branches: [main]\n\npermissions:\n  contents: read\n  security-events: write\n\njobs:\n  logicguard:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v4\n        with:\n          fetch-depth: 0\n      - uses: Aviation3006/logicguard@v0.1.0\n        env:\n          OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }}\n```\n\n*(Swap in `provider: ollama` or `offline-only: true` if your codebase cannot touch external APIs.)*\n\nEvery 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.\n\nIf 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.", "url": "https://wpnews.pro/news/i-built-logicguard-a-diff-aware-tree-sitter-llm-scanner-for-business-logic-bugs", "canonical_source": "https://dev.to/aviation3006/i-built-logicguard-a-diff-aware-tree-sitter-llm-scanner-for-business-logic-bugs-l5k", "published_at": "2026-12-04 20:08:55+00:00", "updated_at": "2026-12-04 20:13:46.829650+00:00", "lang": "en", "topics": ["ai-tools", "developer-tools", "ai-agents", "ai-safety"], "entities": ["LogicGuard", "Tree-sitter", "GitHub", "OpenRouter", "Anthropic", "Ollama", "Aviation3006"], "also_reported_by": [], "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.", "recommendation": null, "alternates": {"html": "https://wpnews.pro/news/i-built-logicguard-a-diff-aware-tree-sitter-llm-scanner-for-business-logic-bugs", "markdown": "https://wpnews.pro/news/i-built-logicguard-a-diff-aware-tree-sitter-llm-scanner-for-business-logic-bugs.md", "text": "https://wpnews.pro/news/i-built-logicguard-a-diff-aware-tree-sitter-llm-scanner-for-business-logic-bugs.txt", "jsonld": "https://wpnews.pro/news/i-built-logicguard-a-diff-aware-tree-sitter-llm-scanner-for-business-logic-bugs.jsonld"}}