Chapter 34 Exercises: Supply Chain Security
Exercise 34.1: Dependency Inventory and Analysis
Difficulty: Beginner Objective: Create a comprehensive dependency inventory for a sample project and assess risk.
- Clone a sample open-source project (e.g., a Node.js Express application or a Python Flask application) from GitHub.
- Identify all direct dependencies listed in the project's manifest file (package.json, requirements.txt, or equivalent).
- Generate a complete dependency tree including all transitive dependencies. For npm, use
npm ls --all. For pip, usepipdeptree. - Count the total number of direct and transitive dependencies.
- For each direct dependency, record: package name, version, license, last update date, and number of weekly downloads.
- Identify any dependencies that have not been updated in the last 12 months.
- Write a one-paragraph risk assessment summarizing your findings.
Deliverable: A spreadsheet or markdown table of all direct dependencies with their metadata, plus your risk assessment paragraph.
Exercise 34.2: Vulnerability Scanning with Trivy
Difficulty: Beginner Objective: Use Trivy to scan a project for known vulnerabilities in dependencies.
- Install Trivy on your lab system.
- Scan a sample project directory:
trivy fs --scanners vuln ./project-directory - Scan a public Docker image:
trivy image python:3.9-slim - For each vulnerability found, record: CVE ID, severity, affected package, fixed version (if available).
- Categorize vulnerabilities by severity (Critical, High, Medium, Low).
- Research the top three most severe vulnerabilities. What is the attack vector? Is there a known exploit?
- Create a prioritized remediation plan.
Deliverable: Vulnerability scan report with categorized findings and remediation plan.
Exercise 34.3: SBOM Generation and Analysis
Difficulty: Intermediate Objective: Generate and analyze Software Bills of Materials using multiple tools.
- Choose a sample project with at least 20 dependencies.
- Generate an SBOM in CycloneDX format using Syft:
syft packages dir:./project -o cyclonedx-json > sbom-cdx.json - Generate an SBOM in SPDX format:
syft packages dir:./project -o spdx-json > sbom-spdx.json - Compare the two formats. What information does each contain? What are the differences?
- Use Grype to scan your CycloneDX SBOM for vulnerabilities:
grype sbom:./sbom-cdx.json - Upload your SBOM to OWASP Dependency-Track (install locally or use the demo instance). Explore the dashboard.
- Set up a CI/CD pipeline (GitHub Actions or local Jenkins) that automatically generates an SBOM on every build.
Deliverable: Both SBOM files, Grype scan results, screenshots of Dependency-Track dashboard, and CI/CD pipeline configuration.
Exercise 34.4: Dependency Confusion Simulation
Difficulty: Intermediate Objective: Understand dependency confusion by simulating the attack in a controlled environment.
- Set up a local npm registry using Verdaccio:
npm install -g verdaccio && verdaccio - Create a private package named
@mycompany/internal-utilsand publish it to your local registry. - Create a project that depends on
@mycompany/internal-utilsand configure it to use your local registry. - Now create a package named
internal-utils(without the scope) version 99.0.0 and publish it to your local registry under a different feed URL to simulate a public registry. - Misconfigure the project's
.npmrcto simulate a vulnerable configuration where both registries are checked. - Run
npm installand observe which package is installed. - Fix the configuration to prevent dependency confusion. Verify the fix works.
- Document the vulnerable vs. secure configurations.
Deliverable: Documentation showing the vulnerable configuration, the attack result, the fixed configuration, and verification.
Exercise 34.5: CI/CD Pipeline Security Audit
Difficulty: Intermediate Objective: Audit a GitHub Actions workflow configuration for security issues.
Review the following GitHub Actions workflow and identify all security issues:
name: Build and Deploy
on:
pull_request_target:
types: [opened, synchronize]
jobs:
build:
runs-on: ubuntu-latest
permissions: write-all
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
- run: echo "Building PR from ${{ github.event.pull_request.head.label }}"
- run: echo "PR Title: ${{ github.event.pull_request.title }}"
- uses: docker/build-push-action@v4
with:
push: true
tags: ghcr.io/myorg/myapp:${{ github.event.pull_request.head.sha }}
- name: Deploy to staging
run: |
curl -H "Authorization: Bearer ${{ secrets.DEPLOY_TOKEN }}" \
https://deploy.myorg.com/stage
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_KEY }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET }}
- List every security issue you can find (aim for at least 6).
- For each issue, explain the risk and how an attacker could exploit it.
- Rewrite the workflow with all issues fixed.
- Add additional security controls that you would recommend.
Deliverable: Annotated audit of the original workflow, rewritten secure workflow, and list of additional recommended controls.
Exercise 34.6: Code Signing with Cosign
Difficulty: Intermediate Objective: Practice signing and verifying container images with Sigstore/Cosign.
- Install Cosign on your lab system.
- Build a simple Docker image from a Dockerfile.
- Push the image to a local or free container registry (e.g., Docker Hub, GitHub Container Registry).
- Sign the image using Cosign keyless signing:
cosign sign <image-reference> - Verify the signature:
cosign verify <image-reference> --certificate-identity=<your-email> --certificate-oidc-issuer=<issuer> - Generate a key pair and sign with an explicit key:
cosign generate-key-pairthencosign sign --key cosign.key <image-reference> - Verify with the public key:
cosign verify --key cosign.pub <image-reference> - Examine the Rekor transparency log entry for your signature.
- Configure a Kubernetes admission controller (e.g., Kyverno or Connaisseur) to reject unsigned images.
Deliverable: Documentation of each step with screenshots, the Rekor log entry, and Kubernetes admission controller configuration.
Exercise 34.7: OpenSSF Scorecard Assessment
Difficulty: Intermediate Objective: Evaluate open-source project security using OpenSSF Scorecard.
- Install the OpenSSF Scorecard CLI.
- Run Scorecard against three popular open-source projects of your choice (e.g., one well-maintained, one moderately maintained, one poorly maintained).
- For each project, record the overall score and individual check scores.
- Compare the results across the three projects.
- For the lowest-scoring project, identify the three most impactful improvements the maintainers could make.
- Research the Criticality Score for these same projects (if available).
- Write a recommendation memo (as if to your organization's engineering leadership) about dependency selection criteria based on your analysis.
Deliverable: Scorecard results for three projects, comparative analysis, and recommendation memo.
Exercise 34.8: Typosquatting Detection
Difficulty: Intermediate Objective: Build a tool to detect potential typosquatting packages.
- Write a Python script that takes a package name as input and generates potential typosquatting variations:
- Character omission (e.g.,
reqestsforrequests) - Character substitution (e.g.,requastsforrequests) - Character transposition (e.g.,reuqestsforrequests) - Hyphen/underscore confusion (e.g.,request_sforrequests) - Homoglyph substitution (e.g., using similar-looking Unicode characters) - For each variation, check whether a package with that name exists on PyPI (use the PyPI JSON API).
- For any existing typosquat candidates, compare their metadata with the legitimate package (author, description, creation date, download count).
- Test your tool against five popular Python packages.
- Document any actual typosquatting attempts you discover.
Deliverable: Python script, test results for five packages, and documentation of any discovered typosquatting attempts.
Exercise 34.9: SLSA Provenance Verification
Difficulty: Advanced Objective: Implement and verify SLSA provenance for a build pipeline.
- Create a simple Go or Node.js application.
- Set up a GitHub Actions workflow that builds the application.
- Add the
slsa-framework/slsa-github-generatorto your workflow to generate SLSA provenance. - Build the application and verify that provenance is generated.
- Download the provenance attestation and examine its contents.
- Verify the provenance using
slsa-verifier:slsa-verifier verify-artifact <artifact> --provenance-path <provenance> --source-uri github.com/<org>/<repo> - Modify the build to tamper with the artifact after building (add a byte to the binary). Attempt verification and confirm it fails.
- Document the difference between SLSA Level 1, 2, and 3 and which level your pipeline achieves.
Deliverable: GitHub repository with SLSA-enabled workflow, provenance attestation, verification results (both pass and fail), and SLSA level documentation.
Exercise 34.10: Supply Chain Threat Modeling
Difficulty: Advanced Objective: Conduct a comprehensive supply chain threat model for a sample application.
Using the MedSecure patient portal as your target:
- Draw a supply chain diagram showing all components: source code, dependencies, build system, distribution, runtime.
- Identify all trust boundaries in the supply chain.
- For each trust boundary, list potential attack vectors.
- Apply STRIDE (Spoofing, Tampering, Repudiation, Information Disclosure, Denial of Service, Elevation of Privilege) to each component.
- Rank each threat by likelihood and impact.
- Map threats to relevant mitigations from SLSA, SBOM, and other frameworks discussed in this chapter.
- Identify the top 5 highest-risk threats and develop detailed mitigation plans for each.
Deliverable: Supply chain diagram, STRIDE analysis table, risk ranking, and detailed mitigation plans.
Exercise 34.11: Build System Security Hardening
Difficulty: Advanced Objective: Harden a CI/CD pipeline against supply chain attacks.
- Create a GitHub repository with a multi-stage CI/CD pipeline (build, test, scan, deploy).
- Implement the following hardening measures: - Pin all GitHub Actions to specific commit SHAs - Set minimum required permissions for each job - Add SBOM generation step - Add vulnerability scanning step with Trivy or Grype - Add container image signing with Cosign - Configure branch protection and CODEOWNERS for pipeline files - Implement hash verification for downloaded tools
- Verify each hardening measure is working correctly.
- Create a security scoring rubric and score your pipeline.
- Document any hardening measures you could not implement and explain why.
Deliverable: GitHub repository with hardened pipeline, security scoring rubric, and documentation.
Exercise 34.12: Incident Response Tabletop: Supply Chain Compromise
Difficulty: Advanced Objective: Practice incident response for a supply chain attack scenario.
Scenario: Your organization's security monitoring has detected that a popular Python package your backend services depend on (python-auth-helper version 2.4.1) has been compromised. A malicious version was published 3 days ago and your CI/CD pipeline installed it during yesterday's build.
- What are your immediate actions? List them in order of priority.
- How do you determine which systems are affected?
- What evidence do you need to collect?
- How do you contain the compromise?
- What is your communication plan (internal and external)?
- How do you determine whether data was exfiltrated?
- What changes do you make to prevent recurrence?
- Draft a one-page incident summary for leadership.
Deliverable: Prioritized action plan, evidence collection checklist, communication plan, and incident summary.
Exercise 34.13: in-toto Layout Verification
Difficulty: Advanced Objective: Implement in-toto supply chain verification for a simple project.
- Install the in-toto Python tools:
pip install in-toto - Create a simple software project with three supply chain steps: code, review, build.
- Define an in-toto layout that requires: - The developer writes code (signed with developer key) - The reviewer approves code (signed with reviewer key) - The CI builds the artifact (signed with CI key)
- Generate link metadata for each step.
- Verify the complete supply chain with
in-toto-verify. - Test a scenario where a step is skipped. Confirm verification fails.
- Test a scenario where an unauthorized person performs a step. Confirm verification fails.
Deliverable: in-toto layout file, link metadata files, verification results for both valid and invalid scenarios.
Exercise 34.14: Package Registry Security Comparison
Difficulty: Intermediate Objective: Compare the security features of major package registries.
Research and compare the security features of npm, PyPI, Maven Central, and crates.io:
- For each registry, document: - Account security (2FA requirements, access controls) - Package signing/verification capabilities - Provenance attestation support - Typosquatting detection/prevention - Vulnerability scanning integration - Package removal/yanking policies - Namespace reservation (scoped packages) - Download statistics and transparency
- Create a comparison matrix.
- Identify which registry has the strongest security posture and justify your assessment.
- For the weakest registry, recommend three improvements that would significantly improve security.
Deliverable: Comparison matrix and analysis document.
Exercise 34.15: Continuous Dependency Monitoring
Difficulty: Intermediate Objective: Set up continuous dependency monitoring for a project.
- Create or fork a project with known vulnerable dependencies.
- Set up Dependabot (GitHub) or Renovate to automatically detect and propose updates for vulnerable dependencies.
- Configure the tool to open pull requests for security updates.
- Set up OWASP Dependency-Track to continuously monitor the project's SBOM.
- Configure alerting for new critical and high-severity vulnerabilities.
- Simulate a new vulnerability disclosure: add a dependency with a known CVE and verify the monitoring tools detect it.
- Document the end-to-end process from vulnerability disclosure to remediation.
Deliverable: Configuration files for monitoring tools, screenshots of alerts, and process documentation.