Every change that reaches production went through your pipeline, which makes the pipeline the cheapest place to catch security problems. A leaked key found in a merge request costs one force-push and one rotation. The same key found by an attacker costs an incident. GitLab ships a family of scanners you can add in a few lines. This lesson adds them to Orbit, explains what each one finds and covers the other half of the story: securing the pipeline itself.
The scanners at a glance
| Scanner | Looks at | Finds | Typical stage |
|---|---|---|---|
| Secret detection | Repository content and commits | API keys, tokens, private keys | test |
| SAST | Source code | Injection, unsafe functions, weak crypto | test |
| Dependency scanning | Lock files and manifests | Known CVEs in libraries | test |
| Container scanning | The built image | CVEs in OS packages and runtimes | after the image build |
| DAST | The running app | Missing headers, injection, auth issues seen from outside | after deploying a review app |
| IaC scanning | Terraform, Kubernetes, CloudFormation files | Misconfigurations like public buckets | test |
Adding scanners with templates
GitLab maintains ready-made jobs for each scanner. Include them and they appear in your pipeline:
stages: [build, test, package, deploy, verify]
include:
- template: Jobs/Secret-Detection.gitlab-ci.yml
- template: Jobs/SAST.gitlab-ci.yml
- template: Jobs/Dependency-Scanning.gitlab-ci.yml
- template: Jobs/Container-Scanning.gitlab-ci.yml
The templates detect your languages and only add the relevant analyzers. For Orbit they add a Node.js SAST job, a secret detection job, a dependency scanning job that reads package-lock.json (it only runs on Ultimate and is skipped on other tiers), and a container scanning job.
The jobs land in the test stage by default, so that stage must exist. Container scanning needs to know which image to scan:
container_scanning:
needs: [build-image]
variables:
CS_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA
The same thing with CI/CD components
GitLab also publishes these scanners as CI/CD components in the CI/CD Catalog. Components are versioned and take typed inputs, so you pin exactly what you run:
include:
- component: $CI_SERVER_FQDN/components/secret-detection/secret-detection@~latest
- component: $CI_SERVER_FQDN/components/sast/sast@~latest
Replace ~latest with a specific version for reproducible pipelines. Lesson 12 explains components in depth.
What you get on each tier
SAST, secret detection and container scanning run on every tier. What changes is how you see and manage the results, plus a few scanners reserved for Ultimate:
| Free | Ultimate | |
|---|---|---|
| Run SAST, secret detection, container scanning | Yes | Yes |
| Download the JSON reports from the job | Yes | Yes |
| Findings in the merge request widget | No | Yes |
| Vulnerability report, dismissals, triage | No | Yes |
| Dependency scanning, DAST, security policies | No | Yes |
On Free, the scanners are still valuable: make the job fail on findings and read the report artifact. On Ultimate, findings show up inline in the merge request with severity, location and suggested fixes.
Secret detection
Secret detection scans files for patterns of well-known credentials: cloud keys, GitLab tokens, Slack webhooks, private keys and many more. In merge request pipelines it checks the commits of the merge request; in branch pipelines it scans the latest content.
Two extra layers stop leaks earlier:
- Secret push protection (Ultimate) blocks a
git pushthat contains a high-confidence secret before it ever reaches the repository. - A local pre-commit hook with a scanner such as
gitleakscatches mistakes on the developer’s machine.
A detected secret is a leaked secret. Removing it from the file or even rewriting history does not undo the leak: clones, forks and caches may already have it. Revoke and rotate the credential first, then clean up.
To scan the entire history once, for example when adopting the scanner on an old repository:
secret_detection:
variables:
SECRET_DETECTION_HISTORIC_SCAN: "true"
SAST
Static application security testing reads source code without running it, looking for patterns like SQL built from strings, eval on user input, disabled TLS verification or weak hashing. GitLab’s SAST uses a Semgrep-based analyzer with GitLab-maintained rules for most languages.
Typical things it flags in a Node.js API:
// Flagged: user input concatenated into SQL
db.query("SELECT * FROM notes WHERE owner = '" + req.query.owner + "'");
// Fixed: parameterised query
db.query("SELECT * FROM notes WHERE owner = $1", [req.query.owner]);
Expect false positives. Triage each one: fix it, or dismiss it with a reason so it does not come back. A noisy scanner that nobody reads protects nothing.
Dependency and container scanning
Most code in Orbit’s image is not Orbit’s: hundreds of npm packages and an Alpine base with its own libraries. Two scanners cover them:
- Dependency scanning reads lock files and reports libraries with known vulnerabilities, with the version that fixes them. It can also produce a CycloneDX SBOM, a list of everything you ship.
- Container scanning looks inside the built image, including OS packages your lock file never mentions.
Act on the results with a few habits:
- Update the base image regularly (
node:24-alpinegets patched often) and rebuild even when your code has not changed. A weekly scheduled pipeline does this. - Pin images by digest and let a bot such as Renovate open merge requests when a new digest is published.
- Fix what is reachable and exploitable first. A critical CVE in a test-only dependency is less urgent than a medium one in your request parser.
DAST
Dynamic testing attacks a running app from the outside, like a scanner on the internet would. Point it at the review app from lesson 7:
include:
- template: DAST.gitlab-ci.yml
dast:
stage: verify
needs: [deploy-review]
variables:
DAST_TARGET_URL: https://$CI_COMMIT_REF_SLUG.review.orbit.example.com
DAST_FULL_SCAN: "false"
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
A passive scan only observes responses and is safe to run anywhere. An active full scan sends attack payloads, so only run it against environments built for it, never production. DAST requires Ultimate.
Making findings block merges
Scanners that only report get ignored. Decide what blocks a merge:
- On Ultimate: a merge request approval policy requires security approval when a scan finds, say, new critical or high vulnerabilities. A pipeline execution policy or scan execution policy forces scanners into every project of a group, so nobody can quietly delete them from
.gitlab-ci.yml. GitLab 19 added security configuration profiles to switch on secret detection, SAST and dependency scanning across projects through policy instead of editing every pipeline. - On Free: add a small job that reads the JSON report and fails on high-severity findings.
sast-gate:
stage: test
image: alpine:3
needs:
- job: semgrep-sast
artifacts: true
script:
- apk add --no-cache jq
- HIGH=$(jq '[.vulnerabilities[] | select(.severity=="Critical" or .severity=="High")] | length' gl-sast-report.json)
- echo "High or critical findings - $HIGH"
- test "$HIGH" -eq 0
Securing the pipeline itself
Attackers increasingly target CI/CD because it holds the keys to production. Scanners do not protect you from these risks; configuration does:
- **Protect
mainand release tags.** Only maintainers merge; nobody pushes directly. - Protected variables and runners for anything that can reach production (lessons 4 and 5).
- OIDC instead of stored cloud keys (lesson 11).
- Pin images and includes.
include: remote:or an unpinned component can change under you; pin versions or commit SHAs. - **Review changes to
.gitlab-ci.yml** with a CODEOWNERS rule so the platform team approves them. - Limit the job token allowlist to projects that really need access.
- Do not run untrusted fork pipelines with access to secrets. Merge requests from forks run in the fork by default; keep it that way unless a maintainer explicitly approves.
- Minimal job images. Fewer tools in the image means fewer tools for an attacker.
.gitlab/CODEOWNERS
/.gitlab-ci.yml @orbit-team/platform
/ci/ @orbit-team/platform
Exercise
Secret detection flags an AWS access key in a merge request. The developer deletes the line and pushes again. Is the problem solved?
Show answer
Answer: C. Once a secret is pushed, assume it is compromised. Revoke it first, issue a new one through a safe channel, then clean the history if you want to. Deleting the line only hides it from the latest version.
Exercise
Which scanner would find a vulnerable version of OpenSSL inside the Alpine base image of Orbit’s container?
Show answer
Answer: D. OS packages in the base image are not in your source code or your npm lock file. Only scanning the built image sees them.
Key takeaways
- Secret detection, SAST, dependency, container and DAST scans each cover a different blind spot.
- Add them with GitLab’s templates or versioned CI/CD components in a few lines.
- SAST, secret detection and container scanning run on every tier; Ultimate adds dependency scanning, DAST, merge request findings, triage and policies.
- A leaked secret must be rotated, not just deleted.
- Make high-severity findings block merges, with policies or a simple gate job.
- Protect the pipeline itself: protected branches, runners and variables, OIDC, pinned includes and CODEOWNERS on CI files.
FAQ
Will these scanners slow my pipeline down?
Each adds a job that runs in parallel with your tests, typically one to three minutes. Because they run alongside other test jobs, the total pipeline time barely changes.
Why does SAST report so many low-severity findings?
Rules err on the side of caution. Triage once, dismiss what does not apply with a reason, and configure the gate to block only on high and critical findings so the noise does not block work.
Do I need DAST if I already run SAST?
They find different problems. SAST sees code paths, DAST sees what the running app actually exposes: headers, cookies, server configuration, auth flows. Mature teams use both.
Can I use other tools like Trivy, Snyk or Semgrep directly?
Yes. Any tool that runs in a container can be a job. If it produces GitLab’s report format (many can), its findings join the same reports and policies.
How often should I rebuild images for security fixes?
At least weekly with a scheduled pipeline, plus immediately for critical CVEs in your base image. Rebuilding picks up patched base layers even when your code did not change.