4 Hours

8. Security Scanning in CI/CD: SAST, DAST, and SCA

Security

Security scanning is an essential part of modern CI/CD pipelines. It catches vulnerabilities before they reach production. This module covers three types of security scanning: SAST (Static Application Security Testing), DAST (Dynamic Application Security Testing), and SCA (Software Composition Analysis).

The key insight is that security scanning should be integrated into the CI/CD pipeline, not performed as a separate process. This shift-left approach catches vulnerabilities early, when they're cheaper to fix. Understanding security scanning is essential for building secure CI/CD pipelines.

This module covers each type of scanning, integration in CI/CD, and best practices for security.

Types of Security Scanning

SAST analyzes source code for vulnerabilities without executing the application. It catches issues like SQL injection, XSS, and insecure dependencies. DAST tests running applications by simulating attacks. It finds runtime vulnerabilities like insecure configurations. SCA analyzes open-source dependencies for known vulnerabilities. It catches outdated or vulnerable libraries. Each type catches different types of vulnerabilities, and they should all be used together.

  • SAST (Static Analysis): Analyzes source code for vulnerabilities before runtime.
  • DAST (Dynamic Analysis): Tests running applications by simulating attacks.
  • SCA (Software Composition Analysis): Analyzes open-source dependencies for known vulnerabilities.
  • Container Scanning: Scans container images for vulnerabilities.
  • Secret Scanning: Detects hardcoded secrets in code.

Step-by-Step: Security Scanning Integration

Follow these steps to integrate security scanning into your CI/CD pipeline.

GitHub Actions with CodeQL:
name: <strong><code>CodeQL

on: [push, pull_request]

jobs:
analyze:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: github/codeql-action/init@v2
with:
languages: javascript, python
- uses: github/codeql-action/analyze@v2

SCA with Dependabot:
Create .github/dependabot.yml:
version: 2<br>updates:<br> - package-ecosystem: <strong><code>npm
directory: /
schedule:
interval: weekly
open-pull-requests-limit: 10

Container Scanning with Trivy:
steps:<br> - uses: actions/checkout@v4<br> - name: Build image<br> run: docker build -t myapp .<br> - name: Scan image<br> uses: aquasecurity/trivy-action@master<br> with:<br> image-ref: myapp<br> format: <strong><code>sarif
output: trivy-results.sarif

SAST with Semgrep:
steps:<br> - uses: actions/checkout@v4<br> - name: Run Semgrep<br> uses: returntocorp/semgrep-action@v1<br> with:<br> config: p/security-audit

Try It Yourself: Add security scanning to your CI/CD pipeline. Identify and fix vulnerabilities found by the scans. Monitor the security dashboard for your repository.

Knowledge Check

Ready to test your understanding of 8. Security Scanning in CI/CD: SAST, DAST, and SCA?

Back