GithubHelp home page GithubHelp logo

bernardoamc / dependency_inspector Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 11 KB

A tool for analyzing dependencies in .lock files aiming to give repository owners insights about their dependencies and prevent supply chain attacks.

Makefile 1.44% Go 67.47% Ruby 31.09%

dependency_inspector's Introduction

Dependency Confusion

A small Go program aiming to provide insights into Gemfile.lock or yarn.lock files and their dependencies.

Commands

analyze

This option is useful to detect inconsistent dependencies and hopefully prevent supply chain attacks.

The follow algorithm is used:

  1. Parse every .lock file found in the specified directory
  2. Parse the registry file containing the dependencies and the URL they should be loaded from
  3. For every .lock file, flag dependencies that exists in the `registry`` but that fetched from a different URL

See the Registry file format section for more information.

remotes

This option is useful to detect suspicious remotes being used across your .lock files.

The follow algorithm is used:

  1. Parse every .lock file found in the specified directory
  2. Aggregate every remote found in the dependencies
  3. Print the unique remotes found

For example, if dependencies are all from https://registry.yarnpkg.com it will print a single line with that information, ignoring dependency names.

Registry file format

{
	"url": "https://npm.acme.io/",
	"dependencies": [
        "dependency1",
        "dependency2",
        "dependencyN"
    ]
}

Examples

Keep the following things in mind besides the examples shared below:

  1. the --path flag can also point to a single .lock file instead of a directory.
  2. the --verbose flag will print the dependencies parsed from each .lock file.

Use the --help flag to get more information about the available options.

Analyzing Gemfile.lock files for incorrect dependencies

Parsing every .lock file found in lock_files/ruby and checking if any of the dependencies are being loaded from a different url than the one specified in registries/ruby.json. For example, if we had the following .lock files:

  • lock_files/ruby/repo1.lock
  • lock_files/ruby/repo2.lock
  • lock_files/ruby/repo3.lock

And our program found inconsistencies in repo1 and repo3, the following files would be created:

  • analyze_output/repo1.json
  • analyze_output/repo3.json
./dependency_inspector analyze --path lock_files/ruby --registry registries/ruby.json --ruby

Analyzing yarn.lock files for incorrect dependencies

./dependency_inspector analyze --path lock_files/js --registry registries/js.json --js

Listing unique remotes from every Gemfile.lock file in directory

./dependency_inspector remotes --path lock_files/ruby --ruby

We can also grep by a particular substring:

./dependency_inspector remotes --path lock_files/ruby --grep "acme" --ruby

Listing unique remotes from every yarn.lock file in directory

./dependency_inspector remotes --path lock_files/js --js

The grep flag is also available for the js option.

Scripts

The scripts directory contains a few scripts that can be used to fetch .lock files from your repositories and perform a partial analysis from dependencies within your registry file against rubygems.

Known limitations (for now)

yarn.lock files with entries that contain dependencies with distinct names in the same line tend to cause duplicated remote entries in the output.

Example:

"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:

This will return the following remote:

Instead of the expected:

This is happening because our parser will fetch wrap-ansi-cjs from the definition above and won't be able to clean the remote URL since it contains wrap-ansi.

dependency_inspector's People

Contributors

bernardoamc avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.