Security-focused static analysis

I write Semgrep rules when a precise pattern can catch the problem, and CodeQL queries when the answer depends on data flow or framework behavior. Getting the first match is the easy part. I spend more time adding safe cases and tightening the rule until the finding is worth interrupting a developer for.

01 / Approach

How I approach static analysis.

  1. Pick the right engine

    I reach for Semgrep when syntax and local context are enough. If the check needs data flow, framework models, or relationships across calls, I write it in CodeQL. The rule should be no more complicated than the behavior demands.

  2. The first match is a draft

    A rule usually starts broad. I run it against real code, add safe wrappers and common framework patterns, and narrow it when ordinary code gets flagged. Fewer false positives means developers are more likely to trust the next result.

  3. Test what should not match

    Every rule gets vulnerable examples and safe ones. The safe fixtures matter just as much. They record the rule's boundaries, stop old mistakes from returning, and make later changes easier to review.

02 / Evidence

Things I have built and changed.

03 / Questions

Questions about static analysis.

01

What is security-focused static analysis?

Static analysis reads code without running the application. A simple rule may look for one risky pattern. A deeper query can follow data through several functions or understand how a framework handles it. The purpose is to find a specific security problem early enough to fix it in code review.

Semgrep static analysis glossary
02

Why do SAST tools produce false positives?

A false positive happens when a rule flags code that is safe in its real context. The rule may be too broad, miss a safe wrapper, or misunderstand how the framework handles the data. I reduce that noise by adding those safe cases to the rule and its tests.

Semgrep error matrix definitions
03

What makes a good static analysis security rule?

A good rule starts with a real risky behavior. It catches vulnerable examples, ignores realistic safe ones, and explains why the match matters. The message should give the developer enough context to fix the code without having to read the rule first.

GitHub guidance for custom CodeQL queries
04

When should a team write a custom CodeQL or Semgrep rule?

Write a custom rule when the same bug keeps appearing and the standard rules miss it or flag it badly. Start with real vulnerable and safe examples. Then choose Semgrep or CodeQL based on how much context the check needs.

GitHub custom CodeQL query use cases

04 / Related

05 / Contact

Working on a problem like this?