We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Dependency Maintenance

A security check only helps when it runs regularly and someone actually responds to its results. Developers often remember to keep security in mind in production, but forget about their CI servers!

Say we have this GitHub Actions workflow that runs on every push and pull request:

name: Dependency audit

on: [push, pull_request]

permissions:
  contents: read

jobs:
  audit:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
      - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
        with:
          node-version: "24"
          cache: npm
      - run: npm ci --ignore-scripts
      - run: npm run audit:security

There are a few good practices here:

  1. We pin actions/checkout and actions/setup-node to full-length commit SHAs, so a moved tag can't silently change the code our workflow runs.
  2. We grant the GITHUB_TOKEN only contents: read permission, which is the minimum required for this workflow.
  3. We use npm ci instead of npm install to install the exact dependency tree in package-lock.json.
  4. We use --ignore-scripts when installing dependencies, which prevents any lifecycle scripts from running during installation, reducing the risk of executing potentially malicious code from dependencies.
  5. We explicitly run npm run audit:security afterward, so --ignore-scripts doesn't prevent the audit itself from running.

Assignment

Bearly Secure's dependency audit currently depends on someone remembering to run it. Add a GitHub Actions workflow that enforces the audit policy on pushes and pull requests.

  1. actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
    actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
    
  2. npm ci --ignore-scripts
    npm run audit:security
    
  3. actionlint .github/workflows/dependency-audit.yml
    

Run and submit the CLI tests from the project root.