Logo

dev-resources.site

for different kinds of informations.

Fixing vulnerabilities found in a dependency tree

Published at
2/4/2022
Categories
yarn
npm
dependency
security
Author
webit
Categories
4 categories in total
yarn
open
npm
open
dependency
open
security
open
Author
5 person written this
webit
open
Fixing vulnerabilities found in a dependency tree

I'm working on the app that is not yet publicly available and during the preparation for the launch, we made a full code scan to find any vulnerabilities.
We discovered that some of the dependencies used in our codebase depend on old and potentially harmful packages. 

It was like we need packageA but that library depends on the vulnerable library packageB.

We needed to take proper action as soon as possible.

Yarn solution

What I've found was the fact that it's relatively easy to force some deeply nested dependencies in the yarn package manager:

Yarn supports selective version resolutions, which lets you define custom package versions or ranges inside your dependencies through the resolutions field in your package.json file.

How to use it?

We need to add resolutions to our package.json instructing Yarn how to handle dependencies:

{
  "name": "project",
  "version": "1.0.0",
  "dependencies": {
    "left-pad": "1.0.0",
    "c": "file:../c-1",
    "d2": "file:../d2-1"
  },
  "resolutions": {
    "d2/left-pad": "1.1.1",
    "c/**/left-pad": "^1.1.2"
  }
}
Enter fullscreen mode Exit fullscreen mode

That will install version 1.0.0 of left-pad alongside locally stored c and d2. But it will install version 1.1.1 of left-pad for d2 and version ^1.1.2 for any dependencies requiring left-pad somewhere under c.

NPM implementation

If you use npm instead of yarn, you can achieve a similar effect using the overrides setting in package.json. There are some differences though.

We can't use glob matching (double asterisk -  **) instead, we have to nest dependencies:

{
  "overrides": {
    "foo": {
      ".": "1.0.0",
      "bar": "1.0.0"
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

In that example, we're overriding foo package to be at version 1.0.0 and making bar at any depth beyond foo also 1.0.0.

Final words

With those, maybe, lesser-known options, we can force a newer (or simply other) version of any deeply nested package. This is a way for fixing issues when one of our dependency packages relies on e.g. not maintaining any more packages containing e.g. vulnerabilities.

dependency Article's
30 articles in total
Favicon
Ore: Advanced Dependency Injection Package for Go
Favicon
vcpkg - how to modify dependencies
Favicon
CocoaPods is in Maintenance Mode
Favicon
Safely restructure your codebase with Dependency Graphs
Favicon
Understanding Dependencies in Programming
Favicon
A zoom installer script for linux
Favicon
Loose Coupling and Dependency Injection (DI) principle
Favicon
Dependency Injection in swift
Favicon
Dependency relation in AWS CDK
Favicon
CORS how to enable them in .NET?
Favicon
Angular Dependency Injection
Favicon
Dependency management made easy with Dependabot and GitHub Actions
Favicon
Jetpack compose — Dependency injection with Dagger/HILT
Favicon
Dependencies in node project
Favicon
Fixing vulnerabilities found in a dependency tree
Favicon
How to create your own dependency injection framework in Java
Favicon
Reduzindo a quantidade de Branchs na criação de Objetos com uma estrutura plugável
Favicon
NodeJs - Dependency injection, make it easy
Favicon
A Step by Step Guide to ASP.NET Core Dependency Injection
Favicon
The Basics of Dependency Maintenance in NPM/yarn
Favicon
The troubles of modern software dependency management and what to do about them
Favicon
Loose Coupling Basics
Favicon
Correctly defining CDK dependencies in L3 constructs
Favicon
What dependency hell looks like, and how to avoid it
Favicon
How to create your own dependency injection framework in Java
Favicon
Dependency Inversion Principle in Swift
Favicon
Angular: Create a custom dependency injection
Favicon
Dagger with a Hilt
Favicon
How to find what is the dependency of a function, class, or variable in ES6 via AST
Favicon
Data Dependency Graph

Featured ones: