Skip to content
mentoor

Topic 3 of 5 · 5 min read

Dependency and secret scanning

Goal: Interpret a dependency or secret scan report on an agent's change and choose which findings block the merge.

Agents add packages and handle credentials without thinking twice, so scan every change for known-vulnerable dependencies and for leaked secrets, and block the merge when the finding is real.

Check yourself · 1 of 3

An agent commits a live API key in a test file. What must happen besides removing the line?

Choose one answer

Why it matters

Two things happen often. An agent needs a library and adds one, sometimes an old version from its training data, sometimes a package name that is slightly wrong. And an agent that is given a key to test an API may paste it into a file, a test or a log. Both are easy to miss in a diff and costly later.

Dependency scanning

A dependency scanner reads your lockfile and compares each package and version with a database of known vulnerabilities. OSV-Scanner uses the open OSV database. Dependabot watches your repo and opens update pull requests. An SBOM (software bill of materials) is a list of everything your build contains, which lets you answer "are we affected?" fast when a new vulnerability is announced.

Triage a finding in four questions:

  1. Is the vulnerable code reachable? A flaw in a function you never call is lower risk.
  2. Is it a runtime or dev-only dependency? Dev-only usually matters less.
  3. Is a fixed version available? If yes, upgrade. If not, note a mitigation and a review date.
  4. Is the package real and wanted? A new, unknown package with few downloads and a name close to a famous one may be a typosquat. Check it before anything else.

Secret scanning

Gitleaks and similar tools search files and git history for key patterns. Push protection, offered by GitHub and others, rejects a push that contains a known secret format. Any real secret in a diff blocks the merge, with no exceptions. Then rotate it: removing it from the file does not help, because it is still in history and may be in an agent's logs.

Before and after

Before: gitleaks finds  aws-access-token  in tests/payments.test.ts:14
After:  key revoked and replaced, test reads process.env.PAYMENT_KEY,
        .env is in .gitignore, history cleaned or key rotated

What goes wrong

  • Fix by deleting the line. The key lives on in history.
  • Block on everything. If every low-severity finding stops the merge, people bypass the scanner. Block on severity and reachability, and track the rest.
  • Trusting the name. Never accept a new dependency because the agent recommended it. Read its page first.

Examples

The unfamiliar package

An agent adds requets to requirements.txt, one letter off the real requests. The scan reports no CVE, because the package is new. The review catches it: the name is wrong, it has almost no history, and the agent made a typo. Replace it with requests.

The pasted key

A test file contains STRIPE_KEY = "sk_live_...redacted". Gitleaks flags it. The fix is three steps: revoke the key in the dashboard, read the value from an environment variable, and add a pre-commit scan so it cannot recur.

Key points

  • Scan lockfiles with a tool like OSV-Scanner or Dependabot on every change that touches dependencies.
  • Triage by reachability, runtime versus dev use, and whether a fixed version exists.
  • Check any new package an agent adds for typosquatting before trusting it.
  • A real secret in a diff always blocks the merge, and the key must be rotated, not just deleted.
  • Use push protection and a scanner such as Gitleaks so secrets are stopped before they reach the remote.

Common mistakes

  • Deleting a leaked secret from the file and not rotating it.
  • Blocking merges on every low-risk finding, which teaches people to bypass the scanner.
  • Accepting a new dependency without checking that the package is real and maintained.
  • Scanning only the lockfile at release time, not on each agent change.

Check yourself · 2 of 3

Which question helps you decide how urgent a dependency vulnerability is?

Choose one answer

Check yourself · 3 of 3

An agent adds a package you have never heard of, named almost like a famous one. What is the best first step?

Choose one answer

Practice items, not counted towards your mastery.

Start here

More for this topic