bmsdna-devtools 0.53.0__tar.gz → 0.54.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.
- bmsdna_devtools-0.53.0/README.md → bmsdna_devtools-0.54.0/PKG-INFO +61 -0
- bmsdna_devtools-0.53.0/PKG-INFO → bmsdna_devtools-0.54.0/README.md +42 -18
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/cli.py +2 -0
- bmsdna_devtools-0.54.0/bmsdna/devtools/deps/__init__.py +7 -0
- bmsdna_devtools-0.54.0/bmsdna/devtools/deps/advisories.py +500 -0
- bmsdna_devtools-0.54.0/bmsdna/devtools/deps/cli.py +151 -0
- bmsdna_devtools-0.54.0/bmsdna/devtools/deps/lockfiles.py +210 -0
- bmsdna_devtools-0.54.0/bmsdna/devtools/deps/osv.py +137 -0
- bmsdna_devtools-0.54.0/bmsdna/devtools/deps/versions.py +219 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/pyproject.toml +2 -1
- bmsdna_devtools-0.54.0/tests/test_cli_deps.py +124 -0
- bmsdna_devtools-0.54.0/tests/test_deps_advisories.py +238 -0
- bmsdna_devtools-0.54.0/tests/test_deps_lockfiles.py +143 -0
- bmsdna_devtools-0.54.0/tests/test_deps_osv.py +92 -0
- bmsdna_devtools-0.54.0/tests/test_deps_versions.py +89 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/uv.lock +3 -1
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/.github/workflows/auto-release.yml +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/.github/workflows/python-publish.yml +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/.github/workflows/python-test.yml +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/.gitignore +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/.python-version +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/__init__.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/_api_dump.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/ado_auth.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/ado_issue.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/agent_mentions.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/api_usage.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/app_service_logs.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/azure_arm.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/azure_auth.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/bdt_config.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/business_user.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/ci_plan.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/ci_plan_env.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/cli_tools.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/commit.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/dead_code.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/env_config.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/env_files.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/find_injection.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/find_repo.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/gh_args.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/gh_issue.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/gh_pr.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/github_api.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/gitrepo.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/injection_frontend.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/injection_python.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/issue_do.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/issue_show.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/issue_watch.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/lint.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/lint_findings.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/lint_models.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/lint_sql.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/lint_sql_files.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/lint_tooling.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/lint_typescript.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/logs.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/pr_build.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/pr_cancel.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/pr_choice.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/pr_create_args.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/pr_info.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/pr_issue_link.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/pr_labels.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/pr_markdown.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/pr_merge_defaults.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/pr_ref.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/pull.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/testdb.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/translate.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/usage/__init__.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/usage/cli.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/usage/pipeline.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/usage/pricing.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/usage/report.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/usage/sql/00_schema.sql +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/usage/sql/01_ingest_claude.sql +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/usage/sql/01_ingest_codex.sql +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/usage/sql/02_messages.sql +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/usage/sql/03_markers.sql +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/usage/sql/04_facts.sql +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/usage/sql/05_views.sql +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/bmsdna/devtools/worktree.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/justfile +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/skills/bmsdna-devtools/SKILL.md +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/conftest.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/fake_github.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_ado_auth.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_ado_issue.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_ado_issue_flow.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_agent_mentions.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_api_usage.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_app_service_logs.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_azure_arm.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_bdt_config.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_business_user.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_ci_plan.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_ci_plan_env.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_cli_cleanup.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_cli_commit.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_cli_issue.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_cli_pr_create.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_cli_pr_id.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_cli_pull.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_cli_tools.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_cli_version.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_commit.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_env_config.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_env_files.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_find_injection.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_find_repo.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_gh_issue.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_gh_pr.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_github_api.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_gitrepo.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_issue_do.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_issue_for_me.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_issue_show.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_issue_watch.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_lint.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_lint_models.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_lint_sql.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_lint_sql_files.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_lint_tooling.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_lint_typescript.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_logs.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_pr_build.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_pr_build_create_options.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_pr_build_flow.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_pr_cancel_build.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_pr_choice.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_pr_create_args.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_pr_description_not_truncated.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_pr_info.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_pr_issue_link.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_pr_labels.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_pr_markdown.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_pr_merge_defaults.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_pull.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_testdb.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_translate.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_usage.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_wait_timeout.py +0 -0
- {bmsdna_devtools-0.53.0 → bmsdna_devtools-0.54.0}/tests/test_worktree_clean.py +0 -0
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: bmsdna-devtools
|
|
3
|
+
Version: 0.54.0
|
|
4
|
+
Summary: Shared Azure DevOps / GitHub / git / Azure Monitor developer tooling for BMS projects
|
|
5
|
+
Requires-Python: >=3.14
|
|
6
|
+
Requires-Dist: azure-identity>=1.19.0
|
|
7
|
+
Requires-Dist: packaging>=24.0
|
|
8
|
+
Requires-Dist: pgdevkit[db]>=0.7.1
|
|
9
|
+
Requires-Dist: requests>=2.32.0
|
|
10
|
+
Requires-Dist: rich>=13.0.0
|
|
11
|
+
Requires-Dist: tomli-w>=1.0.0
|
|
12
|
+
Requires-Dist: typer>=0.26.7
|
|
13
|
+
Provides-Extra: lint
|
|
14
|
+
Requires-Dist: sqlglot>=27.0.0; extra == 'lint'
|
|
15
|
+
Provides-Extra: usage
|
|
16
|
+
Requires-Dist: duckdb>=1.3.0; extra == 'usage'
|
|
17
|
+
Requires-Dist: plotly>=5.24.0; extra == 'usage'
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
|
|
1
20
|
# bmsdna-devtools
|
|
2
21
|
|
|
3
22
|
Shared developer tooling for BMS projects: PR build/check status and a
|
|
@@ -1192,6 +1211,48 @@ catch-all, service-to-service endpoints and an external API folder.
|
|
|
1192
1211
|
then on only *new* unused routes fail -- and a baseline line whose route has since been deleted, excluded or
|
|
1193
1212
|
used is reported as `api-route-baseline-stale`, so the list can only shrink.
|
|
1194
1213
|
|
|
1214
|
+
## `bdt deps affected` / `bdt deps advisories`
|
|
1215
|
+
|
|
1216
|
+
Security incidents and supply chain attacks (bmsuisse/devtools#113): which locked dependencies are touched? Both
|
|
1217
|
+
commands only read: they never edit a file, a lock or an environment. They cover `uv.lock` (PyPI) and `bun.lock` (npm)
|
|
1218
|
+
below each `--path` (default: the current directory; `node_modules`, virtualenvs, `.git` and `.worktrees` are skipped).
|
|
1219
|
+
Git, path, alias and workspace sources can't be matched against an advisory: they are listed as `unsupported`, never skipped.
|
|
1220
|
+
|
|
1221
|
+
```bash
|
|
1222
|
+
bdt deps affected lodash --version-spec "<4.17.21" --path ~/projects/CCMT2 --path ~/projects/OneSales
|
|
1223
|
+
bdt deps advisories --path . # OSV lookup of every locked version, one status per affected package
|
|
1224
|
+
bdt deps advisories --json # machine-readable
|
|
1225
|
+
```
|
|
1226
|
+
|
|
1227
|
+
`affected PACKAGE` lists the locked versions of one package (PyPI names are normalised, npm names exact; `--ecosystem`
|
|
1228
|
+
narrows) and marks those matching `--version-spec` (comparators such as `<4.17.21` or `>=1.0,<2`, comma = and). Exit 0
|
|
1229
|
+
none matches, 1 a locked version matches, 2 setup error (no lockfile, unreadable lockfile, bad spec), 3 incomplete (a
|
|
1230
|
+
git/path/alias source of that name could not be matched).
|
|
1231
|
+
|
|
1232
|
+
`advisories` queries [OSV](https://osv.dev) (GHSA, PYSEC and the OpenSSF `MAL-` malicious-package advisories) and the
|
|
1233
|
+
CISA KEV feed, groups aliases (GHSA = PYSEC = CVE) and reports per locked package one status. The maintenance skill's
|
|
1234
|
+
cooldown exception flow (`references/audit.md`) acts on it:
|
|
1235
|
+
|
|
1236
|
+
| Status | Meaning |
|
|
1237
|
+
|---|---|
|
|
1238
|
+
| `malicious` | a `MAL-` advisory covers the locked version: an incident, not a bump |
|
|
1239
|
+
| `needs-triage` | affected range, fix, or (when the fix is inside the cooldown) severity is missing, conflicting or unparseable |
|
|
1240
|
+
| `no-fix` | an affected advisory has no fixed version |
|
|
1241
|
+
| `blocked` | the fixed version is outside the range the project declares for a direct dependency |
|
|
1242
|
+
| `exempt-eligible` | high/critical (CVSS v3 score >= 7 and/or GHSA label; sources that disagree go to triage) or in CISA KEV, and the fixed version is younger than the cooldown (or its age is unknown) |
|
|
1243
|
+
| `bump` | the fixed version is older than the cooldown: a normal bump takes it |
|
|
1244
|
+
| `informational` | affected, lower severity, fix still inside the cooldown |
|
|
1245
|
+
|
|
1246
|
+
The target version is the lowest one the advisory data shows to be outside every affected range of the urgent
|
|
1247
|
+
advisories (all of them when none is urgent), never "latest". Lower-severity advisories that need a newer version stay open until a normal bump, and the finding names them. `next:` lines give the per-invocation commands. Unsupported sources are listed but don't change the exit code. The fix's age
|
|
1248
|
+
comes from the registry (PyPI: youngest file; npm: `time[version]`); `--cooldown-days` (default 5) is the project's
|
|
1249
|
+
cooldown. Compatibility with the parents' ranges of a *transitive* dependency isn't known here: re-run after the bump.
|
|
1250
|
+
|
|
1251
|
+
It fails closed: OSV, KEV or an advisory record that can't be read is reported as `incomplete` with exit 3, never as
|
|
1252
|
+
"no advisory". Exit 0 no affected locked version, 1 affected, 2 setup error, 3 incomplete. `uv audit` / `bun audit`
|
|
1253
|
+
remain the per-repo CI checks; this command adds what they don't give uniformly (fixed version and severity for both
|
|
1254
|
+
ecosystems, KEV, `MAL-` advisories, the fix's age against the cooldown) and scans many repos in one run.
|
|
1255
|
+
|
|
1195
1256
|
## `bdt find-injection`
|
|
1196
1257
|
|
|
1197
1258
|
Scans backend and frontend code for injection risks, and warns when a web project has no
|
|
@@ -1,21 +1,3 @@
|
|
|
1
|
-
Metadata-Version: 2.5
|
|
2
|
-
Name: bmsdna-devtools
|
|
3
|
-
Version: 0.53.0
|
|
4
|
-
Summary: Shared Azure DevOps / GitHub / git / Azure Monitor developer tooling for BMS projects
|
|
5
|
-
Requires-Python: >=3.14
|
|
6
|
-
Requires-Dist: azure-identity>=1.19.0
|
|
7
|
-
Requires-Dist: pgdevkit[db]>=0.7.1
|
|
8
|
-
Requires-Dist: requests>=2.32.0
|
|
9
|
-
Requires-Dist: rich>=13.0.0
|
|
10
|
-
Requires-Dist: tomli-w>=1.0.0
|
|
11
|
-
Requires-Dist: typer>=0.26.7
|
|
12
|
-
Provides-Extra: lint
|
|
13
|
-
Requires-Dist: sqlglot>=27.0.0; extra == 'lint'
|
|
14
|
-
Provides-Extra: usage
|
|
15
|
-
Requires-Dist: duckdb>=1.3.0; extra == 'usage'
|
|
16
|
-
Requires-Dist: plotly>=5.24.0; extra == 'usage'
|
|
17
|
-
Description-Content-Type: text/markdown
|
|
18
|
-
|
|
19
1
|
# bmsdna-devtools
|
|
20
2
|
|
|
21
3
|
Shared developer tooling for BMS projects: PR build/check status and a
|
|
@@ -1210,6 +1192,48 @@ catch-all, service-to-service endpoints and an external API folder.
|
|
|
1210
1192
|
then on only *new* unused routes fail -- and a baseline line whose route has since been deleted, excluded or
|
|
1211
1193
|
used is reported as `api-route-baseline-stale`, so the list can only shrink.
|
|
1212
1194
|
|
|
1195
|
+
## `bdt deps affected` / `bdt deps advisories`
|
|
1196
|
+
|
|
1197
|
+
Security incidents and supply chain attacks (bmsuisse/devtools#113): which locked dependencies are touched? Both
|
|
1198
|
+
commands only read: they never edit a file, a lock or an environment. They cover `uv.lock` (PyPI) and `bun.lock` (npm)
|
|
1199
|
+
below each `--path` (default: the current directory; `node_modules`, virtualenvs, `.git` and `.worktrees` are skipped).
|
|
1200
|
+
Git, path, alias and workspace sources can't be matched against an advisory: they are listed as `unsupported`, never skipped.
|
|
1201
|
+
|
|
1202
|
+
```bash
|
|
1203
|
+
bdt deps affected lodash --version-spec "<4.17.21" --path ~/projects/CCMT2 --path ~/projects/OneSales
|
|
1204
|
+
bdt deps advisories --path . # OSV lookup of every locked version, one status per affected package
|
|
1205
|
+
bdt deps advisories --json # machine-readable
|
|
1206
|
+
```
|
|
1207
|
+
|
|
1208
|
+
`affected PACKAGE` lists the locked versions of one package (PyPI names are normalised, npm names exact; `--ecosystem`
|
|
1209
|
+
narrows) and marks those matching `--version-spec` (comparators such as `<4.17.21` or `>=1.0,<2`, comma = and). Exit 0
|
|
1210
|
+
none matches, 1 a locked version matches, 2 setup error (no lockfile, unreadable lockfile, bad spec), 3 incomplete (a
|
|
1211
|
+
git/path/alias source of that name could not be matched).
|
|
1212
|
+
|
|
1213
|
+
`advisories` queries [OSV](https://osv.dev) (GHSA, PYSEC and the OpenSSF `MAL-` malicious-package advisories) and the
|
|
1214
|
+
CISA KEV feed, groups aliases (GHSA = PYSEC = CVE) and reports per locked package one status. The maintenance skill's
|
|
1215
|
+
cooldown exception flow (`references/audit.md`) acts on it:
|
|
1216
|
+
|
|
1217
|
+
| Status | Meaning |
|
|
1218
|
+
|---|---|
|
|
1219
|
+
| `malicious` | a `MAL-` advisory covers the locked version: an incident, not a bump |
|
|
1220
|
+
| `needs-triage` | affected range, fix, or (when the fix is inside the cooldown) severity is missing, conflicting or unparseable |
|
|
1221
|
+
| `no-fix` | an affected advisory has no fixed version |
|
|
1222
|
+
| `blocked` | the fixed version is outside the range the project declares for a direct dependency |
|
|
1223
|
+
| `exempt-eligible` | high/critical (CVSS v3 score >= 7 and/or GHSA label; sources that disagree go to triage) or in CISA KEV, and the fixed version is younger than the cooldown (or its age is unknown) |
|
|
1224
|
+
| `bump` | the fixed version is older than the cooldown: a normal bump takes it |
|
|
1225
|
+
| `informational` | affected, lower severity, fix still inside the cooldown |
|
|
1226
|
+
|
|
1227
|
+
The target version is the lowest one the advisory data shows to be outside every affected range of the urgent
|
|
1228
|
+
advisories (all of them when none is urgent), never "latest". Lower-severity advisories that need a newer version stay open until a normal bump, and the finding names them. `next:` lines give the per-invocation commands. Unsupported sources are listed but don't change the exit code. The fix's age
|
|
1229
|
+
comes from the registry (PyPI: youngest file; npm: `time[version]`); `--cooldown-days` (default 5) is the project's
|
|
1230
|
+
cooldown. Compatibility with the parents' ranges of a *transitive* dependency isn't known here: re-run after the bump.
|
|
1231
|
+
|
|
1232
|
+
It fails closed: OSV, KEV or an advisory record that can't be read is reported as `incomplete` with exit 3, never as
|
|
1233
|
+
"no advisory". Exit 0 no affected locked version, 1 affected, 2 setup error, 3 incomplete. `uv audit` / `bun audit`
|
|
1234
|
+
remain the per-repo CI checks; this command adds what they don't give uniformly (fixed version and severity for both
|
|
1235
|
+
ecosystems, KEV, `MAL-` advisories, the fix's age against the cooldown) and scans many repos in one run.
|
|
1236
|
+
|
|
1213
1237
|
## `bdt find-injection`
|
|
1214
1238
|
|
|
1215
1239
|
Scans backend and frontend code for injection risks, and warns when a web project has no
|
|
@@ -41,6 +41,7 @@ from .bdt_config import find_pyproject, load_bdt_table
|
|
|
41
41
|
from .cli_tools import CLI_TIMEOUT_SECS, EXIT_WAIT_TIMEOUT, detect_agent_session, require_gh
|
|
42
42
|
from .github_api import GitHubClient
|
|
43
43
|
from .pr_create_args import PrCreateArgsError, extract_labels, parse_pr_create_args, resolve_body, unsupported_notes
|
|
44
|
+
from .deps.cli import deps_app
|
|
44
45
|
from .usage.cli import usage_app
|
|
45
46
|
from .gitrepo import (
|
|
46
47
|
AdoRemote,
|
|
@@ -133,6 +134,7 @@ logs_app = typer.Typer(name="logs", help="Application Insights / Log Analytics q
|
|
|
133
134
|
app.add_typer(logs_app, name="logs")
|
|
134
135
|
|
|
135
136
|
app.add_typer(usage_app, name="usage")
|
|
137
|
+
app.add_typer(deps_app, name="deps")
|
|
136
138
|
|
|
137
139
|
ci_app = typer.Typer(name="ci", help="CI helpers (Azure Pipelines)")
|
|
138
140
|
app.add_typer(ci_app, name="ci")
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"""`bdt deps`: which locked dependencies a security advisory or supply chain incident touches (bmsuisse/devtools#113).
|
|
2
|
+
|
|
3
|
+
- `lockfiles` -- read `uv.lock` (PyPI) and `bun.lock` (npm) into one shape
|
|
4
|
+
- `versions` -- version parsing, comparison and range matching per ecosystem
|
|
5
|
+
- `osv` -- OSV / CISA KEV / registry timestamp client (the only network code)
|
|
6
|
+
- `advisories` -- turns OSV records into a per-package status; pure logic, no I/O
|
|
7
|
+
"""
|
|
@@ -0,0 +1,500 @@
|
|
|
1
|
+
"""Advisory evaluation for `bdt deps advisories`: OSV records in, one status per affected locked package out.
|
|
2
|
+
|
|
3
|
+
Statuses (the maintenance skill's cooldown exception flow, references/audit.md, acts on them):
|
|
4
|
+
|
|
5
|
+
- `malicious` a `MAL-` advisory covers the locked version: an incident, not a bump
|
|
6
|
+
- `needs-triage` affected range, fix or (when the fix is younger than the cooldown) severity is missing, conflicting
|
|
7
|
+
or unparseable: a human decides, never an automatic exception
|
|
8
|
+
- `no-fix` an affected advisory has no fixed version
|
|
9
|
+
- `blocked` the fixed version is outside the range the project itself declares for a direct dependency
|
|
10
|
+
- `exempt-eligible` high/critical (or in CISA KEV) and the fixed version is younger than the cooldown (or its age is unknown)
|
|
11
|
+
- `bump` the fixed version is already older than the cooldown: a normal bump takes it
|
|
12
|
+
- `informational` affected, lower severity, fix still inside the cooldown: wait
|
|
13
|
+
|
|
14
|
+
The target is the lowest version the advisory data shows to be outside every affected range of the urgent advisories
|
|
15
|
+
(all of them when none is urgent), never "latest". Compatibility with parent ranges of *transitive* dependencies is not
|
|
16
|
+
known here; re-run after the bump to confirm the locked version moved.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from __future__ import annotations
|
|
20
|
+
|
|
21
|
+
from collections.abc import Callable, Iterable
|
|
22
|
+
from dataclasses import dataclass, field
|
|
23
|
+
from datetime import datetime
|
|
24
|
+
from typing import Any, Literal
|
|
25
|
+
|
|
26
|
+
from .lockfiles import LockedPackage, LockfileContent, Unsupported
|
|
27
|
+
from .osv import AdvisorySource, DataError, PackageQuery
|
|
28
|
+
from .versions import (
|
|
29
|
+
Ecosystem,
|
|
30
|
+
SemVer,
|
|
31
|
+
VersionError,
|
|
32
|
+
declared_range_satisfied,
|
|
33
|
+
normalize_name,
|
|
34
|
+
parse_version,
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
Status = Literal[
|
|
38
|
+
"malicious",
|
|
39
|
+
"needs-triage",
|
|
40
|
+
"no-fix",
|
|
41
|
+
"blocked",
|
|
42
|
+
"exempt-eligible",
|
|
43
|
+
"bump",
|
|
44
|
+
"informational",
|
|
45
|
+
]
|
|
46
|
+
URGENT_LABELS = frozenset({"HIGH", "CRITICAL"})
|
|
47
|
+
_SEVERITY_RANK = {"LOW": 0, "MODERATE": 1, "HIGH": 2, "CRITICAL": 3}
|
|
48
|
+
DEFAULT_COOLDOWN_DAYS = 5
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
@dataclass(frozen=True, slots=True)
|
|
52
|
+
class AffectedEntry:
|
|
53
|
+
ecosystem: str
|
|
54
|
+
name: str
|
|
55
|
+
ranges: tuple[tuple[str, tuple[dict[str, str], ...]], ...] # (range type, events)
|
|
56
|
+
versions: frozenset[str]
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
@dataclass(frozen=True, slots=True)
|
|
60
|
+
class Vuln:
|
|
61
|
+
id: str
|
|
62
|
+
aliases: frozenset[str]
|
|
63
|
+
summary: str
|
|
64
|
+
severity: str | None # GHSA label: LOW / MODERATE / HIGH / CRITICAL
|
|
65
|
+
affected: tuple[AffectedEntry, ...]
|
|
66
|
+
cvss: tuple[float, ...] = () # CVSS v3 base scores computed from OSV `severity[]` vectors
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def parse_vuln(raw: dict[str, Any]) -> Vuln:
|
|
70
|
+
label = ((raw.get("database_specific") or {}).get("severity") or "").upper() or None
|
|
71
|
+
if label == "MEDIUM":
|
|
72
|
+
label = "MODERATE"
|
|
73
|
+
entries = []
|
|
74
|
+
for aff in raw.get("affected", []):
|
|
75
|
+
package = aff.get("package") or {}
|
|
76
|
+
eco = package.get("ecosystem", "")
|
|
77
|
+
name = normalize_name("PyPI", package.get("name", "")) if eco == "PyPI" else package.get("name", "")
|
|
78
|
+
ranges = tuple((r.get("type", ""), tuple(r.get("events", []))) for r in aff.get("ranges", []))
|
|
79
|
+
entries.append(AffectedEntry(eco, name, ranges, frozenset(aff.get("versions", []))))
|
|
80
|
+
scores = tuple(
|
|
81
|
+
score
|
|
82
|
+
for score in (
|
|
83
|
+
cvss3_score(e.get("score", ""))
|
|
84
|
+
for e in raw.get("severity", [])
|
|
85
|
+
if e.get("type") in ("CVSS_V3", "CVSS_V3_1")
|
|
86
|
+
)
|
|
87
|
+
if score is not None
|
|
88
|
+
)
|
|
89
|
+
return Vuln(
|
|
90
|
+
raw["id"],
|
|
91
|
+
frozenset(raw.get("aliases", [])),
|
|
92
|
+
raw.get("summary") or raw.get("details", "")[:120],
|
|
93
|
+
label,
|
|
94
|
+
tuple(entries),
|
|
95
|
+
scores,
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
_CVSS_AV = {"N": 0.85, "A": 0.62, "L": 0.55, "P": 0.2}
|
|
100
|
+
_CVSS_AC = {"L": 0.77, "H": 0.44}
|
|
101
|
+
_CVSS_UI = {"N": 0.85, "R": 0.62}
|
|
102
|
+
_CVSS_CIA = {"H": 0.56, "L": 0.22, "N": 0.0}
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def _roundup(value: float) -> float:
|
|
106
|
+
scaled = round(value * 100000)
|
|
107
|
+
return scaled / 100000.0 if scaled % 10000 == 0 else (scaled // 10000 + 1) / 10.0
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def cvss3_score(vector: str) -> float | None:
|
|
111
|
+
"""Base score of a CVSS 3.0/3.1 vector (FIRST specification); None for anything else (v2, v4, malformed)."""
|
|
112
|
+
if not vector.startswith(("CVSS:3.0/", "CVSS:3.1/")):
|
|
113
|
+
return None
|
|
114
|
+
try:
|
|
115
|
+
m = dict(part.split(":", 1) for part in vector.split("/")[1:])
|
|
116
|
+
if m["S"] not in ("U", "C"):
|
|
117
|
+
return None
|
|
118
|
+
changed = m["S"] == "C"
|
|
119
|
+
pr = {"N": 0.85, "L": 0.68 if changed else 0.62, "H": 0.5 if changed else 0.27}[m["PR"]]
|
|
120
|
+
iss = 1 - (1 - _CVSS_CIA[m["C"]]) * (1 - _CVSS_CIA[m["I"]]) * (1 - _CVSS_CIA[m["A"]])
|
|
121
|
+
impact = 7.52 * (iss - 0.029) - 3.25 * (iss - 0.02) ** 15 if changed else 6.42 * iss
|
|
122
|
+
exploitability = 8.22 * _CVSS_AV[m["AV"]] * _CVSS_AC[m["AC"]] * pr * _CVSS_UI[m["UI"]]
|
|
123
|
+
except KeyError, ValueError:
|
|
124
|
+
return None
|
|
125
|
+
if impact <= 0:
|
|
126
|
+
return 0.0
|
|
127
|
+
return _roundup(min((1.08 if changed else 1.0) * (impact + exploitability), 10))
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def _band(score: float) -> str:
|
|
131
|
+
return "CRITICAL" if score >= 9 else "HIGH" if score >= 7 else "MODERATE" if score >= 4 else "LOW"
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
# ── fixed version of one advisory ────────────────────────────────────────────────────────────────────────────────
|
|
135
|
+
|
|
136
|
+
FixState = Literal["fixed", "no-fix", "unknown"]
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def _event_version(ecosystem: Ecosystem, text: str) -> Any:
|
|
140
|
+
if text == "0":
|
|
141
|
+
return SemVer(0, 0, 0) if ecosystem == "npm" else parse_version(ecosystem, "0")
|
|
142
|
+
return parse_version(ecosystem, text)
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def fix_for(vuln: Vuln, ecosystem: Ecosystem, name: str, version: str) -> tuple[FixState, str | None, str]:
|
|
146
|
+
"""The lowest version outside every affected interval of `vuln` that contains the locked `version`."""
|
|
147
|
+
try:
|
|
148
|
+
locked = parse_version(ecosystem, version)
|
|
149
|
+
except VersionError as exc:
|
|
150
|
+
return "unknown", None, str(exc)
|
|
151
|
+
entries = [a for a in vuln.affected if a.ecosystem == ecosystem and a.name == name]
|
|
152
|
+
if not entries:
|
|
153
|
+
return "unknown", None, "the advisory has no affected entry for this package"
|
|
154
|
+
fixed: list[tuple[Any, str]] = []
|
|
155
|
+
open_ended = False
|
|
156
|
+
try:
|
|
157
|
+
for entry in entries:
|
|
158
|
+
for range_type, events in entry.ranges:
|
|
159
|
+
if range_type not in ("ECOSYSTEM", "SEMVER"):
|
|
160
|
+
continue
|
|
161
|
+
parsed = []
|
|
162
|
+
for event in events:
|
|
163
|
+
for kind in ("introduced", "fixed", "last_affected"):
|
|
164
|
+
if kind in event:
|
|
165
|
+
parsed.append(
|
|
166
|
+
(
|
|
167
|
+
_event_version(ecosystem, event[kind]),
|
|
168
|
+
kind,
|
|
169
|
+
event[kind],
|
|
170
|
+
)
|
|
171
|
+
)
|
|
172
|
+
order = {"introduced": 0, "last_affected": 1, "fixed": 2}
|
|
173
|
+
parsed.sort(key=lambda e: (e[0], order[e[1]]))
|
|
174
|
+
start = None
|
|
175
|
+
for ver, kind, text in parsed:
|
|
176
|
+
if kind == "introduced":
|
|
177
|
+
start = ver
|
|
178
|
+
elif start is None:
|
|
179
|
+
continue
|
|
180
|
+
elif kind == "fixed":
|
|
181
|
+
if start <= locked < ver:
|
|
182
|
+
fixed.append((ver, text))
|
|
183
|
+
start = None
|
|
184
|
+
else: # last_affected: the interval is closed but names no fix
|
|
185
|
+
open_ended = open_ended or start <= locked <= ver
|
|
186
|
+
start = None
|
|
187
|
+
if start is not None and start <= locked:
|
|
188
|
+
open_ended = True # introduced with no upper bound
|
|
189
|
+
except VersionError as exc:
|
|
190
|
+
return "unknown", None, f"cannot interpret the affected ranges: {exc}"
|
|
191
|
+
if fixed:
|
|
192
|
+
return "fixed", max(fixed, key=lambda f: f[0])[1], ""
|
|
193
|
+
if open_ended:
|
|
194
|
+
return "no-fix", None, "the advisory lists no fixed version"
|
|
195
|
+
return (
|
|
196
|
+
"unknown",
|
|
197
|
+
None,
|
|
198
|
+
"the locked version is not inside any affected range the advisory describes",
|
|
199
|
+
)
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
# ── grouping aliases (GHSA-x = PYSEC-y = CVE-z) ──────────────────────────────────────────────────────────────────
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
@dataclass(slots=True)
|
|
206
|
+
class VulnGroup:
|
|
207
|
+
vulns: list[Vuln]
|
|
208
|
+
|
|
209
|
+
@property
|
|
210
|
+
def ids(self) -> list[str]:
|
|
211
|
+
return sorted(v.id for v in self.vulns)
|
|
212
|
+
|
|
213
|
+
@property
|
|
214
|
+
def cves(self) -> set[str]:
|
|
215
|
+
return {a.upper() for v in self.vulns for a in (v.aliases | {v.id}) if a.upper().startswith("CVE-")}
|
|
216
|
+
|
|
217
|
+
@property
|
|
218
|
+
def malicious(self) -> bool:
|
|
219
|
+
return any(v.id.startswith("MAL-") for v in self.vulns)
|
|
220
|
+
|
|
221
|
+
@property
|
|
222
|
+
def severity_labels(self) -> set[str]:
|
|
223
|
+
"""The GHSA labels and the bands of the CVSS v3 scores of every member record."""
|
|
224
|
+
return {v.severity for v in self.vulns if v.severity} | {_band(sc) for v in self.vulns for sc in v.cvss}
|
|
225
|
+
|
|
226
|
+
@property
|
|
227
|
+
def summary(self) -> str:
|
|
228
|
+
return next((v.summary for v in self.vulns if v.summary), "")
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
def group_vulns(vulns: Iterable[Vuln]) -> list[VulnGroup]:
|
|
232
|
+
items = list(vulns)
|
|
233
|
+
parent = list(range(len(items)))
|
|
234
|
+
|
|
235
|
+
def find(i: int) -> int:
|
|
236
|
+
while parent[i] != i:
|
|
237
|
+
parent[i] = parent[parent[i]]
|
|
238
|
+
i = parent[i]
|
|
239
|
+
return i
|
|
240
|
+
|
|
241
|
+
owner: dict[str, int] = {}
|
|
242
|
+
for i, v in enumerate(items):
|
|
243
|
+
for key in {v.id, *v.aliases}:
|
|
244
|
+
if key in owner:
|
|
245
|
+
parent[find(i)] = find(owner[key])
|
|
246
|
+
else:
|
|
247
|
+
owner[key] = i
|
|
248
|
+
groups: dict[int, VulnGroup] = {}
|
|
249
|
+
for i, v in enumerate(items):
|
|
250
|
+
groups.setdefault(find(i), VulnGroup([])).vulns.append(v)
|
|
251
|
+
return list(groups.values())
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
# ── per package ──────────────────────────────────────────────────────────────────────────────────────────────────
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
@dataclass(slots=True)
|
|
258
|
+
class GroupInfo:
|
|
259
|
+
ids: list[str]
|
|
260
|
+
cves: list[str]
|
|
261
|
+
severity: str # label, "unknown" or "conflicting"
|
|
262
|
+
kev: bool
|
|
263
|
+
fixed: str | None
|
|
264
|
+
summary: str
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
@dataclass(slots=True)
|
|
268
|
+
class Finding:
|
|
269
|
+
package: LockedPackage
|
|
270
|
+
status: Status
|
|
271
|
+
reason: str
|
|
272
|
+
groups: list[GroupInfo] = field(default_factory=list)
|
|
273
|
+
target: str | None = None
|
|
274
|
+
fix_age_days: float | None = None
|
|
275
|
+
commands: list[str] = field(default_factory=list)
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
@dataclass(slots=True)
|
|
279
|
+
class ScanResult:
|
|
280
|
+
findings: list[Finding] = field(default_factory=list)
|
|
281
|
+
unsupported: list[Unsupported] = field(default_factory=list)
|
|
282
|
+
incomplete: list[str] = field(default_factory=list) # reasons the answer is not complete (exit code 3)
|
|
283
|
+
scanned: int = 0
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
def _commands(finding: Finding) -> list[str]:
|
|
287
|
+
pkg, target = finding.package, finding.target
|
|
288
|
+
if finding.status not in ("exempt-eligible", "bump") or not target:
|
|
289
|
+
return []
|
|
290
|
+
where = f"cd {pkg.lockfile.parent}"
|
|
291
|
+
if pkg.ecosystem == "PyPI":
|
|
292
|
+
if finding.status == "bump":
|
|
293
|
+
return [f"{where} && uv lock --upgrade-package {pkg.name} && uv sync"]
|
|
294
|
+
return [
|
|
295
|
+
f"{where} && uv lock --upgrade-package {pkg.name} --exclude-newer-package {pkg.name}=false && uv lock",
|
|
296
|
+
f"{where} && uv lock --check # and {pkg.name} must be >= {target}, with no [options.exclude-newer-package] entry",
|
|
297
|
+
]
|
|
298
|
+
if finding.status == "bump":
|
|
299
|
+
return [f"{where} && bun update {pkg.name}"]
|
|
300
|
+
return [
|
|
301
|
+
f'{where} && add "{pkg.name}@{target}" to minimumReleaseAgeExcludes in bunfig.toml (bun >= 1.4.4; older: "{pkg.name}"), '
|
|
302
|
+
f"keeping existing entries, then `bun update {pkg.name}` and `git checkout bunfig.toml`",
|
|
303
|
+
]
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
def evaluate_package(
|
|
307
|
+
pkg: LockedPackage,
|
|
308
|
+
groups: list[VulnGroup],
|
|
309
|
+
*,
|
|
310
|
+
kev: set[str] | None,
|
|
311
|
+
release_time: Callable[[Ecosystem, str, str], datetime | None],
|
|
312
|
+
cooldown_days: float,
|
|
313
|
+
now: datetime,
|
|
314
|
+
) -> Finding | None:
|
|
315
|
+
if not groups:
|
|
316
|
+
return None
|
|
317
|
+
infos: list[GroupInfo] = []
|
|
318
|
+
fixes: list[tuple[Any, str]] = []
|
|
319
|
+
urgent_fixes: list[tuple[Any, str]] = []
|
|
320
|
+
urgent_unknown = False
|
|
321
|
+
problem: tuple[Status, str] | None = None
|
|
322
|
+
|
|
323
|
+
for group in groups:
|
|
324
|
+
in_kev = bool(kev and group.cves & kev)
|
|
325
|
+
labels = group.severity_labels
|
|
326
|
+
if not labels:
|
|
327
|
+
severity = "unknown"
|
|
328
|
+
elif len({label in URGENT_LABELS for label in labels}) > 1:
|
|
329
|
+
severity = "conflicting" # one source says high/critical, another doesn't: a human decides
|
|
330
|
+
else:
|
|
331
|
+
severity = max(labels, key=_SEVERITY_RANK.__getitem__)
|
|
332
|
+
urgent = in_kev or (severity in URGENT_LABELS)
|
|
333
|
+
states = [fix_for(v, pkg.ecosystem, pkg.name, pkg.version) for v in group.vulns]
|
|
334
|
+
group_fixed = [s for s in states if s[0] == "fixed"]
|
|
335
|
+
fixed_text: str | None = None
|
|
336
|
+
if group.malicious:
|
|
337
|
+
problem = problem or (
|
|
338
|
+
"malicious",
|
|
339
|
+
f"{', '.join(group.ids)}: a malicious package advisory covers the locked version, see incident.md",
|
|
340
|
+
)
|
|
341
|
+
elif group_fixed:
|
|
342
|
+
fixed_text = max(
|
|
343
|
+
(s[1] for s in group_fixed if s[1]),
|
|
344
|
+
key=lambda t: parse_version(pkg.ecosystem, t),
|
|
345
|
+
)
|
|
346
|
+
fixes.append((parse_version(pkg.ecosystem, fixed_text), fixed_text))
|
|
347
|
+
if urgent:
|
|
348
|
+
urgent_fixes.append(fixes[-1])
|
|
349
|
+
elif any(s[0] == "no-fix" for s in states):
|
|
350
|
+
if urgent or severity in ("unknown", "conflicting"):
|
|
351
|
+
problem = problem or (
|
|
352
|
+
"no-fix",
|
|
353
|
+
f"{', '.join(group.ids)}: no fixed version published",
|
|
354
|
+
)
|
|
355
|
+
else:
|
|
356
|
+
problem = problem or (
|
|
357
|
+
"needs-triage",
|
|
358
|
+
f"{', '.join(group.ids)}: {states[0][2]}",
|
|
359
|
+
)
|
|
360
|
+
if severity in ("unknown", "conflicting") and not in_kev:
|
|
361
|
+
urgent_unknown = True
|
|
362
|
+
infos.append(
|
|
363
|
+
GroupInfo(
|
|
364
|
+
group.ids,
|
|
365
|
+
sorted(group.cves),
|
|
366
|
+
severity,
|
|
367
|
+
in_kev,
|
|
368
|
+
fixed_text,
|
|
369
|
+
group.summary,
|
|
370
|
+
)
|
|
371
|
+
)
|
|
372
|
+
|
|
373
|
+
finding = Finding(pkg, "informational", "", infos)
|
|
374
|
+
if problem:
|
|
375
|
+
finding.status, finding.reason = problem
|
|
376
|
+
return finding
|
|
377
|
+
if not fixes:
|
|
378
|
+
finding.status, finding.reason = (
|
|
379
|
+
"no-fix",
|
|
380
|
+
"no affected advisory has a fixed version",
|
|
381
|
+
)
|
|
382
|
+
return finding
|
|
383
|
+
|
|
384
|
+
chosen = urgent_fixes or fixes
|
|
385
|
+
target = max(chosen, key=lambda f: f[0])[1]
|
|
386
|
+
finding.target = target
|
|
387
|
+
target_version = parse_version(pkg.ecosystem, target)
|
|
388
|
+
still_open = [g for g in infos if g.fixed and parse_version(pkg.ecosystem, g.fixed) > target_version]
|
|
389
|
+
open_note = (
|
|
390
|
+
f"; lower-severity advisories stay open at {target} until a normal bump: "
|
|
391
|
+
+ ", ".join(f"{g.ids[0]} (fixed in {g.fixed})" for g in still_open)
|
|
392
|
+
if urgent_fixes and still_open
|
|
393
|
+
else ""
|
|
394
|
+
)
|
|
395
|
+
|
|
396
|
+
if pkg.declared:
|
|
397
|
+
try:
|
|
398
|
+
if not declared_range_satisfied(pkg.ecosystem, pkg.declared, target):
|
|
399
|
+
finding.status = "blocked"
|
|
400
|
+
finding.reason = f"the declared range {pkg.declared!r} excludes {target}: widen that specifier"
|
|
401
|
+
return finding
|
|
402
|
+
except VersionError as exc:
|
|
403
|
+
finding.status, finding.reason = (
|
|
404
|
+
"needs-triage",
|
|
405
|
+
f"cannot compare the declared range with {target}: {exc}",
|
|
406
|
+
)
|
|
407
|
+
return finding
|
|
408
|
+
|
|
409
|
+
released = release_time(pkg.ecosystem, pkg.name, target)
|
|
410
|
+
if released is not None:
|
|
411
|
+
finding.fix_age_days = round((now - released).total_seconds() / 86400, 1)
|
|
412
|
+
old_enough = finding.fix_age_days is not None and finding.fix_age_days >= cooldown_days
|
|
413
|
+
if old_enough:
|
|
414
|
+
finding.status, finding.reason = (
|
|
415
|
+
"bump",
|
|
416
|
+
f"{target} is {finding.fix_age_days} days old, past the {cooldown_days:g}-day cooldown{open_note}",
|
|
417
|
+
)
|
|
418
|
+
elif urgent_fixes:
|
|
419
|
+
age = "age unknown" if finding.fix_age_days is None else f"{finding.fix_age_days} days old"
|
|
420
|
+
finding.status, finding.reason = (
|
|
421
|
+
"exempt-eligible",
|
|
422
|
+
f"high/critical or exploited; {target} is {age}, inside the cooldown{open_note}",
|
|
423
|
+
)
|
|
424
|
+
elif urgent_unknown:
|
|
425
|
+
finding.status, finding.reason = (
|
|
426
|
+
"needs-triage",
|
|
427
|
+
"severity is missing or conflicting and the fix is inside the cooldown",
|
|
428
|
+
)
|
|
429
|
+
else:
|
|
430
|
+
finding.status, finding.reason = (
|
|
431
|
+
"informational",
|
|
432
|
+
f"lower severity; {target} is inside the cooldown, wait",
|
|
433
|
+
)
|
|
434
|
+
finding.commands = _commands(finding)
|
|
435
|
+
return finding
|
|
436
|
+
|
|
437
|
+
|
|
438
|
+
def scan(
|
|
439
|
+
contents: Iterable[LockfileContent],
|
|
440
|
+
source: AdvisorySource,
|
|
441
|
+
*,
|
|
442
|
+
cooldown_days: float = DEFAULT_COOLDOWN_DAYS,
|
|
443
|
+
now: datetime,
|
|
444
|
+
) -> ScanResult:
|
|
445
|
+
"""Look every locked (ecosystem, name, version) up in OSV. A failing batch query raises `DataError`; a failing record
|
|
446
|
+
or KEV fetch is recorded in `incomplete` and the rest is still reported."""
|
|
447
|
+
result = ScanResult()
|
|
448
|
+
packages: list[LockedPackage] = []
|
|
449
|
+
for content in contents:
|
|
450
|
+
packages.extend(content.packages)
|
|
451
|
+
result.unsupported.extend(content.unsupported)
|
|
452
|
+
result.scanned = len(packages)
|
|
453
|
+
queries: list[PackageQuery] = [(p.ecosystem, p.name, p.version) for p in packages]
|
|
454
|
+
ids_by_query = source.query_batch(queries)
|
|
455
|
+
|
|
456
|
+
vulns: dict[str, Vuln] = {}
|
|
457
|
+
for vuln_id in sorted({i for ids in ids_by_query.values() for i in ids}):
|
|
458
|
+
try:
|
|
459
|
+
vulns[vuln_id] = parse_vuln(source.vuln(vuln_id))
|
|
460
|
+
except (DataError, KeyError, TypeError) as exc:
|
|
461
|
+
result.incomplete.append(f"advisory {vuln_id} could not be read: {exc}")
|
|
462
|
+
kev: set[str] | None = None
|
|
463
|
+
if ids_by_query and any(ids_by_query.values()):
|
|
464
|
+
try:
|
|
465
|
+
kev = source.kev_cves()
|
|
466
|
+
except DataError as exc:
|
|
467
|
+
result.incomplete.append(f"CISA KEV unavailable, exploited-in-the-wild status unknown: {exc}")
|
|
468
|
+
|
|
469
|
+
for pkg in packages:
|
|
470
|
+
ids = ids_by_query.get((pkg.ecosystem, pkg.name, pkg.version), [])
|
|
471
|
+
missing = [i for i in ids if i not in vulns]
|
|
472
|
+
if missing:
|
|
473
|
+
result.incomplete.append(f"{pkg.name} {pkg.version}: unreadable advisory {', '.join(missing)}")
|
|
474
|
+
groups = group_vulns(vulns[i] for i in ids if i in vulns)
|
|
475
|
+
try:
|
|
476
|
+
finding = evaluate_package(
|
|
477
|
+
pkg,
|
|
478
|
+
groups,
|
|
479
|
+
kev=kev,
|
|
480
|
+
release_time=_safe_release_time(source, result),
|
|
481
|
+
cooldown_days=cooldown_days,
|
|
482
|
+
now=now,
|
|
483
|
+
)
|
|
484
|
+
except VersionError as exc:
|
|
485
|
+
finding = Finding(pkg, "needs-triage", f"cannot evaluate: {exc}")
|
|
486
|
+
if finding:
|
|
487
|
+
result.findings.append(finding)
|
|
488
|
+
result.findings.sort(key=lambda f: (str(f.package.lockfile), f.package.name, f.package.version))
|
|
489
|
+
return result
|
|
490
|
+
|
|
491
|
+
|
|
492
|
+
def _safe_release_time(source: AdvisorySource, result: ScanResult) -> Callable[[Ecosystem, str, str], datetime | None]:
|
|
493
|
+
def lookup(ecosystem: Ecosystem, name: str, version: str) -> datetime | None:
|
|
494
|
+
try:
|
|
495
|
+
return source.release_time(ecosystem, name, version)
|
|
496
|
+
except DataError as exc: # age unknown is reported as such; it never hides an advisory
|
|
497
|
+
result.incomplete.append(f"release time of {name} {version} unavailable: {exc}")
|
|
498
|
+
return None
|
|
499
|
+
|
|
500
|
+
return lookup
|