GitLab SAST - Semgrep Analyzer

Overview

What is GitLab SAST?

GitLab Static Application Security Testing (SAST) is an integrated security feature that automatically scans your source code for potential security vulnerabilities as part of your CI/CD pipeline.

GitLab's Built-in Semgrep Scanner

GitLab SAST includes Semgrep as one of its primary static analysis engines. When you enable GitLab SAST, the Semgrep analyzer automatically:

  1. Scans your codebase for security vulnerabilities

  2. Generates detailed findings

  3. Integrates results into GitLab's security dashboard

Mobb Integration with GitLab SAST (Semgrep)

Mobb enhances GitLab SAST by providing automated vulnerability fixing capabilities. While GitLab SAST identifies security issues, Mobb goes further by:

  • Automatically generating fixes for Semgrep-detected vulnerabilities

  • Providing contextual explanations for each fix

  • Maintaining code functionality while addressing security concerns

How the Integration Works

  1. GitLab SAST runs Semgrep and generates a SARIF report

  2. Mobb analyzes the SARIF findings and generates appropriate fixes

  3. Fix Report URL will be provided in the Gitlab runner console log

  4. Developers review and create Merge Requests on the security enhancements from Mobb UI

Sample GitLab CI/CD Configuration

Below is a complete .gitlab-ci.yml configuration that integrates GitLab SAST (Semgrep) with Mobb's automated fixing capabilities:

Configuration Breakdown

Pipeline Structure

  • test stage: Required by GitLab SAST template

  • sast-scan stage: Runs Semgrep analysis

  • mobb-autofixer stage: Processes findings and applies fixes

Workflow Rules

The pipeline triggers on:

  • Merge request events

  • Manual web triggers

Semgrep SAST Job

  • Extends: Uses GitLab's built-in SAST analyzer

  • Artifacts: Preserves SARIF reports for Mobb processing

  • Output: Generates semgrep.sarif file

circle-exclamation

Mobb Autofixer Job

  • Dependencies: Waits for SARIF artifacts from Semgrep

  • Validation: Checks for SARIF file existence

  • Execution: Runs Mobb analysis and auto-fixing

Required Environment Variables

Set these variables in your GitLab project settings:

Variable
Description

MOBB_API_TOKEN

Your Mobb API token for authentication (How to create API tokens)

Mobb CLI Parameters Explained

Parameter
Description

-f semgrep.sarif

Input SARIF file from GitLab SAST

-r "$CI_PROJECT_URL"

Repository URL for context

--ref "$CI_COMMIT_REF_NAME"

Branch/ref being analyzed

--mobb-project-name "GitLab-Fix-Reports"

Project identifier in Mobb

--api-key "$MOBB_API_TOKEN"

Authentication token

--ci

CI/CD mode for optimized execution

Last updated