Sast semgrep

From aiskillstore/marketplace · View interactive version

Sast semgrep is an AI agent skill from the GitHub repository aiskillstore/marketplace. Static application security testing (SAST) using Semgrep for vulnerability detection, security code review, and secure coding guidance with OWASP and CWE framework mapping. Use when: (1) Scanning code for security vulnerabilities across multiple languages, (2) Performing security code reviews with p

How to use this skill

Skill file

SAST with Semgrep

Overview

Perform comprehensive static application security testing using Semgrep, a fast, open-source

static analysis tool. This skill provides automated vulnerability detection, security code

review workflows, and remediation guidance mapped to OWASP Top 10 and CWE standards.

Quick Start

Scan a codebase for security vulnerabilities:

semgrep --config=auto --severity=ERROR --severity=WARNING /path/to/code

Run with OWASP Top 10 ruleset:

semgrep --config="p/owasp-top-ten" /path/to/code

Core Workflows

Workflow 1: Initial Security Scan

  1. Identify the primary languages in the codebase
  2. Run scripts/semgrep_scan.py with appropriate rulesets
  3. Parse findings and categorize by severity (CRITICAL, HIGH, MEDIUM, LOW)
  4. Map findings to OWASP Top 10 and CWE categories
  5. Generate prioritized remediation report

Workflow 2: Security Code Review

  1. For pull requests or commits, run targeted scans on changed files
  2. Use semgrep --diff to scan only modified code
  3. Flag high-severity findings as blocking issues
  4. Provide inline remediation guidance from references/remediation_guide.md
  5. Link findings to secure coding patterns

Workflow 3: Custom Rule Development

  1. Identify organization-specific security patterns to detect
  2. Create custom Semgrep rules in YAML format using assets/rule_template.yaml
  3. Test rules against known vulnerable code samples
  4. Integrate custom rules into CI/CD pipeline
  5. Document rules in references/custom_rules.md

Workflow 4: CI/CD Integration

  1. Add Semgrep to CI/CD pipeline using assets/ci_config_examples/
  2. Configure baseline scanning for pull requests
  3. Set severity thresholds (fail on CRITICAL/HIGH)
  4. Generate SARIF output for security dashboards
  5. Track metrics: vulnerabilities found, fix rate, false positives

Security Considerations

secrets or proprietary code patterns. Use --max-lines-per-finding to limit output.

result access to authorized security and development teams.

findings count for compliance auditing.

Maintain scan history and remediation tracking.

applications, use --config="p/security-audit" for comprehensive coverage.

Language Support

Semgrep supports 30+ languages including:

Bundled Resources

Scripts

References

Assets

Common Patterns

Pattern 1: Daily Security Baseline Scan

# Run comprehensive scan and generate report
scripts/semgrep_scan.py --config security-audit \
  --output results.json \
  --format json \
  --severity HIGH CRITICAL

Pattern 2: Pull Request Security Gate

# Scan only changed files, fail on HIGH/CRITICAL
scripts/diff_scan.sh --fail-on high \
  --base-branch main \
  --output sarif

Pattern 3: Vulnerability Research

# Search for specific vulnerability patterns
semgrep --config "r/javascript.lang.security.audit.xss" \
  --json /path/to/code | jq '.results'

Pattern 4: Custom Rule Validation

# Test custom rule against vulnerable samples
semgrep --config assets/custom_rules.yaml \
  --test tests/vulnerable_samples/

Integration Points

CI/CD Integration

See assets/ci_config_examples/ for ready-to-use configurations.

Security Tool Integration

SDLC Integration

Severity Classification

Semgrep findings are classified by severity:

Performance Optimization

For large codebases:

# Use --jobs for parallel scanning
semgrep --config auto --jobs 4

# Exclude vendor/test code
semgrep --config auto --exclude "vendor/" --exclude "test/"

# Use lightweight rulesets for faster feedback
semgrep --config "p/owasp-top-ten" --exclude-rule "generic.*"

Troubleshooting

Issue: Too Many False Positives

Solution:

Issue: Scan Taking Too Long

Solution:

Issue: Missing Vulnerabilities

Solution:

Advanced Usage

Creating Custom Rules

See references/rule_library.md for guidance on writing effective Semgrep rules.

Use assets/rule_template.yaml as a starting point.

Example rule structure:

rules:
  - id: custom-sql-injection
    patterns:
      - pattern: execute($QUERY)
      - pattern-inside: |
          $QUERY = $USER_INPUT + ...
    message: Potential SQL injection from user input concatenation
    severity: ERROR
    languages: [python]
    metadata:
      cwe: "CWE-89"
      owasp: "A03:2021-Injection"

OWASP Top 10 Coverage

This skill provides detection for all OWASP Top 10 2021 categories.

See references/owasp_cwe_mapping.md for complete coverage matrix.

Best Practices

  1. Baseline First: Establish security baseline before enforcing gates
  2. Progressive Rollout: Start with HIGH/CRITICAL, expand to MEDIUM over time
  3. Developer Training: Educate team on common vulnerabilities and fixes
  4. Rule Maintenance: Regularly update rulesets and tune for your stack
  5. Metrics Tracking: Monitor vulnerability trends, MTTR, and false positive rate
  6. Defense in Depth: Combine with DAST, SCA, and manual code review

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.