/security-tools:semgrepfrom security-tools
Runs Semgrep SAST scans on Drupal custom modules and themes using registry packs (p/php, p/owasp-top-ten, p/secrets) plus custom Drupal rules for SQL injection, XSS, superglobals, static calls, debug leftovers, and route access checks. Triages findings as true positive, false positive, or needs context with OWASP ASVS mapping.
Ships in security-tools. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
A security review that rests only on reading code misses what nobody read. Semgrep gives it a deterministic floor: the same code always gives the same findings, each with a rule id and a line. The review then judges those findings and goes on to what a pattern cannot see (business logic, object-level access, data flow across services).
Use it together with:
owasp-asvs (this plugin) — the requirement each finding maps to;drupal-dev-tools:drupal-security-review — the manual checklist the scan
feeds.Only custom code — contrib and core have their own security process:
web/modules/custom
web/themes/custom
Adjust to the project's docroot (docroot/, html/). Skip paths that do not
exist; a scan of a missing path is an error, not an empty result.
| Config | What it covers |
|---|---|
p/php | General PHP security rules (exec, eval, unserialize, weak crypto…) |
p/owasp-top-ten | OWASP Top 10 rules across languages, incl. JavaScript in themes |
p/secrets | Hard-coded keys, tokens and passwords |
rules/drupal.yml | Custom Drupal PHP rules, below |
rules/drupal-routing.yml | Routes in *.routing.yml without an access requirement |
rules/ is the directory next to this file. Pass the two rule files
explicitly — the directory also holds the test fixtures, which are not rules.
The registry packs (p/…) are downloaded at scan time, so they need network
access. Offline, run only the two local files and say in the report that the
registry packs were not run.
| Rule id | Finds | ASVS | Severity |
|---|---|---|---|
drupal-sqli-concatenated-query | ->query() / db_query() with concatenated, interpolated or sprintf()-built SQL | V1.1.4 | ERROR |
drupal-xss-markup-unescaped | A variable in #markup without t(), Xss::filter() or Html::escape() | V1.1.1, V1.2.1 | WARNING |
drupal-xss-markup-create | Markup::create() with a variable that was not filtered | V1.1.1, V1.2.1 | WARNING |
drupal-superglobal-access | $_GET, $_POST, $_REQUEST, $_COOKIE, $_FILES | V2.1.1 | WARNING |
drupal-static-call-in-di-class | \Drupal::…() in a class with a constructor or create() | — (design) | INFO |
drupal-debug-output | var_dump, print_r, dpm, kint, dump, dd … | V12.1.1, V12.1.2 | WARNING |
drupal-route-without-access-check | A route with no _permission, _access, _custom_access, _entity_access, _role or _user_is_logged_in | V8.1.3, V4.2.1 | WARNING |
The ASVS IDs are the ones used in the owasp-asvs skill. Each rule also holds
them in metadata.asvs, with a metadata.triage hint. The DI rule is a design
finding (dependency inversion, see quality-tools:solid), not an ASVS
requirement; it is reported because a hidden \Drupal::currentUser() or
\Drupal::request() is where access and input handling hide.
From the project root. RULES is the absolute path of this skill's rules/
directory.
Semgrep installed locally (or without installing it: pipx run semgrep …,
uvx semgrep …):
semgrep scan --metrics=off --json --output semgrep.json \
--config p/php --config p/owasp-top-ten --config p/secrets \
--config "$RULES/drupal.yml" --config "$RULES/drupal-routing.yml" \
web/modules/custom web/themes/custom
Docker, nothing installed:
docker run --rm \
-v "$PWD:/src" -v "$RULES:/rules:ro" -w /src \
semgrep/semgrep semgrep scan --metrics=off --json --output semgrep.json \
--config p/php --config p/owasp-top-ten --config p/secrets \
--config /rules/drupal.yml --config /rules/drupal-routing.yml \
web/modules/custom web/themes/custom
In a DDEV project run the same docker run from the host, not inside the web
container. Exit code 0 means the scan ran, whether or not it found anything;
1 with --error means findings; anything else is a failed scan — read
.errors in the JSON before reporting "no findings".
Write semgrep.json outside the repository or add it to .gitignore; scan
output is not committed.
jq -r '.results[] | [.check_id, "\(.path):\(.start.line)", .extra.severity,
((.extra.metadata.asvs // []) | join(",")),
((.extra.metadata.cwe // []) | join("; "))] | @tsv' semgrep.json
jq '.errors' semgrep.json # parse errors, timeouts, skipped files
check_id of a local rule is prefixed with its path
(rules.drupal-sqli-concatenated-query); report the part after the last dot.extra.lines is the matched source, extra.message the rule's advice..errors with a parse error means that file was not scanned: list it in
the report.Every finding gets one verdict, decided by reading the code around it:
| Verdict | When |
|---|---|
| true positive | The flagged value can be influenced by a user (request, entity field, user-editable config, external API) and reaches the sink unprotected, or the pattern is wrong in itself (debug output, a route without access) |
| false positive | The value is constant or already sanitised on the way, or the code never runs in production (tests, a settings.php guard) — say which |
| needs context | The value comes from another method, service or module that you did not read; name what has to be checked |
Rules for triage:
extra.lines. Follow the variable back to
where it is set.metadata.triage hint; it lists the common false positives.Xss::filterAdmin() on
purpose.// nosemgrep: <rule-id> and a reason on the same line. Never silence
a true positive.query() later, input that reaches a sink through another service, and
missing object-level access are not found — they stay on the manual
checklist.Registry rules carry CWE and OWASP Top 10 metadata, not ASVS. Map them by CWE
to the owasp-asvs checklist:
| CWE | ASVS |
|---|---|
| CWE-89 SQL injection | V1.1.4 |
| CWE-79 XSS | V1.1.1, V1.2.1 |
| CWE-78 OS command injection | V1.1.5 |
| CWE-95 / CWE-94 eval, code injection | V1.2.2 |
| CWE-918 SSRF | V1.2.3 |
| CWE-22 path traversal | V5.2.2 |
| CWE-434 unrestricted upload | V5.1.2 |
| CWE-352 CSRF | V3.3.1 |
| CWE-798 / CWE-259 hard-coded secret | V6.3.1, V14.4.1 |
| CWE-327 / CWE-328 weak crypto or hash | V14.1.1 |
| CWE-330 weak randomness | V14.2.1 |
| CWE-862 / CWE-285 missing authorization | V8.1.3 |
| CWE-489 debug code | V12.1.1 |
A CWE that is not in the table: name the CWE and pick the closest ASVS chapter
from owasp-asvs, marked "(nearest)".
One row per finding, true positives first, then needs context, then false positives:
| Rule | Location | ASVS | Severity | Verdict | Reason |
|---|---|---|---|---|---|
| drupal-sqli-concatenated-query | web/modules/custom/foo/src/Repo.php:42 | V1.1.4 | ERROR | true positive | `$title` comes from the route parameter |
| drupal-xss-markup-unescaped | web/modules/custom/foo/src/Controller/Bar.php:18 | V1.1.1 | WARNING | needs context | value built in `BarBuilder::build()`, not read |
| drupal-debug-output | web/modules/custom/foo/foo.module:77 | V12.1.1 | WARNING | false positive | inside `if (getenv('FOO_DEBUG'))`, never set in production |
Below the table: the configs that ran (and which did not, e.g. offline), the
paths scanned, files listed in .errors, and the Semgrep version
(semgrep --version).
Each rule file has a fixture with // ruleid: <id> (the next line must be
reported) and // ok: <id> (the next line must not):
| Rules | Fixture |
|---|---|
rules/drupal.yml | rules/drupal.php |
rules/drupal-routing.yml | rules/drupal-routing.test.yaml |
semgrep --test rules/
# or
docker run --rm -v "$PWD/rules:/rules:ro" semgrep/semgrep semgrep --test /rules
A changed rule ships with a fixture line that proves it — one ruleid: for
what it now finds and one ok: for what it must leave alone.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
semgrep, sast, drupal-security, static-analysis, owasp-asvs, code-scanning
2 skills in this plugin
npx claudepluginhub siva01c/claude-plugins --plugin security-toolsOther plugins' skills for the same job