# Software Supply Chain Security: Managing Risks in Open-Source Dependencies

Software is often built by consuming libraries and frameworks from package repositories. Popular package repositories include npm, PyPI, Maven, NuGet and Docker Hub.

By adding a single web framework to a project, dozens of smaller dependencies may be added.

However, by adding third party packages to an application, it becomes part of your trusted codebase. If a third party package in the dependency chain contains vulnerabilities, or has been compromised, then your application may be at risk.

As such, Software Supply Chain Security is an important consideration in modern software development.

This article will discuss common risks in dependencies, why Software Supply Chain Security is important, and how to implement security in dependencies.

## 1. What is Software Supply Chain Security is the practice of ensuring secure third party code, build tools and components in software development.

This ensures:

* Dependencies are from trusted authors.
* Vulnerabilities in third party packages can be detected and fixed.
* Malicious packages cannot be installed.
* Only trusted code is run in build environments.
* Teams know what components are present in production.

Thus, external code can be treated as securely as code developed in house.

## 2. Why is Software Supply Chain Security important?

Attackers are increasingly targeting dependencies in open source packages and build tools. By exploiting one popular library, attackers can gain access to thousands of downstream organisations.

Risks in dependencies include:

* **Malicious Code Execution:** Installation scripts stealing sensitive data (environment variables, SSH keys, cloud credentials).
* **Vulnerabilities in dependencies:** Critical vulnerabilities may exist in un-maintained transitive dependencies and expose your production systems.
* **Data Exfiltration:** Compromised front-end packages may silently steal form data or user tokens.
* **Disruption in emergency patching:** Teams may be forced to panic in order to find where a vulnerable dependency is being used in multiple repositories.

If teams have visibility over their dependencies, they can react calmly and quickly to new vulnerabilities.

## 3. Common Risks

### 3.1 Vulnerabilities in Dependencies

Even if dependencies directly used by the project are well known, sub-dependencies may be used with less security consideration.

**Mitigation:**

* Automate scanning of dependencies in CI/CD pipelines.
* Ensure dependencies are regularly updated using automated PRs. Do not leave many years between updates.
* Remove unused packages to reduce the size of the dependency tree.

### 3.2 Typosquatting and Dependency Confusion

Attackers often create malicious packages with names very similar to popular packages (typos), or exploit misconfigured private package repositories.

**Mitigation:**

* Carefully ensure that the name, number of downloads, maintainers and source repository of the package is correct before installation.
* Ensure private package repositories are configured securely. Use scoped namespaces to prevent package names in private repositories from being over-ridden by public repositories.
* Use lockfiles (`package-lock.json`, `poetry.lock`, `go.sum`) with cryptographic integrity.

### 3.3 Compromised Maintainers

Many open source packages are maintained by a small number of volunteers. If maintainers do not have MFA enabled, and their account is compromised, an attacker may push a malicious update to a package.

**Mitigation:**

* Do not automatically merge large or untrusted dependency updates into production.
* Pin specific versions of dependencies in production.
* Check release notes and community alerts for changes in critical library versions.

### 3.4 Malicious Installation Scripts

Many package managers will automatically run scripts as part of the install command. This means newly installed packages may have full access to your development machine/server.

**Mitigation:**

* If possible, limit or disable arbitrary post install scripts.
* Ensure builds run in isolated low privileged containers with no access to production secrets.
* Ensure that packages requesting unusual system/network access during installation are audited.

### 3.5 Unmaintained Libraries

Packages which have not been updated for many years may contain unpatched vulnerabilities, or may be vulnerable to hostile takeovers.

**Mitigation:**

* Ensure packages have recent commits, active maintainers and responsive issues.
* Plan to migrate away from archived/deprecated dependencies early.

## 4. Direct & Transitive Dependencies

Understanding direct and transitive dependencies is useful for managing risk.

### Direct Dependencies

* Explicitly added to the project manifest.
* Easy to review, update, and understand.
* Usually only make up a small amount of packages in total.

### Transitive Dependencies

* Added implicitly via direct dependencies.
* Often make up the majority of code in deployed applications.
* Require automated scanning and lockfiles.
* Most vulnerabilities in dependencies occur in deep levels of the transitive dependency tree.

## 5. Best Practice

Teams can reduce risks in dependencies by following best practices.

* Commit lockfiles to source control. This ensures that all developers and CI runners install the same verified packages.
* Create and save SBOMs. This allows teams to quickly determine if they are exposed to a vulnerability in major releases.
* Where possible, choose small, actively maintained libraries. Instead of using large frameworks for simple tasks.
* Set up private registry mirrors. This allows teams to cache approved packages, and prevent known malicious versions from being installed.
* Set up automated security alerts. Set alerts on repositories to notify teams of newly disclosed CVEs.
* Enforce MFA for publishing packages internally. This ensures that if a package is published by your organisation, it is not vulnerable to account takeovers.

## 6. Testing

To ensure that your software supply chain defences work, test them.

* Run dependency scans (`npm audit`, `pip-audit`, `govulncheck` or SCA tools) in CI.
* Ensure that integrity checks in lockfiles fail if the expected hash does not match.
* Ensure that all third-party components are included in the SBOM.
* Ensure that builds are isolated, and cannot access unrelated files or secrets.

Only test in repositories/build systems that you own or have permission to test.

## 7. Frameworks and Standards

Frameworks are available to allow organisations to follow good practices for managing dependencies.

* **OWASP SCVS** provides a framework for identifying and reducing risk in software supply chains.
* **OWASP Dependency-Check** and **CycloneDX** provide open source tools and standards for detecting vulnerabilities and generating SBOMs.
* **OpenSSF Scorecards** automatically score open source projects based on best security practices.

Following these tools allows teams to make informed decisions around open source code.

## 8. Future Trends

As software becomes increasingly complex, transparency and cryptographic assurance in software supply chains is becoming standard practice.

Trends in the future include:

* **SBOMs becoming mandatory.** More regulation and enterprise requirements to ensure all third party components are documented.
* **Provenance.** Package repositories can prove that the binaries being published match the source code in their public repositories.
* **Automated exploitability.** Vulnerability alerts prioritised based on whether the function is exploitable in your code.
* **Sandboxed package execution.** File and network access restricted at language/runtime level.

Good dependency management allows teams to utilise open source innovation safely.

## Conclusion

Using open source dependencies in software development can increase risk surfaces.

By using lockfiles, scanning dependencies, carefully choosing packages and isolating builds, developers can manage software supply chain risks without impacting development speed.

## References

* [OWASP SCVS](https://owasp.org/www-project-software-component-verification-standard/)
* [OpenSSF Scorecards](https://securityscorecards.dev/)
* [CycloneDX SBOM](https://cyclonedx.org/)
