Learning center

Which files did a clean scan actually read?

A scan with zero findings covers only the files it parsed, so read its skipped-file list before accepting the result. Accept the clean result for a skipped file only when that file is generated, vendored or test code that the build does not ship; otherwise rescan it with a parser or configuration that reads it.

Find the skipped files in the scanner's own summary#

Every static analyzer decides which files to read before it looks for problems. It skips files its parser rejects, files that match an ignore list, and files above a size limit, and most tools treat each of these as a note rather than a failure. The zero in "No issues identified" counts findings in the files that were read. The skipped-file section, usually printed last and often only in verbose mode, says which files that zero leaves out.

The constructed project below has a small package svc with a vendored helper in src/svc/vendor/, and one test file. One module, rules.py, contains an eval call and uses the type parameter syntax that Python 3.12 introduced (What's New in Python 3.12 lists PEP 695, the type parameter syntax and the type statement, among its new features). The package declares requires-python = ">=3.12":

# src/svc/rules.py
type Expr = str


def evaluate[T](expr: Expr, env: dict[str, T]) -> T:
    return eval(expr, {}, env)

Bandit: a parse error that exits 0#

Bandit 1.9.4 installed under Python 3.11, as a CI image pinned to an older interpreter might have it, and run with the vendored directory excluded as third-party code (the Semgrep section below returns to that exclusion), reports a clean run and exits 0:

$ bandit -r src -x src/svc/vendor
[main]  INFO    running on Python 3.11.18
...
Test results:
        No issues identified.
...
Files skipped (1):
        src/svc/rules.py (syntax error while parsing AST from file)
$ echo $?
0

The last two lines carry the result. Bandit parses each file with the interpreter it runs on: bandit/core/node_visitor.py at 1.9.4 calls f_ast = ast.parse(data), and bandit/core/manager.py catches the SyntaxError and records "syntax error while parsing AST from file" in its skipped list (manager.py at 1.9.4, node_visitor.py at 1.9.4). Python 3.11 cannot parse a type statement:

$ python3.11 -c "import ast; ast.parse(open('src/svc/rules.py').read())"
Traceback (most recent call last):
  ...
    type Expr = str
         ^^^^
SyntaxError: invalid syntax

The same Bandit version under Python 3.12 reads the file and reports the call:

$ bandit -q -r src -x src/svc/vendor     # Bandit 1.9.4 on Python 3.12.3
>> Issue: [B307:blacklist] Use of possibly insecure function - consider using safer ast.literal_eval.
   Severity: Medium   Confidence: High
   CWE: CWE-78 (https://cwe.mitre.org/data/definitions/78.html)
   More Info: https://bandit.readthedocs.io/en/1.9.4/blacklists/blacklist_calls.html#b307-eval
   Location: src/svc/rules.py:5:11
...
Files skipped (0):
$ echo $?
1

For machine checks, the JSON report puts skipped files in an errors array (bandit -r src -x src/svc/vendor -f json returned [{'filename': 'src/svc/rules.py', 'reason': 'syntax error while parsing AST from file'}] here), which a CI step can require to be empty.

Semgrep: an ignore list you did not write#

Semgrep 1.187.0 parses the 3.12 syntax and finds the eval. Its summary says one finding, and it also skipped three files:

$ semgrep scan --metrics=off --disable-version-check --config rule.yml .
...
    src/svc/rules.py
    ❯❱ eval-call
          ❰❰ Blocking ❱❱
          eval of dynamic input
            5┆ return eval(expr, {}, env)
...
 • Findings: 1 (1 blocking)
 • Rules run: 2
 • Targets scanned: 3
 • Parsed lines: ~100.0%
 • Scan skipped:
   ◦ Files matching .semgrepignore patterns: 3
 • For a detailed list of skipped files and lines, run semgrep with the --verbose flag

The project has no .semgrepignore. --verbose names the files and the source of the rule:

$ semgrep scan --metrics=off --disable-version-check --config rule.yml --verbose .
...
  Skipped by .semgrepignore:
  - https://semgrep.dev/docs/ignoring-files-folders-code/#understand-semgrep-defaults
   • src/svc/vendor/__init__.py
   • src/svc/vendor/runner.py
   • tests/test_rules.py
...
  Skipped by limiting to files smaller than 1000000 bytes:
  (Adjust with the --max-target-bytes flag)
   • <none>

These come from Semgrep's built-in list, used "when no .semgrepignore exists at the project root" according to the comment in Semgrepignore.ml at v1.187.0. The built-in file includes build/, vendor/, dist/ and node_modules/ under "Paths to files and folders that are typically large and ignorable", and test/ and tests/ under "Common test paths". A directory named vendor anywhere in the tree matches, including one inside your package.

The same source comment explains how to turn the defaults off: "if a user needs to override the default semgrepignore rules, they need at least an empty root '.semgrepignore' file." With an empty one, the scan reads six files and reports three findings:

$ touch .semgrepignore && semgrep scan --metrics=off --disable-version-check --config rule.yml .
...
    src/svc/vendor/runner.py
    ❯❱ subprocess-shell-true
          ❰❰ Blocking ❱❱
          subprocess call with shell=True
            5┆ return subprocess.call(cmd, shell=True)
    tests/test_rules.py
    ❯❱ eval-call
          ❰❰ Blocking ❱❱
          eval of dynamic input
            5┆ assert eval("1 + 1") == 2
...
 • Findings: 3 (3 blocking)
 • Rules run: 2
 • Targets scanned: 6
...

Decide whether the skipped file ships#

A skipped file matters if it runs in production. The build artifact answers that, so list what the package actually contains:

$ pip wheel -q . --no-deps -w dist && python -m zipfile -l dist/svc-1.4.0-py3-none-any.whl   # dates and sizes trimmed
File Name
svc/__init__.py
svc/handlers.py
svc/rules.py
svc/vendor/__init__.py
svc/vendor/runner.py
svc-1.4.0.dist-info/METADATA
...

svc/vendor/runner.py is in the wheel. The default ignore list treated it as third-party code, but it ships with the package and runs with its permissions, so its shell=True call needs review like any other. Add it back explicitly (an empty or project-specific .semgrepignore, and no -x for it in the Bandit run, which then reports the same call as B602) and keep scanning it.

tests/test_rules.py is the disconfirming case. It was skipped too, and it holds an eval that Semgrep reports once the defaults are off. The wheel listing has no tests/ entry, so the file never reaches a deployed environment, and its eval runs a constant string in a test. That skip is correct, and the clean result for shipped code stands. The same reasoning covers a generated client or a vendored copy that the build excludes: confirm the exclusion in the artifact, then record it in the ignore file with a comment, so the next reader does not have to rediscover it.

Two cautions apply to the disconfirmation. A file missing from the wheel can still ship by another route, such as a container image that copies the whole repository, so check the artifact you deploy, not only the one you built here. And vendored code that ships is code you run, even if you did not write it; skipping it in a source scan only makes sense when a dependency or image scanner covers it.

Decide from the skipped-file list#

What the scan saysEvidence to collectDecision
Zero findings, files skipped for parse errorsThe interpreter or parser version the scanner used, and the project's requires-pythonRerun on a matching interpreter; the clean result does not cover those files
Zero findings, files skipped by an ignore list you did not writeThe verbose skipped list and the built-in ignore fileCheck each skipped path against the build artifact
Skipped file is in the wheel, image or bundleThe artifact listingRemove the skip and fix or triage what the rescan finds
Skipped file is a test, generated or vendored file absent from every artifactArtifact listings for each deploy routeAccept the skip; record the reason in the ignore file
Files skipped for sizeThe size limit flag and the file's roleRaise the limit for source you ship; accept it for generated data

A finding that seems to apply to code the build never compiles is a related question, covered in the guide to findings in code that is not compiled. When a reviewer's file list is narrower than the change, the guide to excluding generated review files shows how to keep that list deliberate.

One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. Eligibility and fair-use terms.

Start free with GitHub

Related reading