CI/CD Automation Tutorial 0/46 lessons ~6 min read Lesson 34

    Dependency Scanning

    Dependency Scanning (SCA) inspects third-party libraries — lockfiles, manifests, container layers — for known CVEs.

    Course progress0%
    Focus
    20 guided sections
    Practice signal
    Examples included
    Career prep
    Interview Q&A included

    Introduction

    Dependency Scanning (SCA) inspects third-party libraries — lockfiles, manifests, container layers — for known CVEs. CI dependency scanning answers: does this build introduce or inherit a vulnerable component? Staff programs combine SCA tools (Dependabot, Snyk, OSV), SBOM generation (CycloneDX, SPDX), and a published CVE policy so teams know whether to patch, upgrade, or waive within SLA.

    The story

    Log4Shell (CVE-2021-44228) hit a logistics company whose manual dependency review ran monthly. Teams with Dependabot + SCA in CI had PRs upgrading log4j within hours; this company discovered exposure three days later via WAF alerts. After the incident they mandated: SBOM on every release artifact, SCA gate blocking Critical CVEs on merge, Dependabot grouped weekly with auto-merge for patch bumps. Next critical CVE (Spring4Shell) was patched org-wide in 6 hours with audit trail from CI logs and SBOM diff.

    Understanding the topic

    SCA + SBOM + policy form the supply chain verification layer in CI.

    • SCA (Software Composition Analysis): matches dependencies against CVE databases (NVD, GitHub Advisory, OSV).
    • Dependabot/Renovate: automated PRs bumping vulnerable or outdated deps — shift-left remediation.
    • SBOM: machine-readable bill of materials (CycloneDX JSON, SPDX) attached to each build artifact for audit and incident response.
    • CVE policy: Critical = block merge + 24h SLA; High = 7 days; Medium = 30 days; waivers require security sign-off + compensating controls.
    • CI placement: scan after lockfile resolve, before artifact publish; re-scan container image layers separately.

    Internal architecture

    Dependency scan pipeline — from lockfile to SBOM to gate.

    text
    npm ci / mvn dependency:tree
    SCA scan (Snyk, osv-scanner, Trivy fs)
    Generate SBOM (cyclonedx-npm, syft)
    Policy engine: CVE severity vs thresholds
    ┌ fail PR ──┬── pass → attach SBOM to artifact
    │ └── waiver ticket → allow with audit
    Dependabot/Renovate (parallel track) opens fix PRs

    Visual explanation

    Two diagrams show where Dependency Scanning lives in the delivery path and how teams implement it in production.

    Dependency Scanning — system view
    Trigger
    Git event
    Pipeline
    Stages
    Artifact
    Immutable
    Deploy
    Gated
    Where this topic sits in the delivery path.
    Dependency Scanning — execution flow
    Plan
    Design
    Build
    Verify
    Release
    Promote
    Observe
    Metrics
    Follow this loop when designing or reviewing pipelines.

    Step-by-step explanation

    1. Commit lockfiles (package-lock.json, poetry.lock) — SCA without lockfile is guesswork.
    2. Add SCA job: Snyk snyk test --severity-threshold=high or OSV-Scanner on lockfile.
    3. Generate SBOM: npx @cyclonedx/cyclonedx-npm --output-file sbom.json; upload as build artifact.
    4. Publish CVE policy doc: severity SLAs, waiver form, owner (security@corp).
    5. Enable Dependabot v2 (.github/dependabot.yml) for ecosystems in use — group patch updates weekly.
    6. On Critical CVE: pipeline fails; Dependabot PR auto-assigned; track MTTR in dashboard.

    Production implementation

    Dependabot config + OSV-Scanner + SBOM in GitHub Actions:

    yaml
    # .github/dependabot.yml
    version: 2
    updates:
    - package-ecosystem: npm
    directory: /
    schedule: { interval: weekly }
    groups:
    production-deps:
    patterns: ["*"]
    update-types: [patch, minor]
    # CI job
    sca:
    steps:
    - run: npm ci
    - run: |
    curl -sSfL https://github.com/google/osv-scanner/releases/latest/download/osv-scanner_linux_amd64 -o osv-scanner && chmod +x osv-scanner
    ./osv-scanner --lockfile=package-lock.json --format sarif --output osv.sarif
    - run: npx @cyclonedx/cyclonedx-npm --output-file sbom.json
    - uses: actions/upload-artifact@v4
    with: { name: sbom, path: sbom.json }

    Execution workflow

    1SCA + SBOM + CVE policy rollout
    1 / 5

    Lockfile discipline

    All ecosystems commit lockfiles.

    CI fails if lockfile out of date.

    Real-world use

    Executive Order 14028 mandated SBOM for US federal software suppliers. CycloneDX and SPDX are Linux Foundation standards. GitHub Dependabot serves millions of repos; Google OSV aggregates advisories. npm audit is useful but incomplete — production programs use OSV/Snyk + lockfile scanning. Log4Shell and xz utils backdoor renewed board-level focus on SCA.

    Enterprise use cases

    Multi-ecosystem org (Java + Node + Python): Snyk org-wide with SSO; SBOM mandatory for FedRAMP boundary systems. CycloneDX embedded in container labels via ORAS. CVE waiver board meets weekly; waivers expire in 90 days max. Executive dashboard: open Critical count across repos.

    • Inner source: internal libraries scanned same as external — typosquatting policy on private registry.
    • License compliance: FOSSA or Snyk license gate blocks GPL in proprietary services.
    • Incident: SBOM query "who uses log4j-core 2.14.x?" answered in minutes vs days.

    Production case study

    SaaS billing (PCI adjacent): QSA required evidence of vulnerability management for dependencies.

    • Challenge: manual npm audit monthly; no SBOM; Critical CVE in axios reached prod.
    • Decision: OSV-Scanner gate on PR; CycloneDX SBOM on every release tag; Dependabot weekly grouped.
    • Policy: Critical blocks merge; High 7-day SLA tracked in JIRA automation from SARIF.
    • Outcome: PCI audit passed; MTTR for Critical CVEs 4 hours median over 12 months.

    Trade-offs

    • Fail on any CVE: blocks all merges when ecosystem has transient unfixable advisories.
    • Warn only: CVE debt accumulates until breach — policy without gate is toothless.
    • Dependabot noise: daily PR flood — use grouping and auto-merge for patches with CI green.
    • SBOM storage cost: negligible JSON; governance of retention and PII in SBOM fields matters.
    • Transitive deps: SCA finds CVE; fix may require upstream — waiver + monitoring required.

    Security implications

    Dependency scanning is supply chain defense — but implementation has risks:

    • SCA tools need registry access — use read-only tokens; never prod credentials in scan job.
    • Dependabot PRs are code changes — require CI green + review; auto-merge only patch with tests.
    • SBOMs reveal internal package names — classify as internal confidential in regulated environments.
    • Typosquatting: scan package names on NEW dependency addition, not just CVE on existing.

    Scalability analysis

    Enterprise dependency management at scale:

    • 10,000 repos × weekly Dependabot PRs needs merge automation and ownership mapping (CODEOWNERS).
    • Central CVE exception database synced to all pipelines — avoid per-repo waiver YAML drift.
    • Monorepo: scan from root lockfile; affected-package reporting in PR comment.
    • SBOM aggregation for release train — one composite SBOM per deployed version across 50 images.

    Staff engineer insights

    • SBOM is for incident response and audit — generate it even if no auditor asks yet; Log4Shell proved why.
    • CVE count is a vanity metric — track exploitable path (reachable) vs theoretical; Grype/Snyk reachability helps prioritize.
    • Dependabot without auto-merge policy becomes PR noise engineers ignore — group patches, automate safe merges.
    • Waivers must expire — permanent waivers are how Critical CVEs live in prod for years.

    Best practices

    • Scan lockfiles, not just manifests — transitive CVEs live in the lock.
    • Attach SBOM to immutable artifact (image digest, jar SHA).
    • Publish CVE SLA policy before enabling fail gates — teams need clarity.
    • Use SARIF output integrated with GitHub Security or DefectDojo.
    • Re-scan on schedule — new CVEs affect old builds; alert if deployed artifact now vulnerable.

    Common mistakes

    • npm audit alone as sole SCA — misses many ecosystems and transitive gaps.
    • No lockfile in repo — scan results non-deterministic across CI runs.
    • Dependabot enabled without grouping — 20 PRs/day per repo, all ignored.
    • SBOM generated but never stored — useless during incident response.

    Advanced interview questions

    Interview Prep

    Practice concise answers, then expand each card for the explanation.

    5 questions
    1IntermediateQuestionExplain SCA, SBOM, and Dependabot roles in CI.+

    Answer

    SCA matches deps against CVE DB — gate on severity. SBOM is machine-readable component list per build — audit and incident "am I affected?". Dependabot/Renovate opens upgrade PRs proactively — remediation shift-left. Together: detect (SCA), document (SBOM), fix (Dependabot).

    Follow-up

    CycloneDX vs SPDX?
    2AdvancedQuestionDesign a CVE policy for a 50-team engineering org.+

    Answer

    Critical: block merge, 24h SLA, no waiver without CISO. High: 7 days, merge allowed with ticket. Medium: 30 days. Waivers: compensating control, expiry 90 days, weekly board review. MTTR metrics per team. Re-scan deployed artifacts when new CVE published.

    Follow-up

    Unreachable CVE — fail or warn?
    3AdvancedQuestionLog4Shell hits Friday 5pm. What does your pipeline evidence show?+

    Answer

    SCA scan results per commit, SBOM listing log4j version per artifact, Dependabot PR timestamp, deploy records mapping digest to prod. Query SBOM: which prod services on vulnerable version. CI logs prove when fix merged. MTTR measured from advisory to patched deploy.

    Follow-up

    How often to re-scan old artifacts?
    4IntermediateQuestionDependabot creates 15 PRs weekly. Reduce noise without ignoring security.+

    Answer

    Group patch/minor updates weekly. Auto-merge patch when CI green + no major version. Pin major updates manual review. Limit ecosystems per repo config. Use Renovate schedule and automerge rules with vulnerability alert priority.

    Follow-up

    Auto-merge risk?
    5IntermediateQuestionWhere does dependency scanning run vs container scanning?+

    Answer

    SCA on lockfiles/filesystem before image build — catches app deps early. Container scan (Trivy/Grype) catches OS packages and anything copied into image — run both. SBOM from build; re-validate at image scan. Gate at both stages or final image as source of truth for deploy.

    Follow-up

    Syft vs cyclonedx-npm?

    Hands-on exercise

    Lab: Add a vulnerable dependency version to a sample Node project. Configure OSV-Scanner to fail CI. Generate CycloneDX SBOM. Enable Dependabot and merge the fix PR. Document CVE policy table.

    • Upload SBOM as artifact on release tag.
    • Write waiver template with 90-day expiry.
    • Query SBOM JSON for specific package version.

    Summary

    You can wire dependency scanning as SCA + SBOM + CVE policy: OSV/Snyk on PR, CycloneDX on artifact, Dependabot for fixes, waivers with expiry for exceptions. Explain SBOM as the incident-response artifact executives wish they had before Log4Shell.

    Ready to mark this lesson complete?Track your journey across the entire course.