π³οΈ Loophole
π Website: https://frinjo.me/loophole Β· π¦ Latest release: v1.2.2
This project is tested with BrowserStack.
Loophole is a zero-dependency static security scanner that finds the holes
in your code β hardcoded secrets, SQL injection, XSS, command injection, weak
crypto and more β across JavaScript/TypeScript, Python, Go and PHP.
It also explains why each finding matters, suggests a fix, and can print
mechanical fix suggestions as diffs without ever touching your files.
python3 loophole.py scan ./src
# or, with the wrapper on your PATH:
loophole scan ./srcWhy another scanner?
Most scanners are either heavyweight SaaS products or regex grep-scripts with
noisy output. Loophole sits in the middle:
- Single file, stdlib only β no install, no dependencies, runs anywhere
Python 3.8+ exists. Drop it into CI in seconds. - Taint-aware (v1) β it doesn't just pattern-match sinks; it tracks
variables assigned from request/user input (req.query,request.args,
$_GET,r.URL.Query(), β¦) and flags when they flow into dangerous
sinks, including directquery($_GET['id'])usage. - Near-zero false positives β parameterized queries,
textContent,
execFilewith literals,crypto.randomUUID, env-var secrets and friends
are all recognized as safe. - Fix suggestions, not just findings β
--fix-dryprints unified diffs
for safe mechanical fixes. It never modifies your files.
Quick start
# scan a directory or file
python3 loophole.py scan ./src
# JSON report for tooling
python3 loophole.py scan ./src --json report.json
# SARIF for GitHub code scanning
python3 loophole.py scan ./src --sarif results.sarif
# self-contained HTML report (inline CSS, no external assets)
python3 loophole.py scan ./src --html report.html
# JUnit XML for CI dashboards (Jenkins, GitLab CI, Azure DevOps, CircleCI)
python3 loophole.py scan ./src --junit report.xml
# GitLab SAST report for the Security Dashboard / merge request widget
python3 loophole.py scan ./src --gitlab gl-sast-report.json
# adopt on an existing codebase: record today's findings as a baseline,
# then fail CI only on NEW ones
python3 loophole.py scan ./src --write-baseline baseline.json
python3 loophole.py scan ./src --baseline baseline.json
# show suggested fixes as diffs (read-only)
python3 loophole.py scan ./src --fix-dry
# list all rules
python3 loophole.py scan --rules .
# show what one rule checks, its severity and how to fix it
python3 loophole.py scan --explain SEC001
# only critical findings, skip tests
python3 loophole.py scan ./src --severity critical --exclude 'tests/*'Exit code is 1 when any critical/high finding exists (CI-friendly),
0 otherwise.
Docker
No local Python needed β scan from the container image instead.
The image is python:3.12-slim, contains only loophole.py
(stdlib only, no extra dependencies), and runs as a non-root user.
docker build -t loophole .
docker run --rm -v "$PWD:/src" loophole scan /srcPublished image (GHCR)
On every release, the smoke-tested image is published to GitHub
Container Registry as ghcr.io/rootsiemen/loophole:<tag> and
:latest β no local build needed:
docker pull ghcr.io/rootsiemen/loophole:latest
docker run --rm -v "$PWD:/src" ghcr.io/rootsiemen/loophole:latest scan /srcFor a specific release, replace latest with the tag, for
example ghcr.io/rootsiemen/loophole:v1.2.0. The entrypoint is
the same (python3 loophole.py), so all scan arguments work
unchanged.
That mounts the current directory at /src inside the container
and scans it. The exit code is the same as the local scanner:
1 when any critical/high finding exists, 0 otherwise.
Scan a single file or a different directory the same way:
docker run --rm -v "$PWD:/src" loophole scan /src/tests/fixtures/py_vuln.py
docker run --rm -v "$PWD:/src" loophole scan /src --json /src/report.jsonNote: with --json, --sarif, --html or --junit, write the report to a
path under /src so the file lands in your mounted directory.
GitHub Action
Run Loophole on every push and pull request, with findings uploaded to
GitHub code scanning (your repo's Security tab):
name: Security scan
on: [push, pull_request]
permissions:
contents: read
security-events: write # required for the SARIF upload
jobs:
loophole:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: rootsiemen/loophole@v1Options (all optional):
| Input | Default | What it does |
|---|---|---|
path |
. |
File or directory to scan |
severity |
medium |
Minimum severity to report: critical, high or medium |
exclude |
β | Comma-separated directory names to skip |
upload-sarif |
true |
Upload the SARIF report to code scanning |
fail-on-findings |
true |
Fail the step when critical/high findings exist |
python-version |
3.12 |
Python version used to run the scanner |
Example β scan only src, never block the build:
- uses: rootsiemen/loophole@v1
with:
path: src
fail-on-findings: "false"Pre-commit
Catch findings before they are committed, with the
pre-commit framework:
repos:
- repo: https://github.com/rootsiemen/loophole
rev: v1.2.2
hooks:
- id: loopholeThe hook scans every staged JavaScript, TypeScript, Python, Go and PHP
file and fails the commit when a file has critical or high findings
(the scanner's default exit behaviour). Until the package is
pip-installable (issue #21), the hook runs from a checkout of this
repository via a small wrapper script, because loophole scan takes a
single path per invocation.
Shell completions
Tab-completion for bash and zsh lives in completions/:
# bash β copy the script into your completions directory, then start
# a new shell (or `source` it for the current session only)
cp completions/loophole.bash ~/.local/share/bash-completion/completions/loophole
# zsh β copy the file to a directory on your fpath, then re-run compinit
mkdir -p ~/.zsh/completions
cp completions/_loophole ~/.zsh/completions/_loophole
rm -f ~/.zcompdump; compinitIf ~/.zsh/completions is not already on your fpath, add this to
~/.zshrc before compinit:
fpath=(~/.zsh/completions $fpath)Both complete the scan subcommand, every scan flag, the
--severity choices (critical, high, medium), file paths for
the report/config options (--json, --sarif, --html, --junit,
--gitlab, --config, --baseline, --write-baseline, --cache), rule IDs for
--explain, and files/directories for the scan target. The selftest
suite checks that every flag in loophole scan --help appears in both
files, so the completions cannot silently drift from the CLI.
Example output
Loophole found 3 issue(s): 1 critical, 2 high, 0 medium
ββ CRITICAL (1) ββββββββββββββββββββββββββββββββββββββββββββββ
CMD001 Command injection via child_process (JS/TS)
src/app.js:33
βΊ exec(cmd, (err, out) => res.send(out));
taint: req.query.cmd -> cmd -> exec
why: Passing user-influenced strings to a shell lets attackers append
commands (`; rm -rf /`, `$(...)`) that run with the app's privileges.
fix: Avoid shells entirely: use execFile/spawn with an argument array
(no shell). Never concatenate input into a command string.
Rules (62)
Each finding carries: rule id, severity, file:line, code snippet, taint
path (when tracked), why it matters, and a fix suggestion.
Taint tracking (v1)
Loophole performs lightweight intra-file taint analysis:
- Sources β assignments from
req.query/req.body/req.params,
request.args/request.form,$_GET/$_POST/$_REQUEST/
$_COOKIE,r.URL.Query(),os.Args, and friends mark a variable tainted. - Direct sources β
query($_GET['id'])(no intermediate variable) is
caught too. - Formatted strings β variables holding interpolated SQL/HTML
(f-strings, template literals,fmt.Sprintf,"β¦$x") are tracked so
q = f"β¦{x}"; cursor.execute(q)still flags. - Sinks β SQL calls,
exec/system,eval, file functions, HTTP
clients. When tainted data reaches a sink, the finding shows the path:
req.query.cmd -> cmd -> exec.
Scope is deliberately small (single file, ~2 hops, no inter-procedural
analysis). It catches the common cases with very few false positives;
deeper analysis is on the roadmap.
CI example (GitHub Actions)
name: security-scan
on: [push, pull_request]
jobs:
loophole:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Run Loophole
run: python3 loophole.py scan ./src --sarif loophole.sarif
- name: Upload SARIF
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: loophole.sarifThe step fails (exit 1) when critical/high findings exist, and results
appear under your repo's Security β Code scanning tab.
Suppressing findings
When a finding is a false positive (or a risk you've accepted), silence it
inline β no config file needed:
token = derive_token(salt) # loophole: skip=SEC005// loophole: skip=CORS001 (bare form silences every rule on the line)
res.setHeader('Access-Control-Allow-Origin', '*');Comma-separated rule ids are supported: # loophole: skip=SEC001,SEC005.
Use suppressions sparingly β each one is a hole you're choosing not to see.
loophole:ignore is an alias with a space-separated form, handy in
languages where = looks odd in comments:
res.cookie('session', id, opts); // loophole:ignore COOKIE001Configuration
Drop a .loophole.json in the directory you scan (or point --config
at any file) to tune the scan per project:
{
"exclude": ["generated", "fixtures"],
"disable": ["HDR001"],
"severity": { "SEC001": "medium", "LOG001": "critical" }
}excludeβ path names or glob patterns to skip (merged with the
built-in excludes and any--excludeflags).disableβ rule ids that never run for this project.severityβ per-rule severity overrides (critical,high,
medium); they affect the report order and the exit code.
A broken config file prints a warning and is ignored β a scan never
dies because of its config.
Ignoring files (.loopholeignore)
Commit a .loopholeignore in the directory you scan to skip files
and directories, gitignore-style β one pattern per line:
# generated output and vendored files
generated/
*.min.js
legacy.py
- A bare
namematches a file or directory name at any depth. - A
path/pattern matches everything under that directory. *and?globs match a path component (*.min.js) or, when the
pattern contains a/, the path relative to the scanned root
(generated/*).- Blank lines and
#comments are ignored.
Ignored files are skipped during the walk exactly like excluded
directories, and the count appears as ignored in the JSON summary
(summary.ignored) and on the terminal. --exclude and the config
exclude keep working and combine with the ignore file. Removing
.loopholeignore restores the skipped findings.
Baseline
Adopting a scanner on an existing codebase usually means a wall of
findings you can't fix today. Record them once:
python3 loophole.py scan ./src --write-baseline baseline.jsonCommit baseline.json, and later scans hide everything in it:
python3 loophole.py scan ./src --baseline baseline.jsonCI then fails only on new findings. Entries are keyed by rule,
file and code snippet, so small line shifts don't resurrect them.
Incremental cache (--cache)
Repeat scans of a large tree re-analyse every file. Opt in to a cache
to skip unchanged files:
python3 loophole.py scan ./src --cache .loophole-cache.json- The first run is a cold cache (everything scanned); the second
reuses stored findings for files that did not change. - Entries are keyed by file path plus size, mtime and a SHA-256 of the
contents, so editing a file invalidates only that file's entry. - The cache also records the Loophole version and the scan config: a
Loophole upgrade or a config change (disabled rules, severity
overrides) invalidates the whole cache automatically. - Baseline and severity filtering still apply after cache retrieval,
so a cached run produces exactly the same findings as an uncached
run. The JSON summary reportssummary.cachedβ how many files were
served from cache β and the terminal prints the same count. - The cache is always opt-in: without
--cachenothing is read or
written and every scan is a full scan. There is no daemon or watch
mode; a corrupt or unreadable cache file is ignored and the scan
falls back to a full scan of the affected files.
HTML report
python3 loophole.py scan ./src --html report.htmlProduces a single self-contained HTML file β inline CSS, no external
assets, works offline β with findings grouped by severity, each with
file/line, the code snippet, why it matters and the fix.
JUnit report
python3 loophole.py scan ./src --junit report.xmlProduces a JUnit XML report for CI systems that ingest test-style
results (Jenkins, GitLab CI, Azure DevOps, CircleCI): one
<testsuite> for the scan, one <testcase> per finding with
classname set to the rule ID and name set to path:line, and a
<failure> whose message includes the severity, rule ID and finding
title. A clean scan emits an empty suite (tests="0" failures="0").
GitLab SAST report
python3 loophole.py scan ./src --gitlab gl-sast-report.jsonProduces a GitLab SAST report (schema 15.x) for the Security
Dashboard and the merge request widget: one vulnerability per
finding, with a stable id (a hash of rule + file + snippet, so the
same finding keeps the same id across scans), category: "sast",
severity mapped from Loophole's critical/high/medium onto
GitLab's Critical/High/Medium, the rule id in identifiers
(with a link to the rule docs), and location (file,
start_line). A clean scan emits an empty vulnerabilities list.
Wire it into .gitlab-ci.yml:
loophole:
image: python:3.12-slim
script:
- python3 loophole.py scan ./src --gitlab gl-sast-report.json
artifacts:
reports:
sast: gl-sast-report.jsonProject layout
loophole/
βββ loophole.py # the scanner (single file, stdlib only)
βββ completions/ # shell completions for bash and zsh
β βββ loophole.bash
β βββ _loophole
βββ Dockerfile # container image: python:3.12-slim, non-root, stdlib only
βββ loophole # shell wrapper: loophole scan <path>
βββ README.md
βββ tests/
βββ selftest.py # python3 tests/selftest.py
βββ fixtures/ # 20 fixtures (10 vulnerable + 10 clean)
Contributing
- New rules go in
loophole.py: write arule_XXXnnn(ctx)function
returning a list of findings, register it inRULESwith its languages. - Add a vulnerable fixture and a clean counterpart under
tests/fixtures/β the clean one must produce zero findings. - Run
python3 tests/selftest.pyand the dogfood check below before
submitting.
Dogfood rule: every change must keep python3 loophole.py scan loophole.py
clean (exit 0).
License
MIT β see LICENSE. Loophole is free and non-commercial: no paid tiers, no telemetry, no usage restrictions beyond the MIT terms.