惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
I
InfoQ
人人都是产品经理
人人都是产品经理
博客园 - 三生石上(FineUI控件)
爱范儿
爱范儿
Hugging Face - Blog
Hugging Face - Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
SegmentFault 最新的问题
美团技术团队
小众软件
小众软件
Blog — PlanetScale
Blog — PlanetScale
Jina AI
Jina AI
aimingoo的专栏
aimingoo的专栏
H
Help Net Security
Last Week in AI
Last Week in AI
博客园_首页
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
L
LangChain Blog
云风的 BLOG
云风的 BLOG
Martin Fowler
Martin Fowler
宝玉的分享
宝玉的分享
G
Google Developers Blog
博客园 - 叶小钗
博客园 - Franky

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
What ground truth caught that unit tests missed: 3 real b...
Ofri Peretz · 2026-05-14 · via DEV Community

We added a npm run ilb:flagship:smoke gate to the quality script. It's small: for each flagship rule with a labeled corpus, run the rule against vulnerable/* (must fire) and safe/* (must stay silent). Compute precision, recall, F1. Fail the build below F1=1.00.

The first run hit nine rules. Six passed. Three failed.

Rule Result What broke
react-features/hooks-exhaustive-deps P=67% R=100% F1=0.80 False positive on the standard .then((r) => r.json()) pattern
mongodb-security/no-unsafe-query P=100% R=50% F1=0.67 Missed $where injection via template-literal interpolation
vercel-ai-security/no-unsafe-output-handling P=— R=0% F1=— Found nothing in const { text } = await generateText(...); el.innerHTML = text

All three rules had passing unit-test suites. All three had been benchmarked alongside peer plugins on real OSS for weeks. None of those signals would have surfaced these bugs.

What did surface them: 14 fixtures across 3 corpora — 12 lines of code per corpus on average — labeled with // This MUST be detected or // This MUST NOT fire comments and run through the same lint config a real user would have.

Bug #1: hooks-exhaustive-deps fires on inner-callback parameters

The fixture:

import { useEffect, useState } from 'react';

export function Profile({ userId }: { userId: string }) {
  const [data, setData] = useState(null);
  useEffect(() => {
    fetch(`/api/users/${userId}`).then((r) => r.json()).then(setData);
  }, [userId]);
  return <div>{JSON.stringify(data)}</div>;
}

Enter fullscreen mode Exit fullscreen mode

This is the canonical "fetch on user-id change" pattern. userId is closed over and listed in deps. r is a parameter of the .then() callback — local to that arrow function, not a closure.

Our rule fired:

React Hook useEffect has missing dependencies: r

Enter fullscreen mode Exit fullscreen mode

Tracing into the source, extractLocallyDeclaredIdentifiers walked the effect body, collected VariableDeclaration and FunctionDeclaration names, but didn't collect params of nested ArrowFunctionExpression / FunctionExpression. Every callback parameter inside the effect was treated as a closure-from-outside.

Fix: when visiting a nested function node, add its params to the declared set:

if (
  n.type === 'ArrowFunctionExpression' ||
  n.type === 'FunctionExpression' ||
  n.type === 'FunctionDeclaration'
) {
  for (const param of n.params) collectFromPattern(param);
}

Enter fullscreen mode Exit fullscreen mode

collectFromPattern handles Identifier, ObjectPattern (with nested Property and RestElement), ArrayPattern, RestElement, and AssignmentPattern — destructured params, rest spreads, defaults. After the fix, the fixture passes.

The reason unit tests missed this: every test fixture in the suite used either a closure-only effect or an effect with a single top-level callback. None had .then((r) => …).then((data) => …) — the most common real-world shape.

Bug #2: NoSQL injection via $where was invisible

The fixture:

async function searchByName(req) {
  return db.collection('items').find({
    $where: `this.name == '${req.query.name}'`,
  }).toArray();
}

Enter fullscreen mode Exit fullscreen mode

This is a real NoSQL injection. $where evaluates JavaScript on the database server. With req.query.name interpolated unescaped, an attacker sends name=' || true || ' and gets every record.

Our rule didn't fire. Walking the source:

function getNodeSource(node: TSESTree.Node): string {
  if (node.type === Identifier) return node.name;
  if (node.type === MemberExpression) /* …recurse */;
  if (node.type === Literal) return String(node.value);
  return '[expression]';   // ← TemplateLiteral hit this
}

function containsUserInput(node: TSESTree.Node): boolean {
  const code = getNodeSource(node);
  return USER_INPUT_PATTERNS.some((pattern) => code.includes(pattern));
}

Enter fullscreen mode Exit fullscreen mode

When the value of $where was a TemplateLiteral, getNodeSource returned the literal string '[expression]'. Then containsUserInput checked whether '[expression]' contained req.query — it doesn't. Silent skip.

The fix is to recurse into composite expressions instead of stringifying them:

function containsUserInput(node: TSESTree.Node): boolean {
  if (node.type === TemplateLiteral) {
    return node.expressions.some(containsUserInput);
  }
  if (node.type === BinaryExpression) {
    return containsUserInput(node.left) || containsUserInput(node.right);
  }
  if (node.type === CallExpression) {
    return containsUserInput(node.callee) ||
           node.arguments.some((a) => a.type !== 'SpreadElement' && containsUserInput(a));
  }
  if (node.type === MemberExpression) {
    return USER_INPUT_PATTERNS.some((p) => getNodeSource(node).includes(p));
  }
  return false;
}

Enter fullscreen mode Exit fullscreen mode

TemplateLiteral, BinaryExpression (string concat), and CallExpression (e.g. .toString() chains, String(req.x), JSON.stringify(req.body)) are all routes for tainted data into a query. Each gets recursed into now.

Why the unit tests missed it: the existing test corpus had find({ x: req.body.x }) shapes — direct user input as a property value. That shape gets caught by isUnsafePropertyValue's MemberExpression branch. The $where template literal is also user input, but expressed differently — and the pattern-matching code path didn't recurse far enough to see it.

Bug #3: AI-output detection missed the standard SDK pattern

The fixture:

import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';

async function render(prompt: string, target: HTMLElement) {
  const { text } = await generateText({ model: openai('gpt-4'), prompt });
  target.innerHTML = text;   // ← LLM output flows directly into innerHTML
}

Enter fullscreen mode Exit fullscreen mode

This is straight from the Vercel AI SDK's official documentation. const { text } = await generateText(...) is the destructured pattern every example uses.

Our rule fired on nothing. The detection model:

const aiOutputPatterns = [
  'result.text', 'response.text', 'completion', 'generated',
  'aiOutput', 'aiResponse', 'llmOutput', '.text',
];

function isLikelyAIOutput(node: TSESTree.Node): boolean {
  const text = sourceCode.getText(node);
  return aiOutputPatterns.some((pattern) => text.includes(pattern));
}

Enter fullscreen mode Exit fullscreen mode

When the rule visits target.innerHTML = text, the right-hand side is the bare identifier text. The string 'text' doesn't match 'result.text', 'response.text', or '.text' (which all require a member-access prefix). So isLikelyAIOutput returns false. No diagnostic.

The pattern list assumes the LLM result is referenced as a property of an object. But the destructured pattern produces a free identifier. Two completely valid sources, only one detectable.

The fix is to add scope tracking — record any local variable bound from a known AI SDK call, and treat references to those as AI output:

const aiBoundNames = new Set<string>();
const AI_SDK_CALLS = new Set([
  'generateText', 'streamText', 'generateObject', 'streamObject',
]);

function isAISDKCall(node: TSESTree.Expression): boolean {
  let target = node;
  if (target.type === 'AwaitExpression') target = target.argument;
  if (target.type !== 'CallExpression') return false;
  const callee = target.callee;
  if (callee.type === 'Identifier' && AI_SDK_CALLS.has(callee.name)) return true;
  if (callee.type === 'MemberExpression' &&
      callee.property.type === 'Identifier' &&
      AI_SDK_CALLS.has(callee.property.name)) return true;
  return false;
}

return {
  VariableDeclarator(node) {
    if (!node.init || !isAISDKCall(node.init)) return;
    if (node.id.type === 'Identifier') {
      aiBoundNames.add(node.id.name);
    } else if (node.id.type === 'ObjectPattern') {
      for (const prop of node.id.properties) {
        if (prop.type === 'Property' && prop.value.type === 'Identifier') {
          aiBoundNames.add(prop.value.name);
        }
      }
    }
  },
  // …
};

Enter fullscreen mode Exit fullscreen mode

Now both const result = await generateText(...) (binding result → access via result.text) and const { text } = await generateText(...) (binding text directly) flow into aiBoundNames. The isLikelyAIOutput check picks them up by referenced identifier, regardless of how the user destructured.

Why the unit tests missed it: the test corpus used result.text patterns, matching 'result.text' in the patterns list literally. The destructured pattern was never in the test suite — even though it's the more common shape in production code.

What this whole episode is really about

Three rules. Three bugs. All caught by ground truth, none by unit tests. The pattern across them is the same:

Unit tests verify that the rule does what its author thought it should do. The author wrote the test, the author writes the rule, the same mental model produces both. If the author didn't think of the .then((r) => …) pattern, neither the rule nor the tests cover it. The tests pass; the rule has a hole.

Ground-truth corpora verify that the rule does what the world needs it to do. The fixtures are written from real CVE shapes, real framework documentation, real production codebases. They don't match the rule's mental model — they match the user's. Mismatches surface as F1<1.00.

The fixtures in our suite are tiny — 12 to 18 lines per corpus, 4 fixtures each. The total disk cost is under 5KB. They run in ~3 seconds total. They caught three bugs the unit tests had missed across months of development.

A 5KB corpus that runs in 3 seconds found bugs hundreds of unit tests missed. That should change how you think about "what does it mean to test a static-analysis rule."

Three concrete takeaways for any team writing or shipping linters:

Write fixtures from documentation, not from your tests. When you start a new rule, open the canonical docs for the pattern (CVE description, framework doc, OWASP example). Copy the example into a fixture before writing the rule. If the rule passes the fixture later, you've shipped a feature; if it doesn't, you've found a bug before users do.

Make the corpus a CI gate. Unit tests verify implementation; corpus tests verify behavior. Treating them as the same kind of test means one of them will atrophy. Run both, fail the build on either.

Surface the failures with confusion-matrix detail. "Test failed" is one bit. "F1 = 0.67, TP=1 FP=0 FN=1 TN=2 — where-string.js did not fire" is the actual diagnostic. The test framework should output the matrix, not just the boolean. Triage time goes from 15 minutes to 30 seconds.

The three fixes here are in packages/eslint-plugin-react-features, eslint-plugin-mongodb-security, and eslint-plugin-vercel-ai-security. The corpora are in benchmarks/corpus/. The smoke gate is benchmarks/suites/ilb-flagship/smoke.ts and it runs in three seconds.

Three seconds. Three bugs. Months of "fully tested." Pick which signal you trust.

Two more from the same bench, written up separately

The smoke gate caught the three above. The full ILB-Flagship sweep on 45K+-star OSS repos exposed two more rule bugs the same week — both deeper algorithmic stories than fit here:

Both bugs survived months of unit-test coverage. Both fell to ground-truth fixtures + bench data. Same lesson, two more receipts.


📊 About the author

I'm Ofri Peretz, building the Interlace ESLint ecosystem — a JavaScript static-analysis catalog that runs under ESLint and Oxlint with CI-enforced parity.