<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Avi Narain</title>
    <description>The latest articles on DEV Community by Avi Narain (@aviation3006).</description>
    <link>https://dev.to/aviation3006</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F99mvlsfu5tfj9m7ku25d.png</url>
      <title>DEV Community: Avi Narain</title>
      <link>https://dev.to/aviation3006</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/aviation3006"/>
    <language>en</language>
    <item>
      <title>I Built LogicGuard: A Diff-Aware Tree-sitter + LLM Scanner for Business-Logic Bugs</title>
      <dc:creator>Avi Narain</dc:creator>
      <pubDate>Fri, 04 Dec 2026 20:08:55 +0000</pubDate>
      <link>https://dev.to/aviation3006/i-built-logicguard-a-diff-aware-tree-sitter-llm-scanner-for-business-logic-bugs-l5k</link>
      <guid>https://dev.to/aviation3006/i-built-logicguard-a-diff-aware-tree-sitter-llm-scanner-for-business-logic-bugs-l5k</guid>
      <description>&lt;p&gt;Traditional SAST tools and linters are great at catching syntax issues and known taint patterns (&lt;code&gt;eval&lt;/code&gt;, hardcoded secrets, basic SQLi). Where they struggle is &lt;strong&gt;semantic business-logic bugs&lt;/strong&gt; a newly added &lt;code&gt;/admin&lt;/code&gt; route missing an auth decorator, a TOCTOU check-then-act race condition on a balance transfer, a bare &lt;code&gt;except Exception: pass&lt;/code&gt; swallowing a failed DB write, or an AI-generated security guard that doesn't actually enforce anything.&lt;/p&gt;

&lt;p&gt;On the other end, dumping an entire repository into an LLM on every pull request is slow, expensive, and noisy.&lt;/p&gt;

&lt;p&gt;I just open sourced &lt;strong&gt;LogicGuard v0.1.0&lt;/strong&gt; (MIT) to bridge the two with a diff-scoped, two-stage pipeline for &lt;strong&gt;Python, JavaScript, and TypeScript&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  How the Two-Stage Pipeline Works
&lt;/h2&gt;

&lt;p&gt;Instead of sending every changed line to a model, LogicGuard splits scanning into two distinct phases:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Stage 1 — Tree-sitter AST Pre-Filter (~3ms):&lt;/strong&gt; Parses only the functions modified in your &lt;code&gt;git diff&lt;/code&gt; and extracts structural risk candidates. If a PR touches clean code or non-matching logic, LogicGuard exits immediately with &lt;strong&gt;zero LLM calls&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Stage 2 — Structured LLM Verification (Pydantic v2):&lt;/strong&gt; Evaluates only the matched candidates to filter false positives, pinpoint exact line ranges, and output concrete remediation.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;It supports &lt;strong&gt;OpenRouter&lt;/strong&gt; (works with &lt;code&gt;openrouter/free&lt;/code&gt; for $0 CI runs), &lt;strong&gt;Anthropic&lt;/strong&gt;, local &lt;strong&gt;Ollama&lt;/strong&gt; models, and a pure-AST &lt;code&gt;--offline-only&lt;/code&gt; mode for private or air-gapped repos.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try It Locally (No Install Required)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# List the 5 built-in rules&lt;/span&gt;
uvx logicguard rules

&lt;span class="c"&gt;# Run pure Tree-sitter AST checks against your current git diff&lt;/span&gt;
uvx logicguard diff --base main --offline-only
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or install globally via &lt;code&gt;pipx install logicguard&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Built-in Rules (&lt;code&gt;v0.1.0&lt;/code&gt;)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;auth_bypass&lt;/code&gt; — Mutating API routes missing authentication/authorization guards&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;idor_ownership&lt;/code&gt; — Object access or mutation without verifying resource ownership&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;race_toctou&lt;/code&gt; — Check-then-act state updates (e.g., balances, inventory) without locking or atomic updates&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;silent_except&lt;/code&gt; — Broad exception handlers silently swallowing failures around state changes&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ai_hallucinated_guard&lt;/code&gt; — Placeholder or no-op validation checks commonly introduced by coding assistants&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  GitHub Actions + SARIF 2.1.0
&lt;/h2&gt;

&lt;p&gt;LogicGuard ships with a GitHub Marketplace Action that emits &lt;strong&gt;SARIF 2.1.0&lt;/strong&gt; inline directly into GitHub Code Scanning PR reviews and separates exit codes (&lt;code&gt;0&lt;/code&gt; clean, &lt;code&gt;1&lt;/code&gt; findings, &lt;code&gt;2&lt;/code&gt; provider/config error) so a flaky API doesn't masquerade as a security failure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;LogicGuard Security Diff Scan&lt;/span&gt;
&lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;pull_request&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;branches&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;main&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="na"&gt;permissions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;contents&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;read&lt;/span&gt;
  &lt;span class="na"&gt;security-events&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;write&lt;/span&gt;

&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;logicguard&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;
    &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/checkout@v4&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;fetch-depth&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Aviation3006/logicguard@v0.1.0&lt;/span&gt;
        &lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;OPENROUTER_API_KEY&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ secrets.OPENROUTER_API_KEY }}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;(Swap in &lt;code&gt;provider: ollama&lt;/code&gt; or &lt;code&gt;offline-only: true&lt;/code&gt; if your codebase cannot touch external APIs.)&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Links &amp;amp; Contributing
&lt;/h2&gt;

&lt;p&gt;Every rule follows a self-contained &lt;strong&gt;2-file contract&lt;/strong&gt; (&lt;code&gt;src/logicguard/rules/&amp;lt;name&amp;gt;.py&lt;/code&gt; + &lt;code&gt;tests/rules/test_&amp;lt;name&amp;gt;.py&lt;/code&gt;), and I've opened &lt;strong&gt;8 &lt;code&gt;good first issue&lt;/code&gt; rule specs (&lt;code&gt;#2&lt;/code&gt;–&lt;code&gt;#9&lt;/code&gt;)&lt;/strong&gt; covering JWT &lt;code&gt;none&lt;/code&gt; alg, SSRF, mass assignment, missing rate limits, open redirects, SQL string interpolation, insecure cookie flags, and upload path traversal.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;GitHub:&lt;/strong&gt; &lt;a href="https://github.com/Aviation3006/logicguard" rel="noopener noreferrer"&gt;https://github.com/Aviation3006/logicguard&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;PyPI:&lt;/strong&gt; &lt;a href="https://pypi.org/project/logicguard/" rel="noopener noreferrer"&gt;https://pypi.org/project/logicguard/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;GitHub Marketplace:&lt;/strong&gt; &lt;a href="https://github.com/marketplace/actions/logicguard-security-diff-scan" rel="noopener noreferrer"&gt;https://github.com/marketplace/actions/logicguard-security-diff-scan&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Docs:&lt;/strong&gt; &lt;a href="https://logicguard.me" rel="noopener noreferrer"&gt;https://logicguard.me&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;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.&lt;/p&gt;

</description>
      <category>security</category>
      <category>opensource</category>
      <category>cybersecurity</category>
      <category>python</category>
    </item>
  </channel>
</rss>
