Tutorial · DevSecOps & secure SDLC · Web application security
A DevSecOps pipeline in GitHub Actions – threat modeling, SAST (Semgrep, CodeQL), SCA (npm audit, OSV), CycloneDX SBOMs, Trivy, DAST and dependency updates
We build a GitHub Actions pipeline that checks the pierogi store's security on every pull request – secrets (gitleaks), static analysis (Semgrep with custom rules, CodeQL), dependencies (npm audit, signatures, dependency review), a CycloneDX SBOM, image and IaC scanning (Trivy), DAST (ZAP) on staging and safe updates (Renovate, Dependabot with a cooldown). Plus threat modeling during planning and triage rules, so the scanners help rather than get in the way.
The pierogi store ships changes several times a day. A once-a-year penetration test finds problems that have been in production for months, and a 40-page report lands on a team that has long forgotten how that code works. DevSecOps reverses the order: security is checked on every change, automatically, in the same place where developers see their test results. In this tutorial we build such a pipeline in GitHub Actions – and agree on rules so we don't drown in alerts.
Prerequisites: basic GitHub Actions, a Node.js project with package-lock.json and a Dockerfile, familiarity with the OWASP Top 10 and secrets management.
- 6
- pipeline jobs – secrets, 2× SAST, SCA, image, DAST
- 40 chars
- a SHA instead of a tag – GitHub Actions immune to tag moves
- 3 days
- cooldown for new versions – Renovate `minimumReleaseAge`, Dependabot `cooldown`
- 1.5
- CycloneDX spec version – from `npm sbom` in npm 11
- Plan Threat modeling – "What can go wrong?" for a new feature, abuse cases next to user stories
- Code IDE and pre-commit – security linters, gitleaks before commit, secure coding patterns
- Build SAST, SCA, SBOM – Semgrep, CodeQL, npm audit, dependency review, CycloneDX SBOM
- Test DAST – ZAP on staging, authorization tests with two accounts
- Release Integrity – image scanning, signing and provenance attestations for artifacts
- Deploy IaC and policies – Trivy config, cdk-nag, Access Analyzer, SCPs
- Operate Monitoring – WAF, GuardDuty, alarms on security events, dependency patching
Threat modeling: before the code exists
The cheapest security bug is the one never designed in. The 4-digit pickup codes from the OWASP Top 10 tutorial would pass every scanner – it's a design flaw, not a code flaw. Threat modeling doesn't have to be a heavy process: 30–60 minutes when planning a bigger feature, and Adam Shostack's four questions – what are we working on? what can go wrong? what are we going to do about it? did we do a good job?
| STRIDE | Threat in this flow | Control |
|---|---|---|
| Spoofing | someone impersonates the customer at pickup | 8-character code, attempt limit, last digits of the phone number |
| Tampering | changing the amount or items after payment | values computed on the server, not taken from the body |
| Repudiation | "I never collected the order" | an order.collected event with the cashier ID and time |
| Information disclosure | other people's orders by changing the ID (BOLA) | owner in every query |
| Denial of service | a bot booking every pickup slot | per-account and per-device limits |
| Elevation of privilege | a customer calls the cashier's "hand over" endpoint | roles, a separate token for the tablet |
The outcome of the session isn't a document for a drawer but backlog items and test cases. Mermaid in the repository or OWASP Threat Dragon is enough for the diagrams.
Step 1. The workflow: six jobs
GitHub Actions workflow: secrets, SAST, SCA, image and DAST
name: devsecops
on:
pull_request:
push:
branches: [main]
permissions:
contents: read # every job starts read-only; jobs ask for more explicitly
concurrency:
group: devsecops-${{ github.ref }}
cancel-in-progress: true
jobs:
secrets:
name: Secrets (gitleaks)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
- run: docker run --rm -v "$PWD:/repo" ghcr.io/gitleaks/gitleaks:v8.30.1 git /repo --redact --exit-code 1
sast-semgrep:
name: SAST (Semgrep)
runs-on: ubuntu-latest
permissions:
contents: read
security-events: write # upload SARIF to the Security tab
container:
image: semgrep/semgrep:1.187.0
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- run: semgrep scan --config p/default --config p/typescript --config .semgrep/ --severity ERROR --error --sarif --output semgrep.sarif
- uses: github/codeql-action/upload-sarif@915412ff23e8b7659517e607487dbeae018f2934 # v4.39.5
if: always()
with:
sarif_file: semgrep.sarif
category: semgrep
sast-codeql:
name: SAST (CodeQL)
runs-on: ubuntu-latest
permissions:
contents: read
security-events: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: github/codeql-action/init@915412ff23e8b7659517e607487dbeae018f2934 # v4.39.5
with:
languages: javascript-typescript
build-mode: none
queries: security-extended
- uses: github/codeql-action/analyze@915412ff23e8b7659517e607487dbeae018f2934 # v4.39.5
sca:
name: Dependencies (npm audit, dependency review)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 24
cache: npm
- run: npm ci --ignore-scripts # install scripts of 1,000 dependencies don't run in CI
- run: npm audit signatures # registry signatures and provenance attestations
- run: npm audit --omit=dev --audit-level=high
- if: github.event_name == 'pull_request'
uses: actions/dependency-review-action@bbc44d14a204704ccc493733616cd1e93a0321ec # v5.0.1
with:
fail-on-severity: high
deny-licenses: AGPL-3.0-only, GPL-3.0-only
image:
name: Image (SBOM, Trivy)
runs-on: ubuntu-latest
needs: [secrets, sca]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 24
cache: npm
- run: npm ci --ignore-scripts
- run: npm sbom --sbom-format cyclonedx --omit dev > sbom.cdx.json
- run: docker build -t pierogi-api:${{ github.sha }} .
- name: Trivy – vulnerabilities in the image
uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0
with:
image-ref: pierogi-api:${{ github.sha }}
severity: HIGH,CRITICAL
ignore-unfixed: true
exit-code: '1'
trivyignores: .trivyignore
- name: Trivy – Dockerfile and IaC misconfigurations
uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0
with:
scan-type: config
scan-ref: .
severity: HIGH,CRITICAL
exit-code: '1'
skip-setup-trivy: true
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: sbom-${{ github.sha }}
path: sbom.cdx.json
dast:
name: DAST (ZAP baseline on staging)
if: github.ref == 'refs/heads/main'
needs: [image] # in a real pipeline: after the deploy-to-staging job
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: zaproxy/action-baseline@de8ad967d3548d44ef623df22cf95c3b0baf8b25 # v0.15.0
with:
target: https://staging.pierogarnia.example
allow_issue_writing: false
fail_action: trueThe rest of this article is for members
Create a free account or sign in to read it all. Still ahead:
- Step 2. SAST: Semgrep and CodeQL
- Step 3. Dependencies: npm audit, signatures, dependency review and an SBOM
- Step 4. Image and IaC: Trivy
- Step 5. DAST: ZAP on staging
- Step 6. Dependency updates without the risk
- Triage: rules that save the pipeline
- Common mistakes
- Test yourself
- What's next