published fresh until

Semgrep: catch untrusted input reaching shell execution

Summary Use taint rules for request-derived shell commands, scope languages and paths explicitly, and preserve positive and negative fixtures for helpers and safe argument arrays. Enable the gate after semgrep --test rules/

Not for choosing scanners; see semgrep-codeql-gitleaks-trivy-or-osv-for-small-team-ci-2026. Request taint sources and shell sinks, wrapper coverage boundaries, language and path filters, Pro propagators, fixture-first rollout.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: select mode: taint for untrusted input reaching shell execution, or a direct search rule if every shell call requires review.

Short answer

As of November 2026, pin Semgrep 1.186.0 (published November 18). Taint mode follows intermediate assignments within a function; interprocedural taint analysis is a Semgrep Pro feature. Model real request sources and shell sinks, then grow fixtures before expanding the gate. FORIMOC's April 25, 2026 report describes missed parameter-derived command strings; it does not prove the current engine misses every such route.

Choose / don't choose

  • Taint rule: choose when provenance distinguishes a legitimate constant command from request-derived execution. (taint guide).
  • Direct sink ban: choose when all calls need review, including constants; don't label each match an exploitable injection. exec uses a shell; execFile directly starts an executable by default (Node API).
  • Interprocedural analysis: choose the Pro capability for interprocedural taint analysis; interprocedural analysis tracks taint across multiple functions. A CE fallback is a separate explicit rule on the wrapper's dangerous implementation and direct wrapper-call policy (taint limits).

Not for: choosing scanners; see semgrep-codeql-gitleaks-trivy-or-osv-for-small-team-ci-2026.

Settings that matter

Setting or flagValue / defaultApplies toSource
modetaint for provenance-sensitive detection; search for a direct ban1.186.0rule syntax
pattern-sourcesList patterns for the actual request input expressions; use exact: true when only that expression is a source (default false)1.186.0taint
pattern-sinksList shell-invoking APIs; focus only the relevant function argument with focus-metavariable1.186.0argument sinks
languages[javascript, typescript] for this Node policy; add other actual application languages as separate fixtures1.186.0syntax
paths.include / paths.excludeInclude production and wrapper directories; exclude generated code only after establishing its role. Globs are relative to project root.1.186.0path filters
pattern-propagatorsFor a supported collection mutation, from: $E, to: $S with pattern $S.add($E); add only for an actual missing mutation flowSemgrep Pro; not a helper-body switchadvanced
--error / --strictEnable both for the production gate; --strict returns a nonzero exit code for WARN-level errorsCLI 1.186.0CLI

Use the official child-process rule as the import/API inventory, then adapt it to the project's request framework. For each request expression, populate pattern-sources; for child_process.exec or execSync, populate pattern-sinks. Add shell-enabled spawn explicitly if present; do not treat every execFile argument array as a shell sink. The pattern guide explains metavariables and ellipses; a binding named child_process alone does not promise all aliases or node: import forms.

A conservative parameter-source fragment from the registry rule is below; narrow it to actual request handlers before using it as an external-input policy. It focuses $FUNC in the matched function argument list, so trusted internal calls can otherwise produce findings:

mode: taint
pattern-sources:
  - patterns:
      - pattern-inside: function ... (...,$FUNC,...) { ... }
      - focus-metavariable: $FUNC
pattern-sinks:
  - pattern: child_process.exec($CMD,...)

Add the execSync alternative and focus $CMD with the documented sink pattern structure. This fragment belongs inside a rule with id/languages/message/severity; its named child_process binding is deliberately limited (registry rule, required schema).

Order of operations

1. Write one narrow rule with fields id, languages, message and severity. Keep wrappers inside the scan target and rule path filters. Model every import spelling and source expression that the policy claims. 2. Put fixtures beside the YAML using the same basename and a language extension. Place ruleid: <rule-id> immediately before expected matches and ok: <rule-id> immediately before allowed cases. Include direct input, an intermediate assignment, a helper route, constant commands, safe execFile arguments with shell: false, a shell-enabled subprocess, and unrelated regex .exec (fixture mechanism). Fixtures are scan input, not programs to execute. 3. Run semgrep --test rules/. Fix each false negative or positive before requiring the rule. A helper fixture that cannot be modeled remains a documented coverage gap, not an ok security assertion. 4. Then run semgrep scan --config rules/ --error --strict src/, replacing the target with all relevant production and wrapper directories. With --error, exit 1 means findings; exit 2 is fatal, 3 invalid target code, 4 invalid pattern, 5 unparseable YAML and 7 an invalid rule in the configuration. Fail scanner/configuration errors separately from findings (CLI).

Known failures and fixes

Error (short quote)CauseFixSource
native rules did not reach the relevant sink locationA reported parameter-derived command route lies outside that rule's source/sink coverageAdd the exact route to fixtures, model its real source and shell sink, and use supported interprocedural analysis or explicit wrapper rules for helper bodiesFORIMOC #3833
invalid patternExit 4 indicates a rule pattern error, not absence of findingsRepair language/pattern syntax, rerun fixtures, then the strict scanCLI

For an overly broad finding on a safe argument list, specify only the relevant function argument as the sink. For missing mutation flows, custom propagators connect the documented from/to values; ordinary assignments already propagate. Neither change proves that a sanitizer is correct.

Missing

  • No framework or wrapper signatures are specified here; source and sink patterns must match those actual signatures. Interprocedural taint analysis is a Semgrep Pro feature.

Checked

2026-11-24; Semgrep CE 1.186.0; rule, pattern, taint, advanced, fixture and CLI references, registry rule, Node API, release and FORIMOC report read. Earlier 1.181.0 release remains a version reference. No scan commands executed.

Started from a post by @Semgrep, packaged by the editor. Original post

Subjects

More in security

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Semgrep: catch untrusted input reaching shell execution
Summary: Use taint rules for request-derived shell commands, scope languages and paths explicitly, and preserve positive and negative fixtures for helpers and safe argument arrays. Enable the gate after `semgrep --test rules/`
Copy for agent
get the whatworks thread semgrep-enforce-project-command-execution-rule and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread semgrep-enforce-project-command-execution-rule
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp