Skip to main content

Performs security checks for a dependency update

Project description

PyPI Python Version License Read the documentation at https://depdive.readthedocs.io/ Build Package Status Run Tests Status Codecov pre-commit Black

Each time you accept a dependency update, you are pulling in new third-party code. However, how to ensure the update is secure?

One way to put a security (and quality) control check before accepting an update is to check what part of the code changes has passed through a code review process. Depdive automates this check.

Workflow

Depdive maps code changes between two versions of a package uploaded in the registry to the corresponding commits that made these changes in the source repository. Depdive then identifies if there was a reviewer for the mapped commit(s) through rule-based checks for evidence of code review on GitHub.

Along the process, Depdive also outputs phantom artifacts: files and lines that are present in the registry but not present in the repository. Examples of phantom files can be compiled binaries in PyPI packages, transpiled JavaScript in npm, and other auto-generated files. Not to mention, malicious actors can sneak in code in the last mile between the repository and the registry.

Depdive works for four package registries: (1) Crates.io (Rust), (2) npm (JavaScript), (3) PyPI (Python), and (4) RubyGems (Ruby). Currently, Depdive only works for GitHub repositories, as GitHub is our primary source to check for code review.

docs/images/depdive.drawio.png

Features

  • Outputs changes that have (and have not) been code reviewed in a dependency update. You can calculate the code review coverage from the output by dividing the reviewed lines by the total lines of code changes in an update.

  • Outputs the reviewed and non-reviewed commits. Also outputs how we determined if a commit was code-reviewed, and the actors involved in the review.

  • Outputs files present in the update version downloaded from the registry but not in the source repository, ie phantom files.

  • Outputs code changes that are present in the udpate, but cannot be mapped to changes in the repository, ie phantom lines.

Installation

You can install depdive via pip from PyPI:

$ pip install depdive

Usage

ca = CodeReviewAnalysis(CARGO, "tokio", "1.8.4", "1.9.0")
stats = ca.stats
assert stats.phantom_files == 0
assert stats.files_with_phantom_lines == 0
assert stats.phantom_lines == 0
assert stats.reviewed_lines == 3694
assert stats.non_reviewed_lines == 0
assert stats.total_commit_count == 29
assert stats.reviewed_commit_count == 29

ca = CodeReviewAnalysis(RUBYGEMS, "pundit", "2.1.0", "2.1.1")
stats = ca.stats
assert stats.phantom_files == 0
assert stats.files_with_phantom_lines == 0
assert stats.phantom_lines == 0
assert stats.reviewed_lines == 128
assert stats.non_reviewed_lines == 186
assert stats.total_commit_count == 35
assert stats.reviewed_commit_count == 23

ca = CodeReviewAnalysis(PYPI, "numpy", "1.21.4", "1.21.5")
stats = ca.stats
assert stats.phantom_files == 39
assert stats.files_with_phantom_lines == 1
assert stats.phantom_lines == 3
assert stats.reviewed_lines == 245
assert stats.non_reviewed_lines == 12
assert stats.total_commit_count == 10
assert stats.reviewed_commit_count == 9

ca = CodeReviewAnalysis(NPM, "lodash", "4.17.20", "4.17.21")
stats = ca.stats
assert stats.phantom_files == 1046
assert stats.files_with_phantom_lines == 1
assert stats.phantom_lines == 1
assert stats.reviewed_lines == 58
assert stats.non_reviewed_lines == 14
assert stats.total_commit_count == 3
assert stats.reviewed_commit_count == 2

Future Work

  • Also provide the quality of the code review(s), e.g., what is the relation between the author and the reviewer? Was a sock account used to bypass the code review check?

  • What other checks should we perform for an update?

Credits

This package was created with cookietemple using Cookiecutter based on Hypermodern_Python_Cookiecutter.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

depdive-0.0.42.tar.gz (16.7 kB view details)

Uploaded Source

Built Distribution

depdive-0.0.42-py3-none-any.whl (15.9 kB view details)

Uploaded Python 3

File details

Details for the file depdive-0.0.42.tar.gz.

File metadata

  • Download URL: depdive-0.0.42.tar.gz
  • Upload date:
  • Size: 16.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.1 CPython/3.9.6 Darwin/21.6.0

File hashes

Hashes for depdive-0.0.42.tar.gz
Algorithm Hash digest
SHA256 6231f5be113518debacce5d62416e82ecc64f5833fa6ad2aae9876df26d47a57
MD5 de4d9ef25e130a21d7a3d808cc490306
BLAKE2b-256 0a8f67b452fbfbba6f20093c985b87b1dd091619812a5e371a29f2db51ce23b2

See more details on using hashes here.

File details

Details for the file depdive-0.0.42-py3-none-any.whl.

File metadata

  • Download URL: depdive-0.0.42-py3-none-any.whl
  • Upload date:
  • Size: 15.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.1 CPython/3.9.6 Darwin/21.6.0

File hashes

Hashes for depdive-0.0.42-py3-none-any.whl
Algorithm Hash digest
SHA256 b41768426f7f571cc85d28cb1cd36b7c2a8ad5c0f307dde3770277780a6d1725
MD5 4dec6d92027b4fe565ea67bb81164e98
BLAKE2b-256 8926f72dfa3868b90f88c4bfe5721ec23b130a74a0158d7a0dbe9887968e7853

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page