Skip to content
Tutorials Center
My learning

Topics

Lesson 35 of 38 ยท Projects and Practice

Project: Build a Dependency Audit Tool

Build a small dependency auditor step by step: parse a lock file, compare versions to an advisory feed, rank findings by severity and print a report with fixes.

In this project you build a miniature software composition analysis tool, the kind that powers npm audit and composer audit. It parses a lock file, compares versions against a local advisory feed, ranks the results and prints a report with the fixed version. Everything runs in your browser on fictional data, so it is safe and repeatable.

You will practice ideas from Vulnerable and Outdated Components and Dependency Scanning and SBOMs. Build it in four steps; each TryIt is complete and runnable.

The plan

  1. Parse a lock file into (name, version, parent) records.
  2. Match each record against an advisory feed with proper version ranges.
  3. Explain how the vulnerable package reached the project (the path).
  4. Report and set an exit status like a CI job.
flowchart LR
    L["Lock file"] --> P["Parser"]
    F["Advisory feed"] --> M["Matcher"]
    P --> M
    M --> R["Ranked report"]
    R --> X["Exit code for CI"]

A CI job fails when the report contains findings above the threshold.

Step 1: parse the lock file

Our fictional lock format lists each package with the packages that require it.

Python Step 1: parse the lock file

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Step 2: version ranges and advisories

An advisory says which versions are affected: from introduced up to (not including) fixed. Compare using numeric tuples.

Python Step 2: match versions to advisories

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

http-core 5.0.2 is not flagged because the advisory was fixed in 5.0.0. The range test, not the package name alone, decides.

Step 3: show how it got there

Developers ask "why do I even have this?" The parent chain answers it.

Python Step 3: trace the dependency path

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The advice differs: a direct dependency you upgrade yourself; a transitive one you fix by upgrading the parent (here template-lib), asking its maintainers, or using an override.

Step 4: the full tool

Now combine everything: parse, match, trace, rank and exit.

Python Step 4: the complete auditor

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Extend it

Try these in the editor above:

  • Add a reachable field to each advisory and sort reachable findings first.
  • Output a CycloneDX-style JSON document of the components.
  • Add an ignore list with an expiry date and show ignored findings separately.
  • Handle two advisories for the same package by reporting the highest fixed version needed.
  • Treat versions like 2.4.1-beta by stripping or comparing the suffix.

Check your understanding

Quick check ยท 3 questions

of 3 answered You scored / 3 ยท perfect!

  1. 1. Why does the tool show the dependency path for a finding?

    A transitive dependency is usually fixed by updating the package that pulls it in.
  2. 2. http-core 5.0.2 is not reported against an advisory fixed in 5.0.0. Why?

    Affected means introduced <= version < fixed; 5.0.2 is past the fix.
  3. 3. What does setting an exit status in the tool enable?

    A non-zero exit code is how CI systems detect a failed check.

Summary

  • A dependency auditor is parse, match, trace and report.
  • Use numeric version comparison with introduced and fixed bounds.
  • Show the path so developers know what to upgrade.
  • Return an exit status so CI can gate releases.

Next: Project: Log Attack Detector