The vulnerabilities you inherit from your libraries.
Intermediate12 min · lesson 13 of 17
Lesson files
The scripts, test data and local test servers this lesson uses, exactly as they ran on the lab machine (17 files, 6 KB): sca.tar.gz. The lab VM shares no folders with your computer, so fetch them inside the VM: cd ~/lab && curl -fsSLO https://secopslog.com/lab-files/ci-gitlab/sca.tar.gz && tar -xzf sca.tar.gz, which creates ~/lab/sca/. SHA-256: 509fe9ed0298b5934624f58e35f1f4be4e5b812b289cdd68002c7cebddace6b7
Most of the code your application runs, someone else wrote. A three-line requirements.txt can pull in dozens of packages, and every one of them has its own history of security fixes. Dependency scanning, often called software composition analysis (SCA), compares the versions you pin with databases of known vulnerabilities. It can only check what it can see, though. Scanning requirements.txt checks the three packages listed there, not the dozens they pull in. For those, scan a lock file with every version pinned (from pip-compile, uv or Poetry), or the built image, which the container scanning lesson does. GitLab's own dependency scanning needs the Ultimate tier, so this lab runs Trivy in an ordinary job, which works on any tier.
Trivy in a job
app/requirements.txt
requests==2.19.1
pyyaml==5.3
jinja2==3.1.6
Two of these pins are years old. The job:
app/.gitlab-ci.yml
# Dependency scanning with Trivy. GitLab's own dependency scanning needs the Ultimate tier;
# this job runs on any tier. The vulnerability database is kept in the cache between pipelines.
The Trivy image is pinned by digest, so the tool changes only when the pin does. (GitLab's own scanner templates use moving major-version tags. The SAST lesson's hands-on shows how to pin one.) The job runs three commands: trivy fs scans and writes JSON, the first trivy convert prints the High and Critical findings for people, and the second is the gate, failing the job on the same JSON. Trivy needs its vulnerability database, a large download, so the job keeps it in the cache.
ubuntu@secopslog-cicd:~/lab/sca · GitLab 19.5.3
$./up.sh
runner lab-runner: online (tags: lab,docker)
GitLab 19.5.3 is up on http://127.0.0.1:8929
pushed app: 383e4d1 first commit
--- job dependency-scan (test): failed
Restoring cache
Checking cache for trivy-db-protected...
No URL provided, cache will not be downloaded from shared cache server. Instead a local version of cache will be extracted.
WARNING: Cache file does not exist
Failed to extract cache
$ trivy fs --scanners vuln --format json --output trivy.json .
2026-11-10T23:09:30Z INFO [vulndb] Need to update DB
2026-11-10T23:09:30Z INFO [vulndb] Downloading vulnerability DB...
2026-11-10T23:09:30Z INFO [vulndb] Downloading artifact... repo="mirror.gcr.io/aquasec/trivy-db:2"
2026-11-10T23:13:52Z INFO [vulndb] Artifact successfully downloaded repo="mirror.gcr.io/aquasec/trivy-db:2"
2026-11-10T23:13:52Z INFO [vuln] Vulnerability scanning is enabled
2026-11-10T23:13:52Z WARN [pip] Unable to find python `site-packages` directory. License detection is skipped. err="unable to find path to Python executable"
2026-11-10T23:13:52Z INFO Number of language-specific files num=1
2026-11-10T23:13:52Z INFO [pip] Detecting vulnerabilities...
$ trivy convert --format table --severity HIGH,CRITICAL trivy.json
2026-11-10T23:13:52Z WARN [report] No enabled scanners found. Summary table will not be displayed.
requirements.txt (pip)
======================
Total: 3 (HIGH: 1, CRITICAL: 2)
┌──────────┬────────────────┬──────────┬────────┬───────────────────┬───────────────┬──────────────────────────────────────────────────────────────┐
│ Library │ Vulnerability │ Severity │ Status │ Installed Version │ Fixed Version │ Title │
├──────────┼────────────────┼──────────┼────────┼───────────────────┼───────────────┼──────────────────────────────────────────────────────────────┤
│ pyyaml │ CVE-2020-14343 │ CRITICAL │ fixed │ 5.3 │ 5.4 │ PyYAML: incomplete fix for CVE-2020-1747 │
│ │ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2020-14343 │
│ ├────────────────┤ │ │ ├───────────────┼──────────────────────────────────────────────────────────────┤
│ │ CVE-2020-1747 │ │ │ │ 5.3.1 │ PyYAML: arbitrary command execution through │
│ │ │ │ │ │ │ python/object/new when FullLoader is used │
│ │ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2020-1747 │
├──────────┼────────────────┼──────────┤ ├───────────────────┼───────────────┼──────────────────────────────────────────────────────────────┤
│ requests │ CVE-2018-18074 │ HIGH │ │ 2.19.1 │ 2.20.0 │ python-requests: Redirect from HTTPS to HTTP does not remove │
│ │ │ │ │ │ │ Authorization header │
│ │ │ │ │ │ │ https://avd.aquasec.com/nvd/cve-2018-18074 │
└──────────┴────────────────┴──────────┴────────┴───────────────────┴───────────────┴──────────────────────────────────────────────────────────────┘
$ trivy convert --format table --severity HIGH,CRITICAL --exit-code 1 trivy.json > /dev/null
2026-11-10T23:13:53Z WARN [report] No enabled scanners found. Summary table will not be displayed.
Saving cache for failed job
Creating cache trivy-db-protected...
.trivycache/: found 4 matching artifact files and directories
No URL provided, cache will not be uploaded to shared cache server. Cache will be stored only locally.
Created cache
Uploading artifacts...
trivy.json: found 1 matching artifact files and directories
Uploading artifacts as "archive" to coordinator... 201 Created correlation_id=01M73VTWKB11RG7SXZ0AG1G3AM id=1 status=201 token=64_3uzLSK
ERROR: Job failed: exit code 1
pipeline #1: failed
There was no cache yet, so Trivy downloaded its database first, which took 4 minutes 22 seconds here (from Downloading artifact... to Artifact successfully downloaded). It found three High or Critical findings in requirements.txt: two Critical ones in PyYAML 5.3, both fixed in later 5.x releases, and a High one in requests 2.19.1, fixed in 2.20.0. The Status and Fixed Version columns matter as much as the severity: each of these has a fix, so the remedy is an upgrade. The gate failed the job, and because of cache: when: always the runner still saved the database (Saving cache for failed job). The No enabled scanners found warnings come from trivy convert, which only reformats the JSON and scans nothing itself, so they are harmless. The JSON report counts everything, including severities the table left out:
Four Medium findings didn't fail the gate, because it only looks at High and Critical. That is a decision, so the job carries a comment saying so, where the next person to read it will find it.
With current versions the job passed, and the report now lists no vulnerabilities at all, so the count prints nothing. This time the runner found the cache (Successfully extracted cache), and the log has no vulndb lines: Trivy used the stored database instead of downloading it again.
Cache detail
Why it matters
Saved only after successful jobs, unless cache: when: always
A scan that fails the gate would otherwise throw its database away
Separate caches for protected and unprotected refs
A branch job can't poison the cache main uses, and it doesn't get main's cache either
Local to the runner here (no shared cache server)
Another runner starts empty
Only a speed-up
Without a cache, Trivy downloads the database and the scan still works
Watch out
A passing scan means "no known vulnerabilities in these versions, according to today's database". A new advisory tomorrow makes the same commit fail. Run the scan on a schedule as well as on pushes, so you hear about new advisories for code nobody is changing.
Hands-on
Run the pipeline again with no change, using ./run-pipeline.sh app and then ./pipeline.sh app/, and read the cache lines and Trivy's database lines in the log. Did the job download the database this time? Finish with ./down.sh.
What you should see: Successfully extracted cache again, no vulndb download lines, and the job saved the cache again at the end. Compare the four-minute download in the first run. The database ages, though: when the stored copy is older than Trivy's update interval, the next run downloads a fresh one once and the cache picks it up.
Remember
Scan dependencies on every push and on a schedule, run the scanner from a pinned image, keep its database in a cache that is saved even when the gate fails, and fix findings by upgrading, not by raising the threshold.
Quick check
01Why does the lab set cache: when: always on the scan job?
Incorrect — Caches are per project either way.
Incorrect — It downloads the database when there is none.
Correct — By default the cache is saved only after a successful job, and a scan that fails the gate would lose the database. In the lab the failed first scan still saved its database (Saving cache for failed job), and the next run extracted it.
Incorrect — Forks never get the parent's cache.
02A dependency scan passed last month. Today, with no code change, the same commit fails. What most likely changed?
Correct — A scan result is only as current as its database.
Incorrect — Scans are deterministic for the same database.
Incorrect — A cache only saves time.
Incorrect — GitLab does not edit scanner results.
03On the Free tier, how does this lab get dependency scanning?