Business logic vulnerabilities caught before the pull request merges.

Two-stage Tree-sitter AST and LLM diff scanning for pull requests. Catches auth bypasses, IDOR ownership gaps, TOCTOU races, silent exception swallows, and AI-hallucinated guards.

org/billing-service / PR #214
BLOCKED BY LOGICGUARD
Scanner: logicguard v0.1.0 Stage 1: Tree-sitter AST Stage 2: openrouter/free
Output: SARIF 2.1.0
apps/billing-service/src/routes/invoice.controller.ts
Rule: idor_ownership (CWE-639)
18 export async function getInvoiceRecord(req: Request, res: Response) {
19 const { invoiceId } = req.params;
20
21 - // [idor_ownership] CWE-639: Unscoped lookup by user-controlled invoiceId
22 -   const invoice = await prisma.invoice.findUnique({ where: { id: invoiceId } });
21 + // Recommended patch: enforce authenticated tenant ownership predicate
22 +   const { tenantId } = req.auth;
23 +   const invoice = await prisma.invoice.findFirstOrThrow({
24 +     where: { id: invoiceId, tenantId }
25 +   });
26 return res.json(invoice);
27 }
[idor_ownership · CWE-639 DETECTED] Stage 1 AST + Stage 2 LLM Verified

SARIF 2.1.0 artifact: logicguard.sarif

Runs via openrouter/free ($0), Anthropic, Ollama, or --offline-only.

Two-Stage Architecture

Tree-sitter AST precision paired with LLM context triage.

Sending raw diffs straight to an LLM is noisy and expensive. LogicGuard filters deterministically with Tree-sitter first, then verifies only structural candidates.

STAGE 01 · STRUCTURAL EXTRACTION Tree-sitter AST

Deterministic AST Diff Parser

Parses changed functions, route decorators, ORM queries, lock scopes, and exception handlers via Tree-sitter grammars. Isolates exact candidate spans before any model inference runs.

Zero-network mode: --offline-only Sub-second local scan
STAGE 02 · CONTEXTUAL VERIFICATION LLM Triage

Semantic Reachability & Guard Check

Evaluates flagged AST candidates against caller middleware, session context, and upstream invariants to confirm exploitability and dismiss safe internal patterns.

Default CI model: openrouter/free SARIF 2.1.0 output
OpenRouter $0 FREE TIER

Use openrouter/free in CI or locally for zero-cost Stage 2 verification on every PR.

Anthropic CLAUDE API

Connect your Anthropic key for deep semantic verification across complex authorization boundaries.

Ollama LOCAL LLM

Run local weights entirely inside your workstation or private runner with zero outbound source transfer.

--offline-only ZERO API

Skip Stage 2 LLM calls completely and enforce pure Stage 1 Tree-sitter AST rules with no API key required.

Built-in Rule Registry

Five high-signal rules out of the box.

Inspect the active rule set anytime with uvx logicguard rules. Every rule pairs a Tree-sitter AST matcher with semantic Stage 2 verification.

auth_bypass CWE-287 / CWE-306

Missing Authentication or Role Enforcement

Detects newly exposed API routes, RPC endpoints, or privileged state-mutating handlers that omit authentication middleware, session verification, or role guards.

@app.post("/admin/export") # missing Depends(require_admin)
idor_ownership CWE-639 / BOLA

Unscoped Object Ownership Lookups

Flags database reads, updates, or deletes driven by a user-controlled ID parameter without verifying ownership against user_id or tenant_id.

Invoice.objects.get(id=invoice_id) # missing tenant_id=req.user.tenant_id
race_toctou CWE-362 / CWE-367

Time-of-Check to Time-of-Use Races

Catches non-atomic check-then-act sequences on wallet balances, promo redemptions, and quota counters missing row locks or atomic updates.

if acct.balance >= amt: # unlocked read-modify-write
silent_except CWE-390 / CWE-636

Fail-Open Swallowed Exceptions

Identifies bare except: pass or empty catch {} blocks in auth, signature, or validation flows that fail open silently.

except AuthError: pass # execution continues unauthenticated
ai_hallucinated_guard AI-CODE AUDIT

Stubbed or No-Op Security Guards

Flags placeholder auth functions, tautological checks, or unawaited async verifiers frequently introduced by AI coding tools.

def verify_csrf(req): return True # stubbed guard
CLI Quickstart

Run in seconds from PyPI.

Inspect active rules immediately with uvx or install the CLI globally via pipx. Published live on PyPI as logicguard==0.1.0.

Zero-install run via uvx Recommended
$ uvx logicguard rules
Persistent global install via pipx pypi.org/project/logicguard
$ pipx install logicguard
Run Stage 1 Tree-sitter scan locally with zero API keys --offline-only
$ uvx logicguard scan --offline-only
GitHub Actions Marketplace

$0 automated PR diff scanning with SARIF 2.1.0.

Drop Aviation3006/logicguard@v0.1.0 into your pull request workflow. Pair with openrouter/free for $0 scanning and native SARIF 2.1.0 alerts in GitHub Security.

Emits standard SARIF 2.1.0 for GitHub Code Scanning
Uses openrouter/free for $0 LLM verification in CI
Supports Anthropic, Ollama, and --offline-only
.github/workflows/logicguard.yml
name: LogicGuard Security Diff Scan
on: [pull_request]

permissions:
  contents: read
  security-events: write

jobs:
  logicguard:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: LogicGuard Security Diff Scan ($0 via openrouter/free)
        uses: Aviation3006/logicguard@v0.1.0
        with:
          model: openrouter/free
          format: sarif
          output: logicguard.sarif
        env:
          OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }}

      - name: Upload SARIF 2.1.0 to GitHub Security
        if: always()
        uses: github/codeql-action/upload-sarif@v3
        with:
          sarif_file: logicguard.sarif
LOCAL-FIRST & AUDITABLE

Zero telemetry. Zero vendor lock-in.

LogicGuard executes directly inside your CI runner or local shell. Run purely offline with Tree-sitter AST rules, route through local Ollama weights, or bring your own OpenRouter or Anthropic key.

--offline-only Mode

Deterministic Tree-sitter AST rule evaluation with zero outbound HTTP requests or external credentials.

Self-Hosted Ollama

Point Stage 2 verification at local Ollama endpoints so proprietary code never leaves your hardware.

Direct BYOK Calls

Your CI runner talks directly to OpenRouter or Anthropic. No LogicGuard SaaS middleman touches your diffs.

Open-Source Core

Inspect every AST grammar query, rule heuristic, and prompt directly in the public GitHub repository.

Open Source Contributions

Contribute a rule to LogicGuard.

Each rule combines a clean Tree-sitter AST query with a focused Stage 2 verification prompt. Read the contributor guide or pick up an issue from the open queue.