Skip to content

Secrets and Licences

The last two scanners ask questions that are not about flaws in code at all. The secret scanner reads files the way a burglar would — looking for credentials worth stealing. The license scanner reads your dependencies the way a lawyer would — asking what you have agreed to by using them. Both run inside the same command and report in the same shapes as everything else in this guide.

The secret that was not caught

The lab's first secret fixture, trivy-lab/fixtures/secret-demo, is a notes file containing the most famous credentials in the world: the example AWS key pair from Amazon's own documentation (AKIAIOSFODNN7EXAMPLE and its matching secret), which Amazon publishes precisely so that examples have something harmless to show.

trivy fs --scanners secret trivy-lab/fixtures/secret-demo

Check (transcript trivy-lab/transcripts/t09-secret-scan.txt):

INFO [report] No issues detected with scanner(s). scanners=[secret]

Nothing. And nothing is correct — Trivy's secret rules deliberately ignore the famous published example credentials. They appear in a million tutorials; flagging them would train everyone to ignore the scanner. But hold the lesson at full strength: a clean secret scan is not proof that a file holds no secrets. It is proof that the file holds no secrets the scanner recognises — and the world's most-printed key pair is, by design, one it chooses not to recognise.

The secret that was

The second fixture, trivy-lab/fixtures/secret-demo2, holds an AWS-shaped key pair the lab invented for the occasion — random characters in the right shapes, never a real credential:

trivy fs --scanners secret trivy-lab/fixtures/secret-demo2

Check: Total: 2 (CRITICAL: 2). Both halves caught, each reported with its rule name, its severity, and the exact place it lives:

CRITICAL: AWS (aws-access-key-id)
AWS Access Key ID
 backup-config.ini:6 (offset: 182 bytes)
   5   [backup]
   6 [ aws_access_key_id = ********************
   7   aws_secret_access_key = ****************************************

Two details deserve a look. The values are masked in the report: the scanner shows you where the secret is without printing the secret — a report can be pasted into a ticket without becoming a leak itself. And the scan is fast and local: credentials are recognised by their shapes and by rules per provider (GitHub tokens, Slack tokens, private keys and many more ship with the tool), plus generic checks for suspicious assignments. What it cannot do is recognise a secret with no known shape — your own product's home-grown token format is invisible to it unless you add a rule, a limit chapter 13 states plainly.

A secret found by this scanner in a real project is not a tidy-up task. The correct response is to treat the credential as compromised: revoke and reissue it, then remove it from the file — and from the git history, where deleting the line does not reach (chapter 11 has the recipe-shaped version).

The licence inventory

The licence scanner answers a different audit: what are the terms of the code we depend on? Licences fall into families — permissive ones that ask mainly for attribution (notice in Trivy's classification), and restrictive ones that can oblige you to share your own source or avoid the combination entirely.

One wrinkle first, and the lab met it head-on: the scanner reads the licence information recorded in installed packages, and a lock file alone does not carry it. Scan the JavaScript fixture as it ships and the report is empty, with the startup lines telling you why — npm projects must be installed to collect licence information, and the Python scan in chapter 4 printed its own warning that licence detection was skipped for want of an installed site-packages. So the lab installed the fixture for real (four small packages) and scanned the result:

trivy fs --scanners license trivy-lab/oldjs-installed

(oldjs-installed is generated by that npm install, not shipped; examples/lab-notes.txt has the steps.) Check (transcript trivy-lab/transcripts/t10-license-scan.txt):

package-lock.json (license)
Total: 4 (UNKNOWN: 0, LOW: 4, MEDIUM: 0, HIGH: 0, CRITICAL: 0)

│ ini      │ ISC     │ notice │
│ lodash   │ MIT     │ notice │
│ y18n     │ ISC     │ notice │

MIT and ISC are permissive licences, classified notice and rated LOW: keep the attribution, and you are keeping the terms. In a project with a restrictive licence in its tree, the same table carries it at higher severity with its family named — and chapter 9's exit-code machinery can gate a build on licence classes you will not accept, just as it gates on vulnerabilities.