crossdep-audit 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- crossdep_audit-0.2.0/LICENSE +21 -0
- crossdep_audit-0.2.0/PKG-INFO +86 -0
- crossdep_audit-0.2.0/README.md +62 -0
- crossdep_audit-0.2.0/pyproject.toml +39 -0
- crossdep_audit-0.2.0/setup.cfg +4 -0
- crossdep_audit-0.2.0/src/crossdep_audit/__init__.py +1 -0
- crossdep_audit-0.2.0/src/crossdep_audit/__main__.py +4 -0
- crossdep_audit-0.2.0/src/crossdep_audit/advisories.json +28 -0
- crossdep_audit-0.2.0/src/crossdep_audit/advisories.py +24 -0
- crossdep_audit-0.2.0/src/crossdep_audit/cache.py +42 -0
- crossdep_audit-0.2.0/src/crossdep_audit/cli.py +113 -0
- crossdep_audit-0.2.0/src/crossdep_audit/model.py +26 -0
- crossdep_audit-0.2.0/src/crossdep_audit/osv.py +63 -0
- crossdep_audit-0.2.0/src/crossdep_audit/registries.py +63 -0
- crossdep_audit-0.2.0/src/crossdep_audit/report.py +86 -0
- crossdep_audit-0.2.0/src/crossdep_audit/scanners.py +292 -0
- crossdep_audit-0.2.0/src/crossdep_audit/severity.py +11 -0
- crossdep_audit-0.2.0/src/crossdep_audit/versions.py +72 -0
- crossdep_audit-0.2.0/src/crossdep_audit.egg-info/PKG-INFO +86 -0
- crossdep_audit-0.2.0/src/crossdep_audit.egg-info/SOURCES.txt +22 -0
- crossdep_audit-0.2.0/src/crossdep_audit.egg-info/dependency_links.txt +1 -0
- crossdep_audit-0.2.0/src/crossdep_audit.egg-info/entry_points.txt +2 -0
- crossdep_audit-0.2.0/src/crossdep_audit.egg-info/top_level.txt +1 -0
- crossdep_audit-0.2.0/tests/test_auditor.py +338 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ProTechSean
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: crossdep-audit
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Cross-platform dependency auditor: scans manifests and lockfiles for known vulnerabilities and outdated libraries
|
|
5
|
+
Author: ProTechSean
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Repository, https://github.com/SeanShaffer88/crossdep-audit
|
|
8
|
+
Project-URL: Issues, https://github.com/SeanShaffer88/crossdep-audit/issues
|
|
9
|
+
Keywords: security,vulnerability,dependencies,audit,osv,sarif,lockfile
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Environment :: Console
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Topic :: Security
|
|
19
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
20
|
+
Requires-Python: >=3.11
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
|
|
25
|
+
# crossdep-audit
|
|
26
|
+
|
|
27
|
+
Cross-platform dependency auditor. Scans a project for known security
|
|
28
|
+
vulnerabilities and outdated libraries, then prints a concise summary — no
|
|
29
|
+
manual lookups required.
|
|
30
|
+
|
|
31
|
+
## Supported ecosystems
|
|
32
|
+
|
|
33
|
+
| Ecosystem | Files scanned |
|
|
34
|
+
|-----------|---------------|
|
|
35
|
+
| npm / Yarn / pnpm | `package-lock.json`, `package.json`, `yarn.lock`, `pnpm-lock.yaml` |
|
|
36
|
+
| Python | `requirements.txt`, `Pipfile.lock`, `poetry.lock`, `pyproject.toml` |
|
|
37
|
+
| Rust | `Cargo.lock` |
|
|
38
|
+
| Go | `go.mod` |
|
|
39
|
+
| Ruby | `Gemfile.lock` |
|
|
40
|
+
| Java (Maven/Gradle) | `pom.xml` (recursive), `*.gradle`, `*.gradle.kts` |
|
|
41
|
+
| .NET (NuGet) | `packages.config`, `*.csproj` (recursive) |
|
|
42
|
+
| PHP (Composer) | `composer.lock` |
|
|
43
|
+
|
|
44
|
+
## Install
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pip install crossdep-audit # from PyPI
|
|
48
|
+
pip install . # from a source checkout
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Requires Python 3.11+. No third-party dependencies.
|
|
52
|
+
|
|
53
|
+
## Usage
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
crossdep-audit path/to/project # text summary
|
|
57
|
+
crossdep-audit . --format json # machine-readable JSON
|
|
58
|
+
crossdep-audit . --format sarif > results.sarif # SARIF for GitHub code scanning
|
|
59
|
+
crossdep-audit . --offline # no network: built-in advisory snapshot only
|
|
60
|
+
crossdep-audit . --fail-on high # exit 1 only for HIGH/CRITICAL findings
|
|
61
|
+
crossdep-audit . --no-cache # bypass the 24h local lookup cache
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Vulnerability data comes from the [OSV database](https://osv.dev) (batched
|
|
65
|
+
`querybatch` lookups, cached locally for 24h) plus a built-in advisory
|
|
66
|
+
snapshot in `src/crossdep_audit/advisories.json`, which is used when
|
|
67
|
+
`--offline` is set or the network is unreachable. Outdated checks query each
|
|
68
|
+
ecosystem's official registry (npm, PyPI, crates.io, Go proxy, RubyGems,
|
|
69
|
+
Maven Central, NuGet, Packagist).
|
|
70
|
+
|
|
71
|
+
Exit code is `1` when findings meet the `--fail-on` threshold (default:
|
|
72
|
+
any vulnerability), `0` otherwise — suitable for CI gates.
|
|
73
|
+
|
|
74
|
+
## CI
|
|
75
|
+
|
|
76
|
+
- `.github/workflows/test.yml` runs the unit tests on Python 3.11–3.13 for
|
|
77
|
+
every push/PR to `main`, plus a CLI smoke test.
|
|
78
|
+
- `.github/workflows/publish.yml` builds and publishes to PyPI via trusted
|
|
79
|
+
publishing (OIDC) when a GitHub release is published. The first publish
|
|
80
|
+
requires registering the project / trusted publisher on PyPI.
|
|
81
|
+
|
|
82
|
+
## Development
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
PYTHONPATH=src python -m unittest discover -s tests -v
|
|
86
|
+
```
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# crossdep-audit
|
|
2
|
+
|
|
3
|
+
Cross-platform dependency auditor. Scans a project for known security
|
|
4
|
+
vulnerabilities and outdated libraries, then prints a concise summary — no
|
|
5
|
+
manual lookups required.
|
|
6
|
+
|
|
7
|
+
## Supported ecosystems
|
|
8
|
+
|
|
9
|
+
| Ecosystem | Files scanned |
|
|
10
|
+
|-----------|---------------|
|
|
11
|
+
| npm / Yarn / pnpm | `package-lock.json`, `package.json`, `yarn.lock`, `pnpm-lock.yaml` |
|
|
12
|
+
| Python | `requirements.txt`, `Pipfile.lock`, `poetry.lock`, `pyproject.toml` |
|
|
13
|
+
| Rust | `Cargo.lock` |
|
|
14
|
+
| Go | `go.mod` |
|
|
15
|
+
| Ruby | `Gemfile.lock` |
|
|
16
|
+
| Java (Maven/Gradle) | `pom.xml` (recursive), `*.gradle`, `*.gradle.kts` |
|
|
17
|
+
| .NET (NuGet) | `packages.config`, `*.csproj` (recursive) |
|
|
18
|
+
| PHP (Composer) | `composer.lock` |
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install crossdep-audit # from PyPI
|
|
24
|
+
pip install . # from a source checkout
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Requires Python 3.11+. No third-party dependencies.
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
crossdep-audit path/to/project # text summary
|
|
33
|
+
crossdep-audit . --format json # machine-readable JSON
|
|
34
|
+
crossdep-audit . --format sarif > results.sarif # SARIF for GitHub code scanning
|
|
35
|
+
crossdep-audit . --offline # no network: built-in advisory snapshot only
|
|
36
|
+
crossdep-audit . --fail-on high # exit 1 only for HIGH/CRITICAL findings
|
|
37
|
+
crossdep-audit . --no-cache # bypass the 24h local lookup cache
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Vulnerability data comes from the [OSV database](https://osv.dev) (batched
|
|
41
|
+
`querybatch` lookups, cached locally for 24h) plus a built-in advisory
|
|
42
|
+
snapshot in `src/crossdep_audit/advisories.json`, which is used when
|
|
43
|
+
`--offline` is set or the network is unreachable. Outdated checks query each
|
|
44
|
+
ecosystem's official registry (npm, PyPI, crates.io, Go proxy, RubyGems,
|
|
45
|
+
Maven Central, NuGet, Packagist).
|
|
46
|
+
|
|
47
|
+
Exit code is `1` when findings meet the `--fail-on` threshold (default:
|
|
48
|
+
any vulnerability), `0` otherwise — suitable for CI gates.
|
|
49
|
+
|
|
50
|
+
## CI
|
|
51
|
+
|
|
52
|
+
- `.github/workflows/test.yml` runs the unit tests on Python 3.11–3.13 for
|
|
53
|
+
every push/PR to `main`, plus a CLI smoke test.
|
|
54
|
+
- `.github/workflows/publish.yml` builds and publishes to PyPI via trusted
|
|
55
|
+
publishing (OIDC) when a GitHub release is published. The first publish
|
|
56
|
+
requires registering the project / trusted publisher on PyPI.
|
|
57
|
+
|
|
58
|
+
## Development
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
PYTHONPATH=src python -m unittest discover -s tests -v
|
|
62
|
+
```
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "crossdep-audit"
|
|
7
|
+
version = "0.2.0"
|
|
8
|
+
description = "Cross-platform dependency auditor: scans manifests and lockfiles for known vulnerabilities and outdated libraries"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
authors = [{ name = "ProTechSean" }]
|
|
13
|
+
keywords = ["security", "vulnerability", "dependencies", "audit", "osv", "sarif", "lockfile"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 4 - Beta",
|
|
16
|
+
"Environment :: Console",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"License :: OSI Approved :: MIT License",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3.11",
|
|
21
|
+
"Programming Language :: Python :: 3.12",
|
|
22
|
+
"Programming Language :: Python :: 3.13",
|
|
23
|
+
"Topic :: Security",
|
|
24
|
+
"Topic :: Software Development :: Quality Assurance",
|
|
25
|
+
]
|
|
26
|
+
dependencies = []
|
|
27
|
+
|
|
28
|
+
[project.urls]
|
|
29
|
+
Repository = "https://github.com/SeanShaffer88/crossdep-audit"
|
|
30
|
+
Issues = "https://github.com/SeanShaffer88/crossdep-audit/issues"
|
|
31
|
+
|
|
32
|
+
[project.scripts]
|
|
33
|
+
crossdep-audit = "crossdep_audit.cli:main"
|
|
34
|
+
|
|
35
|
+
[tool.setuptools.packages.find]
|
|
36
|
+
where = ["src"]
|
|
37
|
+
|
|
38
|
+
[tool.setuptools.package-data]
|
|
39
|
+
crossdep_audit = ["advisories.json"]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.2.0"
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
[
|
|
2
|
+
{"id": "CVE-2021-23337", "ecosystem": "npm", "package": "lodash", "summary": "Command injection via template in lodash", "severity": "HIGH", "constraints": "<4.17.21"},
|
|
3
|
+
{"id": "CVE-2020-8203", "ecosystem": "npm", "package": "lodash", "summary": "Prototype pollution in lodash zipObjectDeep", "severity": "HIGH", "constraints": "<4.17.19"},
|
|
4
|
+
{"id": "CVE-2021-44906", "ecosystem": "npm", "package": "minimist", "summary": "Prototype pollution in minimist", "severity": "HIGH", "constraints": "<1.2.6"},
|
|
5
|
+
{"id": "CVE-2022-23529", "ecosystem": "npm", "package": "jsonwebtoken", "summary": "Insecure default algorithm acceptance in jsonwebtoken", "severity": "HIGH", "constraints": "<9.0.0"},
|
|
6
|
+
{"id": "CVE-2022-29078", "ecosystem": "npm", "package": "ejs", "summary": "Server-side template injection in ejs", "severity": "HIGH", "constraints": "<3.1.7"},
|
|
7
|
+
{"id": "CVE-2021-23369", "ecosystem": "npm", "package": "handlebars", "summary": "Prototype pollution in handlebars", "severity": "HIGH", "constraints": "<4.7.7"},
|
|
8
|
+
{"id": "CVE-2022-31129", "ecosystem": "npm", "package": "moment", "summary": "Path traversal in moment locale loading", "severity": "MODERATE", "constraints": "<2.29.4"},
|
|
9
|
+
{"id": "CVE-2021-23358", "ecosystem": "npm", "package": "underscore", "summary": "Arbitrary code execution in underscore template", "severity": "MODERATE", "constraints": "<1.12.1"},
|
|
10
|
+
{"id": "CVE-2023-26136", "ecosystem": "npm", "package": "tough-cookie", "summary": "Prototype pollution in tough-cookie", "severity": "MODERATE", "constraints": "<4.1.3"},
|
|
11
|
+
{"id": "CVE-2021-27290", "ecosystem": "npm", "package": "ssri", "summary": "Regular expression denial of service in ssri", "severity": "MODERATE", "constraints": "<6.0.2"},
|
|
12
|
+
{"id": "CVE-2024-3727", "ecosystem": "PyPI", "package": "requests", "summary": "Netrc credentials leaked to third-party hosts", "severity": "HIGH", "constraints": "<2.32.0"},
|
|
13
|
+
{"id": "CVE-2023-32681", "ecosystem": "PyPI", "package": "requests", "summary": "Proxy-Authorization header leaked on redirect", "severity": "MODERATE", "constraints": "<2.31.0"},
|
|
14
|
+
{"id": "CVE-2023-43665", "ecosystem": "PyPI", "package": "urllib3", "summary": "Cookie header leaked on cross-origin redirect", "severity": "MODERATE", "constraints": ">=1.25.0,<1.26.17"},
|
|
15
|
+
{"id": "CVE-2021-3618", "ecosystem": "PyPI", "package": "urllib3", "summary": "CRLF injection via request method", "severity": "HIGH", "constraints": "<1.26.5"},
|
|
16
|
+
{"id": "CVE-2023-24329", "ecosystem": "PyPI", "package": "urllib3", "summary": "Bypass of bracketed host protections", "severity": "HIGH", "constraints": "<1.26.9"},
|
|
17
|
+
{"id": "CVE-2023-30608", "ecosystem": "PyPI", "package": "sqlparse", "summary": "Denial of service via crafted SQL input", "severity": "MODERATE", "constraints": "<0.4.4"},
|
|
18
|
+
{"id": "CVE-2020-27619", "ecosystem": "PyPI", "package": "py", "summary": "Denial of service in py library", "severity": "MODERATE", "constraints": "<1.11.0"},
|
|
19
|
+
{"id": "CVE-2022-45198", "ecosystem": "PyPI", "package": "pillow", "summary": "Denial of service via crafted image in Pillow", "severity": "HIGH", "constraints": "<9.3.0"},
|
|
20
|
+
{"id": "CVE-2024-34064", "ecosystem": "PyPI", "package": "jinja2", "summary": "Sandbox escape via str.format in Jinja2", "severity": "HIGH", "constraints": "<3.1.4"},
|
|
21
|
+
{"id": "CVE-2020-28493", "ecosystem": "PyPI", "package": "jinja2", "summary": "Sandbox escape via xmlattr filter in Jinja2", "severity": "MODERATE", "constraints": "<3.0.3"},
|
|
22
|
+
{"id": "CVE-2023-45803", "ecosystem": "RubyGems", "package": "rack", "summary": "Denial of service via crafted Range header", "severity": "MODERATE", "constraints": ">=3.0.0,<3.0.8"},
|
|
23
|
+
{"id": "CVE-2022-30122", "ecosystem": "RubyGems", "package": "rack", "summary": "Denial of service in multipart parsing", "severity": "MODERATE", "constraints": ">=2.0.0,<2.2.3.1"},
|
|
24
|
+
{"id": "CVE-2022-30187", "ecosystem": "crates.io", "package": "regex", "summary": "Denial of service in regex crate", "severity": "MODERATE", "constraints": "<1.5.5"},
|
|
25
|
+
{"id": "CVE-2023-39325", "ecosystem": "Go", "package": "golang.org/x/net", "summary": "HTTP/2 rapid reset denial of service", "severity": "HIGH", "constraints": "<0.17.0"},
|
|
26
|
+
{"id": "CVE-2022-32149", "ecosystem": "Go", "package": "golang.org/x/text", "summary": "Denial of service in language parsing", "severity": "HIGH", "constraints": "<0.3.8"},
|
|
27
|
+
{"id": "CVE-2021-44228", "ecosystem": "Maven", "package": "org.apache.logging.log4j:log4j-core", "summary": "Remote code execution in Log4j2 (Log4Shell)", "severity": "CRITICAL", "constraints": "<2.17.1"}
|
|
28
|
+
]
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from importlib.resources import files
|
|
3
|
+
|
|
4
|
+
from .model import Dependency
|
|
5
|
+
from .versions import matches_constraints
|
|
6
|
+
|
|
7
|
+
BUILTIN_ADVISORIES = json.loads(files("crossdep_audit").joinpath("advisories.json").read_text())
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def find_builtin(dep: Dependency) -> list[dict]:
|
|
11
|
+
if not dep.version:
|
|
12
|
+
return []
|
|
13
|
+
hits = []
|
|
14
|
+
for adv in BUILTIN_ADVISORIES:
|
|
15
|
+
if adv["ecosystem"] != dep.ecosystem:
|
|
16
|
+
continue
|
|
17
|
+
if adv["package"].lower() != dep.name.lower():
|
|
18
|
+
continue
|
|
19
|
+
try:
|
|
20
|
+
if matches_constraints(dep.version, adv["constraints"]):
|
|
21
|
+
hits.append(adv)
|
|
22
|
+
except ValueError:
|
|
23
|
+
continue
|
|
24
|
+
return hits
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import os
|
|
3
|
+
import time
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
_TTL_SECONDS = 24 * 3600
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def _path() -> Path:
|
|
10
|
+
return Path(os.environ.get("CROSSDEP_AUDIT_CACHE", str(Path.home() / ".cache" / "crossdep-audit" / "cache.json")))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def _load() -> dict:
|
|
14
|
+
try:
|
|
15
|
+
data = json.loads(_path().read_text())
|
|
16
|
+
if isinstance(data, dict):
|
|
17
|
+
return data
|
|
18
|
+
except Exception:
|
|
19
|
+
pass
|
|
20
|
+
return {}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _save(data: dict) -> None:
|
|
24
|
+
try:
|
|
25
|
+
path = _path()
|
|
26
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
27
|
+
path.write_text(json.dumps(data))
|
|
28
|
+
except Exception:
|
|
29
|
+
pass
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def cache_get(key: str):
|
|
33
|
+
entry = _load().get(key)
|
|
34
|
+
if isinstance(entry, dict) and time.time() - entry.get("ts", 0) < _TTL_SECONDS:
|
|
35
|
+
return entry.get("value")
|
|
36
|
+
return None
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def cache_set(key: str, value) -> None:
|
|
40
|
+
data = _load()
|
|
41
|
+
data[key] = {"ts": time.time(), "value": value}
|
|
42
|
+
_save(data)
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
from . import osv, registries
|
|
5
|
+
from .advisories import find_builtin
|
|
6
|
+
from .cache import cache_get, cache_set
|
|
7
|
+
from .model import OutdatedDependency, Vulnerability
|
|
8
|
+
from .report import render_json, render_sarif, render_text
|
|
9
|
+
from .scanners import scan_project
|
|
10
|
+
from .severity import rank, threshold
|
|
11
|
+
from .versions import compare_versions, diff_kind
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
15
|
+
parser = argparse.ArgumentParser(
|
|
16
|
+
prog="crossdep-audit",
|
|
17
|
+
description="Scan project manifests/lockfiles for known vulnerabilities and outdated libraries.",
|
|
18
|
+
)
|
|
19
|
+
parser.add_argument("path", nargs="?", default=".",
|
|
20
|
+
help="Project root to scan (default: current directory)")
|
|
21
|
+
parser.add_argument("--format", choices=["text", "json", "sarif"], default="text",
|
|
22
|
+
help="Output format (default: text)")
|
|
23
|
+
parser.add_argument("--json", action="store_true", help="Shortcut for --format json")
|
|
24
|
+
parser.add_argument("--offline", action="store_true",
|
|
25
|
+
help="Skip all network lookups (OSV and registry checks); uses the built-in advisory list only")
|
|
26
|
+
parser.add_argument("--no-vulns", action="store_true", help="Skip vulnerability checks")
|
|
27
|
+
parser.add_argument("--no-outdated", action="store_true", help="Skip outdated-library checks")
|
|
28
|
+
parser.add_argument("--fail-on", choices=["any", "low", "moderate", "high", "critical"],
|
|
29
|
+
default="any",
|
|
30
|
+
help="Minimum severity that makes the exit code 1 (default: any)")
|
|
31
|
+
parser.add_argument("--no-cache", action="store_true",
|
|
32
|
+
help="Disable the local 24h cache of OSV/registry lookups")
|
|
33
|
+
return parser
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _collect_vulnerabilities(deps, offline: bool, use_cache: bool) -> list[Vulnerability]:
|
|
37
|
+
vulns: list[Vulnerability] = []
|
|
38
|
+
seen: set[tuple[str, str, str, str]] = set()
|
|
39
|
+
pinned = [d for d in deps if d.version]
|
|
40
|
+
for d in pinned:
|
|
41
|
+
for adv in find_builtin(d):
|
|
42
|
+
key = (adv["id"], d.ecosystem, d.name, d.version)
|
|
43
|
+
if key not in seen:
|
|
44
|
+
seen.add(key)
|
|
45
|
+
vulns.append(Vulnerability(d, adv["id"], adv["summary"], adv["severity"], "builtin"))
|
|
46
|
+
if offline:
|
|
47
|
+
return vulns
|
|
48
|
+
keys = [(d.ecosystem, d.name, d.version) for d in pinned]
|
|
49
|
+
results: dict[tuple[str, str, str], list[dict]] = {}
|
|
50
|
+
missing = []
|
|
51
|
+
for k in keys:
|
|
52
|
+
if use_cache:
|
|
53
|
+
hit = cache_get(f"osv:{k[0]}:{k[1]}:{k[2]}")
|
|
54
|
+
if hit is not None:
|
|
55
|
+
results[k] = hit
|
|
56
|
+
continue
|
|
57
|
+
missing.append(k)
|
|
58
|
+
if missing:
|
|
59
|
+
fresh = osv.query_osv_batch(missing)
|
|
60
|
+
for k in missing:
|
|
61
|
+
value = fresh.get(k, [])
|
|
62
|
+
results[k] = value
|
|
63
|
+
if use_cache:
|
|
64
|
+
cache_set(f"osv:{k[0]}:{k[1]}:{k[2]}", value)
|
|
65
|
+
for d in pinned:
|
|
66
|
+
for v in results.get((d.ecosystem, d.name, d.version), []):
|
|
67
|
+
key = (v["id"], d.ecosystem, d.name, d.version)
|
|
68
|
+
if key not in seen:
|
|
69
|
+
seen.add(key)
|
|
70
|
+
vulns.append(Vulnerability(d, v["id"], v["summary"], v["severity"], "osv"))
|
|
71
|
+
return vulns
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def _collect_outdated(deps, offline: bool, use_cache: bool) -> list[OutdatedDependency]:
|
|
75
|
+
outdated: list[OutdatedDependency] = []
|
|
76
|
+
if offline:
|
|
77
|
+
return outdated
|
|
78
|
+
for d in deps:
|
|
79
|
+
if not d.version:
|
|
80
|
+
continue
|
|
81
|
+
ckey = f"latest:{d.ecosystem}:{d.name}"
|
|
82
|
+
latest = cache_get(ckey) if use_cache else None
|
|
83
|
+
if latest is None:
|
|
84
|
+
latest = registries.latest_version(d.ecosystem, d.name)
|
|
85
|
+
if use_cache and latest:
|
|
86
|
+
cache_set(ckey, latest)
|
|
87
|
+
if latest and compare_versions(d.version, latest) < 0:
|
|
88
|
+
outdated.append(OutdatedDependency(d, latest, diff_kind(d.version, latest)))
|
|
89
|
+
return outdated
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def main(argv: list[str] | None = None) -> int:
|
|
93
|
+
args = build_parser().parse_args(argv)
|
|
94
|
+
fmt = "json" if args.json and args.format == "text" else args.format
|
|
95
|
+
root = Path(args.path)
|
|
96
|
+
deps = scan_project(root)
|
|
97
|
+
if not deps:
|
|
98
|
+
print(f"No supported dependency manifests found in {root.resolve()}")
|
|
99
|
+
return 0
|
|
100
|
+
|
|
101
|
+
use_cache = not args.no_cache
|
|
102
|
+
vulns = [] if args.no_vulns else _collect_vulnerabilities(deps, args.offline, use_cache)
|
|
103
|
+
outdated = [] if args.no_outdated else _collect_outdated(deps, args.offline, use_cache)
|
|
104
|
+
|
|
105
|
+
if fmt == "json":
|
|
106
|
+
print(render_json(root, deps, vulns, outdated))
|
|
107
|
+
elif fmt == "sarif":
|
|
108
|
+
print(render_sarif(root, vulns))
|
|
109
|
+
else:
|
|
110
|
+
print(render_text(root, deps, vulns, outdated))
|
|
111
|
+
|
|
112
|
+
min_rank = threshold(args.fail_on)
|
|
113
|
+
return 1 if any(rank(v.severity) >= min_rank for v in vulns) else 0
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
@dataclass
|
|
5
|
+
class Dependency:
|
|
6
|
+
name: str
|
|
7
|
+
version: str | None
|
|
8
|
+
ecosystem: str
|
|
9
|
+
source: str
|
|
10
|
+
indirect: bool = False
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@dataclass
|
|
14
|
+
class Vulnerability:
|
|
15
|
+
dependency: Dependency
|
|
16
|
+
advisory_id: str
|
|
17
|
+
summary: str
|
|
18
|
+
severity: str
|
|
19
|
+
source: str
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@dataclass
|
|
23
|
+
class OutdatedDependency:
|
|
24
|
+
dependency: Dependency
|
|
25
|
+
latest: str
|
|
26
|
+
kind: str
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import urllib.request
|
|
3
|
+
|
|
4
|
+
OSV_QUERY_URL = "https://api.osv.dev/v1/query"
|
|
5
|
+
OSV_BATCH_URL = "https://api.osv.dev/v1/querybatch"
|
|
6
|
+
|
|
7
|
+
_ECOSYSTEMS = {"npm", "PyPI", "crates.io", "Go", "RubyGems", "Maven", "NuGet", "Packagist"}
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def _headers() -> dict:
|
|
11
|
+
return {"Content-Type": "application/json", "User-Agent": "crossdep-audit/0.2"}
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _normalize(vuln: dict) -> dict:
|
|
15
|
+
severity = str((vuln.get("ecosystem_specific") or {}).get("severity", "")).upper()
|
|
16
|
+
if not severity:
|
|
17
|
+
sev = vuln.get("severity") or []
|
|
18
|
+
if sev and isinstance(sev[0], dict):
|
|
19
|
+
severity = "UNKNOWN"
|
|
20
|
+
summary = vuln.get("summary") or (vuln.get("details") or "")[:160]
|
|
21
|
+
return {
|
|
22
|
+
"id": vuln.get("id", "UNKNOWN"),
|
|
23
|
+
"summary": summary,
|
|
24
|
+
"severity": severity,
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def query_osv(ecosystem: str, name: str, version: str, timeout: int = 10) -> list[dict]:
|
|
29
|
+
if ecosystem not in _ECOSYSTEMS or not version:
|
|
30
|
+
return []
|
|
31
|
+
body = json.dumps({
|
|
32
|
+
"package": {"name": name, "ecosystem": ecosystem},
|
|
33
|
+
"version": version,
|
|
34
|
+
}).encode()
|
|
35
|
+
req = urllib.request.Request(OSV_QUERY_URL, data=body, headers=_headers())
|
|
36
|
+
try:
|
|
37
|
+
with urllib.request.urlopen(req, timeout=timeout) as resp:
|
|
38
|
+
data = json.loads(resp.read())
|
|
39
|
+
except Exception:
|
|
40
|
+
return []
|
|
41
|
+
return [_normalize(v) for v in data.get("vulns", [])]
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def query_osv_batch(items: list[tuple[str, str, str]], timeout: int = 30) -> dict[tuple[str, str, str], list[dict]]:
|
|
45
|
+
filtered = [(e, n, v) for e, n, v in items if e in _ECOSYSTEMS and v]
|
|
46
|
+
if not filtered:
|
|
47
|
+
return {}
|
|
48
|
+
body = json.dumps({
|
|
49
|
+
"queries": [
|
|
50
|
+
{"package": {"name": n, "ecosystem": e}, "version": v}
|
|
51
|
+
for e, n, v in filtered
|
|
52
|
+
]
|
|
53
|
+
}).encode()
|
|
54
|
+
req = urllib.request.Request(OSV_BATCH_URL, data=body, headers=_headers())
|
|
55
|
+
try:
|
|
56
|
+
with urllib.request.urlopen(req, timeout=timeout) as resp:
|
|
57
|
+
data = json.loads(resp.read())
|
|
58
|
+
except Exception:
|
|
59
|
+
return {key: [] for key in filtered}
|
|
60
|
+
out: dict[tuple[str, str, str], list[dict]] = {}
|
|
61
|
+
for key, result in zip(filtered, data.get("results", [])):
|
|
62
|
+
out[key] = [_normalize(v) for v in (result or {}).get("vulns", [])]
|
|
63
|
+
return out
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import urllib.request
|
|
3
|
+
import xml.etree.ElementTree as ET
|
|
4
|
+
from urllib.parse import quote
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def _get(url: str, timeout: int = 10) -> bytes:
|
|
8
|
+
req = urllib.request.Request(
|
|
9
|
+
url, headers={"User-Agent": "crossdep-audit/0.2 (dependency audit)"}
|
|
10
|
+
)
|
|
11
|
+
with urllib.request.urlopen(req, timeout=timeout) as resp:
|
|
12
|
+
return resp.read()
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _get_json(url: str, timeout: int = 10) -> dict:
|
|
16
|
+
return json.loads(_get(url, timeout))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def _latest_maven(name: str) -> str | None:
|
|
20
|
+
group, _, artifact = name.partition(":")
|
|
21
|
+
if not artifact:
|
|
22
|
+
return None
|
|
23
|
+
path = group.replace(".", "/")
|
|
24
|
+
xml = _get(f"https://repo1.maven.org/maven2/{path}/{artifact}/maven-metadata.xml")
|
|
25
|
+
root = ET.fromstring(xml)
|
|
26
|
+
release = root.findtext("versioning/release") or root.findtext("versioning/latest")
|
|
27
|
+
if release:
|
|
28
|
+
return release
|
|
29
|
+
versions = [v.text for v in root.findall("versioning/versions/version") if v.text]
|
|
30
|
+
return versions[-1] if versions else None
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def latest_version(ecosystem: str, name: str) -> str | None:
|
|
34
|
+
try:
|
|
35
|
+
if ecosystem == "npm":
|
|
36
|
+
data = _get_json(f"https://registry.npmjs.org/{quote(name, safe='@/')}")
|
|
37
|
+
return (data.get("dist-tags") or {}).get("latest")
|
|
38
|
+
if ecosystem == "PyPI":
|
|
39
|
+
data = _get_json(f"https://pypi.org/pypi/{quote(name)}/json")
|
|
40
|
+
return (data.get("info") or {}).get("version")
|
|
41
|
+
if ecosystem == "crates.io":
|
|
42
|
+
data = _get_json(f"https://crates.io/api/v1/crates/{quote(name)}")
|
|
43
|
+
crate = data.get("crate") or {}
|
|
44
|
+
return crate.get("max_stable_version") or crate.get("newest_version")
|
|
45
|
+
if ecosystem == "Go":
|
|
46
|
+
data = _get_json(f"https://proxy.golang.org/{name}/@latest")
|
|
47
|
+
return data.get("Version")
|
|
48
|
+
if ecosystem == "RubyGems":
|
|
49
|
+
data = _get_json(f"https://rubygems.org/api/v1/gems/{quote(name)}.json")
|
|
50
|
+
return data.get("version")
|
|
51
|
+
if ecosystem == "Maven":
|
|
52
|
+
return _latest_maven(name)
|
|
53
|
+
if ecosystem == "NuGet":
|
|
54
|
+
data = _get_json(f"https://api.nuget.org/v3-flatcontainer/{quote(name.lower())}/index.json")
|
|
55
|
+
versions = data.get("versions") or []
|
|
56
|
+
return versions[-1] if versions else None
|
|
57
|
+
if ecosystem == "Packagist":
|
|
58
|
+
data = _get_json(f"https://repo.packagist.org/p2/{quote(name)}.json")
|
|
59
|
+
pkgs = (data.get("packages") or {}).get(name) or []
|
|
60
|
+
return pkgs[0].get("version") if pkgs else None
|
|
61
|
+
except Exception:
|
|
62
|
+
return None
|
|
63
|
+
return None
|