Skip to content

Semgrep Executor

Category: Source Code Analysis Script: semgrep.py Integration: CLI Faraday Plugin: SemgrepPlugin Website: https://semgrep.dev/

Description

Runs a Semgrep static analysis (SAST) scan on a source code directory or Git repository and imports the findings into Faraday. By default it uses Semgrep's auto rule set, and you can switch to any rule pack or local rules file.

Prerequisites

  • semgrep installed and available in the agent's PATH (checked with semgrep --version)
  • git, if you scan a repository by URL
  • Read access to the source code, either as a local path or a Git repository

Configuration

Environment Variables (Setup)

Variable Required Description
GIT_USERNAME No Username for cloning private repositories over HTTPS (default: oauth2)
GIT_TOKEN No Access token for cloning private repositories over HTTPS

Execution Arguments

Parameter Type Mandatory Description
SEMGREP_TARGET string No* Path to scan. When SEMGREP_GIT_URL is set, it is a subpath inside the cloned repository (e.g., src/).
SEMGREP_CONFIG string No Comma-separated Semgrep configs: rule packs (e.g., p/owasp-top-ten, p/security-audit) or rule file paths (default: auto)
SEMGREP_EXCLUDE list No Glob patterns of files or directories to skip (e.g., ["tests/*", "vendor/*"])
SEMGREP_TIMEOUT integer No Maximum time in seconds that Semgrep spends on each rule per file
SEMGREP_GIT_URL string No* Git repository to clone and scan
SEMGREP_GIT_REF string No Branch or tag to clone (default: the repository's default branch)

* You must set SEMGREP_TARGET, SEMGREP_GIT_URL, or both.

YAML Configuration Example

executors:
  semgrep:
    repo_executor: semgrep.py
    max_size: 65536
    varenvs:
      GIT_USERNAME: "<git_username>"
      GIT_TOKEN: "<git_token>"
    params:
      SEMGREP_TARGET:
        mandatory: false
        type: string
        base: string
      SEMGREP_CONFIG:
        mandatory: false
        type: string
        base: string
      SEMGREP_EXCLUDE:
        mandatory: false
        type: list
        base: list
      SEMGREP_TIMEOUT:
        mandatory: false
        type: integer
        base: integer
      SEMGREP_GIT_URL:
        mandatory: false
        type: string
        base: string
      SEMGREP_GIT_REF:
        mandatory: false
        type: string
        base: string

How It Works

  1. If SEMGREP_GIT_URL is set, makes a shallow clone of the repository (at SEMGREP_GIT_REF, if given) into a temporary directory. For HTTPS URLs it authenticates with GIT_USERNAME/GIT_TOKEN.
  2. Runs semgrep scan --json with the configured rule sets, exclusions and timeout
  3. Parses the JSON output with SemgrepPlugin and sends the results to Faraday
  4. Deletes the temporary clone when the run ends

Notes

  • SEMGREP_TARGET must point inside the cloned repository. Paths that escape it (e.g., ../) are rejected.
  • The token is hidden in the agent log if the clone fails.
  • Supports the shared agent parameters (AGENT_CONFIG_* tags and severity filters).