@biffo/cli 0.324.3 → 0.324.5
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.
- package/_skeletons/plugin-template/scripts/py-dependency-audit-classification.test.sh +196 -0
- package/_skeletons/plugin-template/scripts/py-dependency-audit.sh +53 -3
- package/_skeletons/sibling-template/scripts/py-dependency-audit-classification.test.sh +196 -0
- package/_skeletons/sibling-template/scripts/py-dependency-audit.sh +53 -3
- package/dist/index.js +26 -23
- package/package.json +1 -1
|
@@ -274,6 +274,202 @@ _stage_clean
|
|
|
274
274
|
_run dev
|
|
275
275
|
_assert_exit "clean run unaffected" 0
|
|
276
276
|
|
|
277
|
+
# ============================================================================
|
|
278
|
+
# uv WORKSPACE MEMBERS (#2120). The export and the classification must read
|
|
279
|
+
# the SAME lockfile. `uv export` run inside a workspace member resolves the
|
|
280
|
+
# WORKSPACE ROOT's uv.lock, not <member>/uv.lock; the classifier then compared
|
|
281
|
+
# that root-lock version against the member's own lock on the base branch, so a
|
|
282
|
+
# pre-existing root-lock advisory read as "introduced by this diff" for every
|
|
283
|
+
# member tree, and the member's own lock was never audited at all. Observed in
|
|
284
|
+
# biffo-platform PR 197 (anyio 4.14.1 in the root lock, 4.14.2 in both member
|
|
285
|
+
# locks).
|
|
286
|
+
#
|
|
287
|
+
# These cases use the REAL `uv export` (offline, --frozen, hand-written locks)
|
|
288
|
+
# because the defect lives in uv's workspace discovery -- a stubbed export
|
|
289
|
+
# would test nothing. Only `uv run pip-audit` is stubbed: for `-r <file>` it
|
|
290
|
+
# reports an advisory on anyio==4.14.1 (fixed in 4.14.2) found in THAT file,
|
|
291
|
+
# and it records the file so the test can assert which lock was audited.
|
|
292
|
+
# ============================================================================
|
|
293
|
+
REAL_UV=$(command -v uv 2>/dev/null || true)
|
|
294
|
+
if [ -z "$REAL_UV" ]; then
|
|
295
|
+
echo "FAIL: workspace-member cases need a real uv on PATH (they exercise uv's workspace discovery) -- not skipping, a skipped case reads as a pass"
|
|
296
|
+
FAILURES=$((FAILURES + 1))
|
|
297
|
+
else
|
|
298
|
+
cat > "$STUB_DIR/uv" <<STUB
|
|
299
|
+
#!/usr/bin/env sh
|
|
300
|
+
if [ "\$1" = "run" ] && [ "\$2" = "pip-audit" ]; then
|
|
301
|
+
reqs=""
|
|
302
|
+
while [ \$# -gt 0 ]; do
|
|
303
|
+
if [ "\$1" = "-r" ]; then reqs="\$2"; fi
|
|
304
|
+
shift
|
|
305
|
+
done
|
|
306
|
+
if [ -z "\$reqs" ]; then
|
|
307
|
+
cat "\$PIPAUDIT_STUB_OUTPUT"
|
|
308
|
+
exit 0
|
|
309
|
+
fi
|
|
310
|
+
cat "\$reqs" >> "\$AUDITED_LOG"
|
|
311
|
+
printf '{"dependencies": ['
|
|
312
|
+
sep=""
|
|
313
|
+
grep -E '^[A-Za-z0-9_.-]+==' "\$reqs" | sed 's/ .*//' | while IFS='=' read -r n _ v; do
|
|
314
|
+
vulns='[]'
|
|
315
|
+
if [ "\$n" = anyio ] && [ "\$v" = 4.14.1 ]; then vulns='[{"id":"GHSA-test-anyio"}]'; fi
|
|
316
|
+
printf '%s{"name":"%s","version":"%s","vulns":%s}' "\$sep" "\$n" "\$v" "\$vulns"
|
|
317
|
+
sep=","
|
|
318
|
+
done
|
|
319
|
+
printf ']}\n'
|
|
320
|
+
exit 0
|
|
321
|
+
fi
|
|
322
|
+
exec "$REAL_UV" "\$@"
|
|
323
|
+
STUB
|
|
324
|
+
chmod +x "$STUB_DIR/uv"
|
|
325
|
+
AUDITED_LOG="$STUB_DIR/audited.log"
|
|
326
|
+
export AUDITED_LOG
|
|
327
|
+
|
|
328
|
+
_ws_lock() {
|
|
329
|
+
# $1 = dest, $2 = anyio version. Member locks (uv resolves a lone member
|
|
330
|
+
# as its own project) hold only that member; the workspace ROOT lock holds
|
|
331
|
+
# the root and every member, exactly as `uv lock` writes them.
|
|
332
|
+
# $3 = "root" for the workspace root lock, "member" for a member's own.
|
|
333
|
+
cat > "$1" <<LOCK
|
|
334
|
+
version = 1
|
|
335
|
+
revision = 3
|
|
336
|
+
requires-python = ">=3.12"
|
|
337
|
+
LOCK
|
|
338
|
+
if [ "$3" = root ]; then
|
|
339
|
+
cat >> "$1" <<'LOCK'
|
|
340
|
+
|
|
341
|
+
[manifest]
|
|
342
|
+
members = ["m", "root"]
|
|
343
|
+
LOCK
|
|
344
|
+
fi
|
|
345
|
+
cat >> "$1" <<LOCK
|
|
346
|
+
|
|
347
|
+
[[package]]
|
|
348
|
+
name = "anyio"
|
|
349
|
+
version = "$2"
|
|
350
|
+
source = { registry = "https://pypi.org/simple" }
|
|
351
|
+
|
|
352
|
+
[[package]]
|
|
353
|
+
name = "m"
|
|
354
|
+
version = "0.1.0"
|
|
355
|
+
source = { virtual = "$([ "$3" = root ] && echo services/m || echo .)" }
|
|
356
|
+
dependencies = [{ name = "anyio" }]
|
|
357
|
+
LOCK
|
|
358
|
+
if [ "$3" = root ]; then
|
|
359
|
+
cat >> "$1" <<'LOCK'
|
|
360
|
+
|
|
361
|
+
[[package]]
|
|
362
|
+
name = "root"
|
|
363
|
+
version = "0.1.0"
|
|
364
|
+
source = { virtual = "." }
|
|
365
|
+
dependencies = [{ name = "anyio" }]
|
|
366
|
+
LOCK
|
|
367
|
+
fi
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
_ws_repo() {
|
|
371
|
+
# $1 = root-lock anyio, $2 = member-lock anyio ON BASE,
|
|
372
|
+
# $3 = member-lock anyio on the PR head (== $2 when the PR leaves it alone)
|
|
373
|
+
rm -rf "$REPO_DIR"
|
|
374
|
+
mkdir -p "$REPO_DIR/services/m"
|
|
375
|
+
( cd "$REPO_DIR" \
|
|
376
|
+
&& git init -q -b trunk \
|
|
377
|
+
&& git config user.email test@example.com \
|
|
378
|
+
&& git config user.name "Test" )
|
|
379
|
+
cat > "$REPO_DIR/pyproject.toml" <<'PYP'
|
|
380
|
+
[project]
|
|
381
|
+
name = "root"
|
|
382
|
+
version = "0.1.0"
|
|
383
|
+
requires-python = ">=3.12"
|
|
384
|
+
dependencies = ["anyio"]
|
|
385
|
+
[tool.uv.workspace]
|
|
386
|
+
members = ["services/*"]
|
|
387
|
+
PYP
|
|
388
|
+
cat > "$REPO_DIR/services/m/pyproject.toml" <<'PYP'
|
|
389
|
+
[project]
|
|
390
|
+
name = "m"
|
|
391
|
+
version = "0.1.0"
|
|
392
|
+
requires-python = ">=3.12"
|
|
393
|
+
dependencies = ["anyio"]
|
|
394
|
+
PYP
|
|
395
|
+
_ws_lock "$REPO_DIR/uv.lock" "$1" root
|
|
396
|
+
_ws_lock "$REPO_DIR/services/m/uv.lock" "$2" member
|
|
397
|
+
( cd "$REPO_DIR" && git add -A && git commit -q -m base && git branch -q origin/dev )
|
|
398
|
+
if [ "$3" != "$2" ]; then
|
|
399
|
+
_ws_lock "$REPO_DIR/services/m/uv.lock" "$3" member
|
|
400
|
+
( cd "$REPO_DIR" && git add -A && git commit -q -m "pr bumps member lock" )
|
|
401
|
+
fi
|
|
402
|
+
: > "$AUDITED_LOG"
|
|
403
|
+
_stage_clean
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
_assert_audited() {
|
|
407
|
+
# $1 = name, $2 = requirement line the MEMBER audit must have received
|
|
408
|
+
if grep -qxF "$2" "$AUDITED_LOG"; then
|
|
409
|
+
echo "PASS: $1 audited '$2'"
|
|
410
|
+
else
|
|
411
|
+
echo "FAIL: $1 -- expected the member tree's OWN lock to be audited ('$2'); pip-audit was given:"
|
|
412
|
+
cat "$AUDITED_LOG"
|
|
413
|
+
FAILURES=$((FAILURES + 1))
|
|
414
|
+
fi
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
_assert_not_audited() {
|
|
418
|
+
if grep -qxF "$2" "$AUDITED_LOG"; then
|
|
419
|
+
echo "FAIL: $1 -- pip-audit was given '$2', i.e. the ROOT lock's version, not the member's own"
|
|
420
|
+
FAILURES=$((FAILURES + 1))
|
|
421
|
+
else
|
|
422
|
+
echo "PASS: $1 did not audit '$2'"
|
|
423
|
+
fi
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
# 8. The reported shape. Root lock has the vulnerable anyio 4.14.1; the
|
|
427
|
+
# member's own lock is already fixed (4.14.2); the PR touches neither.
|
|
428
|
+
# The member's audit must read ITS lock (4.14.2, clean) -- before #2120 it
|
|
429
|
+
# read the root lock (4.14.1), classified that against the member's base
|
|
430
|
+
# lock (4.14.2) and blocked on a finding the diff did not introduce.
|
|
431
|
+
_ws_repo "4.14.1" "4.14.2" "4.14.2"
|
|
432
|
+
_run dev
|
|
433
|
+
_assert_exit "workspace member: root-lock advisory not blamed on the diff" 0
|
|
434
|
+
_assert_audited "workspace member (own lock fixed)" "anyio==4.14.2"
|
|
435
|
+
_assert_not_audited "workspace member (own lock fixed)" "anyio==4.14.1"
|
|
436
|
+
|
|
437
|
+
# 9. Inverse: the MEMBER's own lock carries the advisory (unchanged from
|
|
438
|
+
# base), the root is fine. Before #2120 the member lock was never audited,
|
|
439
|
+
# so this read as a clean pass. It must be audited, and reported as
|
|
440
|
+
# pre-existing rather than silently skipped or blamed on the diff.
|
|
441
|
+
_ws_repo "4.14.2" "4.14.1" "4.14.1"
|
|
442
|
+
_run dev
|
|
443
|
+
_assert_exit "workspace member: own-lock pre-existing advisory does not block" 0
|
|
444
|
+
_assert_audited "workspace member (own lock vulnerable)" "anyio==4.14.1"
|
|
445
|
+
_assert_output_contains "workspace member: own-lock advisory named pre-existing" "pre-existing"
|
|
446
|
+
|
|
447
|
+
# 10. The PR itself bumps the member's own lock INTO the advisory: a real
|
|
448
|
+
# regression in the file that was previously never looked at. Must block.
|
|
449
|
+
_ws_repo "4.14.2" "4.14.2" "4.14.1"
|
|
450
|
+
_run dev
|
|
451
|
+
_assert_exit "workspace member: PR bumping own lock into an advisory blocks" 1
|
|
452
|
+
_assert_output_contains "workspace member: regression named as introduced" "introduced"
|
|
453
|
+
|
|
454
|
+
# 11. A scratch directory INSIDE the repository would put the workspace root
|
|
455
|
+
# back above the staged copy and silently restore the wrong-lock export.
|
|
456
|
+
# TMPDIR pointed under the repo must fail closed (INCONCLUSIVE, exit 2),
|
|
457
|
+
# never fall back to exporting in place.
|
|
458
|
+
_ws_repo "4.14.1" "4.14.2" "4.14.2"
|
|
459
|
+
mkdir -p "$REPO_DIR/scratch"
|
|
460
|
+
(
|
|
461
|
+
cd "$REPO_DIR" || exit 97
|
|
462
|
+
PATH="$STUB_DIR:$PATH"; export PATH
|
|
463
|
+
PIPAUDIT_STUB_OUTPUT="$STUB_DIR/pip-audit-output.json"; export PIPAUDIT_STUB_OUTPUT
|
|
464
|
+
TMPDIR="$REPO_DIR/scratch"; export TMPDIR
|
|
465
|
+
GITHUB_BASE_REF=dev; export GITHUB_BASE_REF
|
|
466
|
+
sh "$TARGET"
|
|
467
|
+
) >"$OUT_FILE" 2>&1
|
|
468
|
+
LAST_RC=$?
|
|
469
|
+
_assert_exit "scratch dir inside the repo fails closed" 2
|
|
470
|
+
_assert_output_contains "scratch-inside-repo names the tree as unaudited" "INCONCLUSIVE"
|
|
471
|
+
fi
|
|
472
|
+
|
|
277
473
|
echo
|
|
278
474
|
if [ "$FAILURES" -eq 0 ]; then
|
|
279
475
|
echo "py-dependency-audit-classification.test.sh: all checks passed."
|
|
@@ -171,7 +171,14 @@ _classify_finding() {
|
|
|
171
171
|
return
|
|
172
172
|
fi
|
|
173
173
|
|
|
174
|
-
|
|
174
|
+
# Read from a regular file, not a pipe: `_lockfile_version_for`'s awk `exit`s
|
|
175
|
+
# on its first match and closes its stdin, so a pipe with `printf` still
|
|
176
|
+
# writing into it gets SIGPIPE and dash reports a stray "printf: I/O error"
|
|
177
|
+
# into the log (#2120 -- the same mechanism #1995 removed from the dump path).
|
|
178
|
+
base_lock_file="$(mktemp)"
|
|
179
|
+
printf '%s\n' "$base_lock_content" > "$base_lock_file"
|
|
180
|
+
base_version="$(_lockfile_version_for "$finding_name" < "$base_lock_file")"
|
|
181
|
+
rm -f "$base_lock_file"
|
|
175
182
|
if [ -n "$base_version" ] && [ "$base_version" = "$finding_version" ]; then
|
|
176
183
|
printf 'pre-existing'
|
|
177
184
|
else
|
|
@@ -340,6 +347,49 @@ for lock in $ALL_LOCKS; do
|
|
|
340
347
|
fi
|
|
341
348
|
done
|
|
342
349
|
|
|
350
|
+
# ## Export the lockfile that is classified (#2120)
|
|
351
|
+
#
|
|
352
|
+
# `_classify_finding` compares a flagged version against `<tree>/uv.lock` on
|
|
353
|
+
# the base branch, so the export MUST read `<tree>/uv.lock` too. It did not for
|
|
354
|
+
# a tree that is a uv WORKSPACE MEMBER: `uv export` run inside a member walks
|
|
355
|
+
# up to the workspace root and exports the ROOT's `uv.lock`. The audit then
|
|
356
|
+
# scanned one lockfile and classified against another -- a pre-existing root
|
|
357
|
+
# advisory read as "introduced by this diff" for every member tree, and the
|
|
358
|
+
# member's own lock was never audited at all (biffo-platform PR 197).
|
|
359
|
+
#
|
|
360
|
+
# The cause is removed rather than detected: the tree's `pyproject.toml` and
|
|
361
|
+
# `uv.lock` are staged ALONE in a scratch directory outside the repository, so
|
|
362
|
+
# there is no workspace above them for uv to find. The bytes exported are then
|
|
363
|
+
# the bytes at the path the classifier reads, by construction -- no membership
|
|
364
|
+
# detection, no second lookup that could disagree. `--frozen` reads the lock
|
|
365
|
+
# without re-resolving, so `[tool.uv.sources]` entries (path, workspace) need
|
|
366
|
+
# not resolve from the scratch directory; verified against uv 0.11.
|
|
367
|
+
#
|
|
368
|
+
# `$1` is the tree directory, the remaining arguments are `uv export` flags.
|
|
369
|
+
# Returns non-zero -- never a partial success -- if the tree has no
|
|
370
|
+
# pyproject.toml/uv.lock to stage or the scratch directory cannot be made or
|
|
371
|
+
# sits inside the repository (a TMPDIR under the repo would put the workspace
|
|
372
|
+
# back above the copy and silently restore the defect).
|
|
373
|
+
_export_own_lock() {
|
|
374
|
+
eo_dir="$1"
|
|
375
|
+
shift
|
|
376
|
+
eo_scratch="$(mktemp -d)" || return 1
|
|
377
|
+
case "$(cd "$eo_scratch" && pwd -P)/" in
|
|
378
|
+
"${REPO_ROOT}"/*)
|
|
379
|
+
rm -rf "$eo_scratch"
|
|
380
|
+
return 1
|
|
381
|
+
;;
|
|
382
|
+
esac
|
|
383
|
+
if ! cp "$eo_dir/pyproject.toml" "$eo_dir/uv.lock" "$eo_scratch/" 2>/dev/null; then
|
|
384
|
+
rm -rf "$eo_scratch"
|
|
385
|
+
return 1
|
|
386
|
+
fi
|
|
387
|
+
(cd "$eo_scratch" && uv export --frozen "$@")
|
|
388
|
+
eo_rc=$?
|
|
389
|
+
rm -rf "$eo_scratch"
|
|
390
|
+
return "$eo_rc"
|
|
391
|
+
}
|
|
392
|
+
|
|
343
393
|
# Audit each discovered tree. The workspace's own lockfile is audited via the
|
|
344
394
|
# INSTALLED environment `uv sync` already produced (unchanged from before —
|
|
345
395
|
# `uv run pip-audit` with no `-r`). Every other discovered lockfile is not an
|
|
@@ -383,13 +433,13 @@ for lock in $ALL_LOCKS; do
|
|
|
383
433
|
# audited -- verified on `services/ideation`, where the export keeps 25
|
|
384
434
|
# packages including three carried `via biffo-plugin-sdk`. So the answer this
|
|
385
435
|
# gate gives is unchanged for every package an advisory can actually be about.
|
|
386
|
-
if
|
|
436
|
+
if _export_own_lock "$dir" --no-dev --no-emit-project --no-emit-local >"$reqs" 2>/dev/null && [ -s "$reqs" ]; then
|
|
387
437
|
# Report what was skipped rather than skipping it quietly: "audited
|
|
388
438
|
# everything except the bits we could not" must never read the same as
|
|
389
439
|
# "audited everything", which is the failure this whole file exists to
|
|
390
440
|
# fight. Counted from the same lockfile, so the number is the tree's, not
|
|
391
441
|
# a guess.
|
|
392
|
-
local_deps=$(
|
|
442
|
+
local_deps=$(_export_own_lock "$dir" --no-dev --no-emit-project 2>/dev/null \
|
|
393
443
|
| grep -cE '^-e |@ file://' || true )
|
|
394
444
|
if [ "${local_deps:-0}" -gt 0 ]; then
|
|
395
445
|
echo " (${rel}: ${local_deps} local path dependenc$([ "$local_deps" -eq 1 ] && echo y || echo ies) excluded -- first-party, audited in their own repo; their transitive dependencies are still scanned)"
|
|
@@ -274,6 +274,202 @@ _stage_clean
|
|
|
274
274
|
_run dev
|
|
275
275
|
_assert_exit "clean run unaffected" 0
|
|
276
276
|
|
|
277
|
+
# ============================================================================
|
|
278
|
+
# uv WORKSPACE MEMBERS (#2120). The export and the classification must read
|
|
279
|
+
# the SAME lockfile. `uv export` run inside a workspace member resolves the
|
|
280
|
+
# WORKSPACE ROOT's uv.lock, not <member>/uv.lock; the classifier then compared
|
|
281
|
+
# that root-lock version against the member's own lock on the base branch, so a
|
|
282
|
+
# pre-existing root-lock advisory read as "introduced by this diff" for every
|
|
283
|
+
# member tree, and the member's own lock was never audited at all. Observed in
|
|
284
|
+
# biffo-platform PR 197 (anyio 4.14.1 in the root lock, 4.14.2 in both member
|
|
285
|
+
# locks).
|
|
286
|
+
#
|
|
287
|
+
# These cases use the REAL `uv export` (offline, --frozen, hand-written locks)
|
|
288
|
+
# because the defect lives in uv's workspace discovery -- a stubbed export
|
|
289
|
+
# would test nothing. Only `uv run pip-audit` is stubbed: for `-r <file>` it
|
|
290
|
+
# reports an advisory on anyio==4.14.1 (fixed in 4.14.2) found in THAT file,
|
|
291
|
+
# and it records the file so the test can assert which lock was audited.
|
|
292
|
+
# ============================================================================
|
|
293
|
+
REAL_UV=$(command -v uv 2>/dev/null || true)
|
|
294
|
+
if [ -z "$REAL_UV" ]; then
|
|
295
|
+
echo "FAIL: workspace-member cases need a real uv on PATH (they exercise uv's workspace discovery) -- not skipping, a skipped case reads as a pass"
|
|
296
|
+
FAILURES=$((FAILURES + 1))
|
|
297
|
+
else
|
|
298
|
+
cat > "$STUB_DIR/uv" <<STUB
|
|
299
|
+
#!/usr/bin/env sh
|
|
300
|
+
if [ "\$1" = "run" ] && [ "\$2" = "pip-audit" ]; then
|
|
301
|
+
reqs=""
|
|
302
|
+
while [ \$# -gt 0 ]; do
|
|
303
|
+
if [ "\$1" = "-r" ]; then reqs="\$2"; fi
|
|
304
|
+
shift
|
|
305
|
+
done
|
|
306
|
+
if [ -z "\$reqs" ]; then
|
|
307
|
+
cat "\$PIPAUDIT_STUB_OUTPUT"
|
|
308
|
+
exit 0
|
|
309
|
+
fi
|
|
310
|
+
cat "\$reqs" >> "\$AUDITED_LOG"
|
|
311
|
+
printf '{"dependencies": ['
|
|
312
|
+
sep=""
|
|
313
|
+
grep -E '^[A-Za-z0-9_.-]+==' "\$reqs" | sed 's/ .*//' | while IFS='=' read -r n _ v; do
|
|
314
|
+
vulns='[]'
|
|
315
|
+
if [ "\$n" = anyio ] && [ "\$v" = 4.14.1 ]; then vulns='[{"id":"GHSA-test-anyio"}]'; fi
|
|
316
|
+
printf '%s{"name":"%s","version":"%s","vulns":%s}' "\$sep" "\$n" "\$v" "\$vulns"
|
|
317
|
+
sep=","
|
|
318
|
+
done
|
|
319
|
+
printf ']}\n'
|
|
320
|
+
exit 0
|
|
321
|
+
fi
|
|
322
|
+
exec "$REAL_UV" "\$@"
|
|
323
|
+
STUB
|
|
324
|
+
chmod +x "$STUB_DIR/uv"
|
|
325
|
+
AUDITED_LOG="$STUB_DIR/audited.log"
|
|
326
|
+
export AUDITED_LOG
|
|
327
|
+
|
|
328
|
+
_ws_lock() {
|
|
329
|
+
# $1 = dest, $2 = anyio version. Member locks (uv resolves a lone member
|
|
330
|
+
# as its own project) hold only that member; the workspace ROOT lock holds
|
|
331
|
+
# the root and every member, exactly as `uv lock` writes them.
|
|
332
|
+
# $3 = "root" for the workspace root lock, "member" for a member's own.
|
|
333
|
+
cat > "$1" <<LOCK
|
|
334
|
+
version = 1
|
|
335
|
+
revision = 3
|
|
336
|
+
requires-python = ">=3.12"
|
|
337
|
+
LOCK
|
|
338
|
+
if [ "$3" = root ]; then
|
|
339
|
+
cat >> "$1" <<'LOCK'
|
|
340
|
+
|
|
341
|
+
[manifest]
|
|
342
|
+
members = ["m", "root"]
|
|
343
|
+
LOCK
|
|
344
|
+
fi
|
|
345
|
+
cat >> "$1" <<LOCK
|
|
346
|
+
|
|
347
|
+
[[package]]
|
|
348
|
+
name = "anyio"
|
|
349
|
+
version = "$2"
|
|
350
|
+
source = { registry = "https://pypi.org/simple" }
|
|
351
|
+
|
|
352
|
+
[[package]]
|
|
353
|
+
name = "m"
|
|
354
|
+
version = "0.1.0"
|
|
355
|
+
source = { virtual = "$([ "$3" = root ] && echo services/m || echo .)" }
|
|
356
|
+
dependencies = [{ name = "anyio" }]
|
|
357
|
+
LOCK
|
|
358
|
+
if [ "$3" = root ]; then
|
|
359
|
+
cat >> "$1" <<'LOCK'
|
|
360
|
+
|
|
361
|
+
[[package]]
|
|
362
|
+
name = "root"
|
|
363
|
+
version = "0.1.0"
|
|
364
|
+
source = { virtual = "." }
|
|
365
|
+
dependencies = [{ name = "anyio" }]
|
|
366
|
+
LOCK
|
|
367
|
+
fi
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
_ws_repo() {
|
|
371
|
+
# $1 = root-lock anyio, $2 = member-lock anyio ON BASE,
|
|
372
|
+
# $3 = member-lock anyio on the PR head (== $2 when the PR leaves it alone)
|
|
373
|
+
rm -rf "$REPO_DIR"
|
|
374
|
+
mkdir -p "$REPO_DIR/services/m"
|
|
375
|
+
( cd "$REPO_DIR" \
|
|
376
|
+
&& git init -q -b trunk \
|
|
377
|
+
&& git config user.email test@example.com \
|
|
378
|
+
&& git config user.name "Test" )
|
|
379
|
+
cat > "$REPO_DIR/pyproject.toml" <<'PYP'
|
|
380
|
+
[project]
|
|
381
|
+
name = "root"
|
|
382
|
+
version = "0.1.0"
|
|
383
|
+
requires-python = ">=3.12"
|
|
384
|
+
dependencies = ["anyio"]
|
|
385
|
+
[tool.uv.workspace]
|
|
386
|
+
members = ["services/*"]
|
|
387
|
+
PYP
|
|
388
|
+
cat > "$REPO_DIR/services/m/pyproject.toml" <<'PYP'
|
|
389
|
+
[project]
|
|
390
|
+
name = "m"
|
|
391
|
+
version = "0.1.0"
|
|
392
|
+
requires-python = ">=3.12"
|
|
393
|
+
dependencies = ["anyio"]
|
|
394
|
+
PYP
|
|
395
|
+
_ws_lock "$REPO_DIR/uv.lock" "$1" root
|
|
396
|
+
_ws_lock "$REPO_DIR/services/m/uv.lock" "$2" member
|
|
397
|
+
( cd "$REPO_DIR" && git add -A && git commit -q -m base && git branch -q origin/dev )
|
|
398
|
+
if [ "$3" != "$2" ]; then
|
|
399
|
+
_ws_lock "$REPO_DIR/services/m/uv.lock" "$3" member
|
|
400
|
+
( cd "$REPO_DIR" && git add -A && git commit -q -m "pr bumps member lock" )
|
|
401
|
+
fi
|
|
402
|
+
: > "$AUDITED_LOG"
|
|
403
|
+
_stage_clean
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
_assert_audited() {
|
|
407
|
+
# $1 = name, $2 = requirement line the MEMBER audit must have received
|
|
408
|
+
if grep -qxF "$2" "$AUDITED_LOG"; then
|
|
409
|
+
echo "PASS: $1 audited '$2'"
|
|
410
|
+
else
|
|
411
|
+
echo "FAIL: $1 -- expected the member tree's OWN lock to be audited ('$2'); pip-audit was given:"
|
|
412
|
+
cat "$AUDITED_LOG"
|
|
413
|
+
FAILURES=$((FAILURES + 1))
|
|
414
|
+
fi
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
_assert_not_audited() {
|
|
418
|
+
if grep -qxF "$2" "$AUDITED_LOG"; then
|
|
419
|
+
echo "FAIL: $1 -- pip-audit was given '$2', i.e. the ROOT lock's version, not the member's own"
|
|
420
|
+
FAILURES=$((FAILURES + 1))
|
|
421
|
+
else
|
|
422
|
+
echo "PASS: $1 did not audit '$2'"
|
|
423
|
+
fi
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
# 8. The reported shape. Root lock has the vulnerable anyio 4.14.1; the
|
|
427
|
+
# member's own lock is already fixed (4.14.2); the PR touches neither.
|
|
428
|
+
# The member's audit must read ITS lock (4.14.2, clean) -- before #2120 it
|
|
429
|
+
# read the root lock (4.14.1), classified that against the member's base
|
|
430
|
+
# lock (4.14.2) and blocked on a finding the diff did not introduce.
|
|
431
|
+
_ws_repo "4.14.1" "4.14.2" "4.14.2"
|
|
432
|
+
_run dev
|
|
433
|
+
_assert_exit "workspace member: root-lock advisory not blamed on the diff" 0
|
|
434
|
+
_assert_audited "workspace member (own lock fixed)" "anyio==4.14.2"
|
|
435
|
+
_assert_not_audited "workspace member (own lock fixed)" "anyio==4.14.1"
|
|
436
|
+
|
|
437
|
+
# 9. Inverse: the MEMBER's own lock carries the advisory (unchanged from
|
|
438
|
+
# base), the root is fine. Before #2120 the member lock was never audited,
|
|
439
|
+
# so this read as a clean pass. It must be audited, and reported as
|
|
440
|
+
# pre-existing rather than silently skipped or blamed on the diff.
|
|
441
|
+
_ws_repo "4.14.2" "4.14.1" "4.14.1"
|
|
442
|
+
_run dev
|
|
443
|
+
_assert_exit "workspace member: own-lock pre-existing advisory does not block" 0
|
|
444
|
+
_assert_audited "workspace member (own lock vulnerable)" "anyio==4.14.1"
|
|
445
|
+
_assert_output_contains "workspace member: own-lock advisory named pre-existing" "pre-existing"
|
|
446
|
+
|
|
447
|
+
# 10. The PR itself bumps the member's own lock INTO the advisory: a real
|
|
448
|
+
# regression in the file that was previously never looked at. Must block.
|
|
449
|
+
_ws_repo "4.14.2" "4.14.2" "4.14.1"
|
|
450
|
+
_run dev
|
|
451
|
+
_assert_exit "workspace member: PR bumping own lock into an advisory blocks" 1
|
|
452
|
+
_assert_output_contains "workspace member: regression named as introduced" "introduced"
|
|
453
|
+
|
|
454
|
+
# 11. A scratch directory INSIDE the repository would put the workspace root
|
|
455
|
+
# back above the staged copy and silently restore the wrong-lock export.
|
|
456
|
+
# TMPDIR pointed under the repo must fail closed (INCONCLUSIVE, exit 2),
|
|
457
|
+
# never fall back to exporting in place.
|
|
458
|
+
_ws_repo "4.14.1" "4.14.2" "4.14.2"
|
|
459
|
+
mkdir -p "$REPO_DIR/scratch"
|
|
460
|
+
(
|
|
461
|
+
cd "$REPO_DIR" || exit 97
|
|
462
|
+
PATH="$STUB_DIR:$PATH"; export PATH
|
|
463
|
+
PIPAUDIT_STUB_OUTPUT="$STUB_DIR/pip-audit-output.json"; export PIPAUDIT_STUB_OUTPUT
|
|
464
|
+
TMPDIR="$REPO_DIR/scratch"; export TMPDIR
|
|
465
|
+
GITHUB_BASE_REF=dev; export GITHUB_BASE_REF
|
|
466
|
+
sh "$TARGET"
|
|
467
|
+
) >"$OUT_FILE" 2>&1
|
|
468
|
+
LAST_RC=$?
|
|
469
|
+
_assert_exit "scratch dir inside the repo fails closed" 2
|
|
470
|
+
_assert_output_contains "scratch-inside-repo names the tree as unaudited" "INCONCLUSIVE"
|
|
471
|
+
fi
|
|
472
|
+
|
|
277
473
|
echo
|
|
278
474
|
if [ "$FAILURES" -eq 0 ]; then
|
|
279
475
|
echo "py-dependency-audit-classification.test.sh: all checks passed."
|
|
@@ -171,7 +171,14 @@ _classify_finding() {
|
|
|
171
171
|
return
|
|
172
172
|
fi
|
|
173
173
|
|
|
174
|
-
|
|
174
|
+
# Read from a regular file, not a pipe: `_lockfile_version_for`'s awk `exit`s
|
|
175
|
+
# on its first match and closes its stdin, so a pipe with `printf` still
|
|
176
|
+
# writing into it gets SIGPIPE and dash reports a stray "printf: I/O error"
|
|
177
|
+
# into the log (#2120 -- the same mechanism #1995 removed from the dump path).
|
|
178
|
+
base_lock_file="$(mktemp)"
|
|
179
|
+
printf '%s\n' "$base_lock_content" > "$base_lock_file"
|
|
180
|
+
base_version="$(_lockfile_version_for "$finding_name" < "$base_lock_file")"
|
|
181
|
+
rm -f "$base_lock_file"
|
|
175
182
|
if [ -n "$base_version" ] && [ "$base_version" = "$finding_version" ]; then
|
|
176
183
|
printf 'pre-existing'
|
|
177
184
|
else
|
|
@@ -340,6 +347,49 @@ for lock in $ALL_LOCKS; do
|
|
|
340
347
|
fi
|
|
341
348
|
done
|
|
342
349
|
|
|
350
|
+
# ## Export the lockfile that is classified (#2120)
|
|
351
|
+
#
|
|
352
|
+
# `_classify_finding` compares a flagged version against `<tree>/uv.lock` on
|
|
353
|
+
# the base branch, so the export MUST read `<tree>/uv.lock` too. It did not for
|
|
354
|
+
# a tree that is a uv WORKSPACE MEMBER: `uv export` run inside a member walks
|
|
355
|
+
# up to the workspace root and exports the ROOT's `uv.lock`. The audit then
|
|
356
|
+
# scanned one lockfile and classified against another -- a pre-existing root
|
|
357
|
+
# advisory read as "introduced by this diff" for every member tree, and the
|
|
358
|
+
# member's own lock was never audited at all (biffo-platform PR 197).
|
|
359
|
+
#
|
|
360
|
+
# The cause is removed rather than detected: the tree's `pyproject.toml` and
|
|
361
|
+
# `uv.lock` are staged ALONE in a scratch directory outside the repository, so
|
|
362
|
+
# there is no workspace above them for uv to find. The bytes exported are then
|
|
363
|
+
# the bytes at the path the classifier reads, by construction -- no membership
|
|
364
|
+
# detection, no second lookup that could disagree. `--frozen` reads the lock
|
|
365
|
+
# without re-resolving, so `[tool.uv.sources]` entries (path, workspace) need
|
|
366
|
+
# not resolve from the scratch directory; verified against uv 0.11.
|
|
367
|
+
#
|
|
368
|
+
# `$1` is the tree directory, the remaining arguments are `uv export` flags.
|
|
369
|
+
# Returns non-zero -- never a partial success -- if the tree has no
|
|
370
|
+
# pyproject.toml/uv.lock to stage or the scratch directory cannot be made or
|
|
371
|
+
# sits inside the repository (a TMPDIR under the repo would put the workspace
|
|
372
|
+
# back above the copy and silently restore the defect).
|
|
373
|
+
_export_own_lock() {
|
|
374
|
+
eo_dir="$1"
|
|
375
|
+
shift
|
|
376
|
+
eo_scratch="$(mktemp -d)" || return 1
|
|
377
|
+
case "$(cd "$eo_scratch" && pwd -P)/" in
|
|
378
|
+
"${REPO_ROOT}"/*)
|
|
379
|
+
rm -rf "$eo_scratch"
|
|
380
|
+
return 1
|
|
381
|
+
;;
|
|
382
|
+
esac
|
|
383
|
+
if ! cp "$eo_dir/pyproject.toml" "$eo_dir/uv.lock" "$eo_scratch/" 2>/dev/null; then
|
|
384
|
+
rm -rf "$eo_scratch"
|
|
385
|
+
return 1
|
|
386
|
+
fi
|
|
387
|
+
(cd "$eo_scratch" && uv export --frozen "$@")
|
|
388
|
+
eo_rc=$?
|
|
389
|
+
rm -rf "$eo_scratch"
|
|
390
|
+
return "$eo_rc"
|
|
391
|
+
}
|
|
392
|
+
|
|
343
393
|
# Audit each discovered tree. The workspace's own lockfile is audited via the
|
|
344
394
|
# INSTALLED environment `uv sync` already produced (unchanged from before —
|
|
345
395
|
# `uv run pip-audit` with no `-r`). Every other discovered lockfile is not an
|
|
@@ -383,13 +433,13 @@ for lock in $ALL_LOCKS; do
|
|
|
383
433
|
# audited -- verified on `services/ideation`, where the export keeps 25
|
|
384
434
|
# packages including three carried `via biffo-plugin-sdk`. So the answer this
|
|
385
435
|
# gate gives is unchanged for every package an advisory can actually be about.
|
|
386
|
-
if
|
|
436
|
+
if _export_own_lock "$dir" --no-dev --no-emit-project --no-emit-local >"$reqs" 2>/dev/null && [ -s "$reqs" ]; then
|
|
387
437
|
# Report what was skipped rather than skipping it quietly: "audited
|
|
388
438
|
# everything except the bits we could not" must never read the same as
|
|
389
439
|
# "audited everything", which is the failure this whole file exists to
|
|
390
440
|
# fight. Counted from the same lockfile, so the number is the tree's, not
|
|
391
441
|
# a guess.
|
|
392
|
-
local_deps=$(
|
|
442
|
+
local_deps=$(_export_own_lock "$dir" --no-dev --no-emit-project 2>/dev/null \
|
|
393
443
|
| grep -cE '^-e |@ file://' || true )
|
|
394
444
|
if [ "${local_deps:-0}" -gt 0 ]; then
|
|
395
445
|
echo " (${rel}: ${local_deps} local path dependenc$([ "$local_deps" -eq 1 ] && echo y || echo ies) excluded -- first-party, audited in their own repo; their transitive dependencies are still scanned)"
|
package/dist/index.js
CHANGED
|
@@ -9744,24 +9744,25 @@ function readTomlStringArray(text, key) {
|
|
|
9744
9744
|
}
|
|
9745
9745
|
return depth === 0 ? strings : [];
|
|
9746
9746
|
}
|
|
9747
|
+
function normaliseName(name) {
|
|
9748
|
+
return name.replace(/[-_.]+/g, "-").toLowerCase();
|
|
9749
|
+
}
|
|
9747
9750
|
function readProjectName(text) {
|
|
9748
|
-
let
|
|
9749
|
-
|
|
9750
|
-
|
|
9751
|
-
|
|
9752
|
-
|
|
9753
|
-
continue;
|
|
9754
|
-
}
|
|
9755
|
-
if (inProject) {
|
|
9756
|
-
const m = /^name\s*=\s*["']([^"']+)["']/.exec(trimmed);
|
|
9757
|
-
if (m) return m[1];
|
|
9758
|
-
}
|
|
9751
|
+
let doc;
|
|
9752
|
+
try {
|
|
9753
|
+
doc = parseToml(text);
|
|
9754
|
+
} catch {
|
|
9755
|
+
return null;
|
|
9759
9756
|
}
|
|
9760
|
-
|
|
9757
|
+
const name = isTable(doc.project) ? doc.project.name : void 0;
|
|
9758
|
+
return typeof name === "string" && name !== "" ? name : null;
|
|
9761
9759
|
}
|
|
9762
9760
|
function requirementName(requirement) {
|
|
9763
9761
|
return /^\s*([A-Za-z0-9._-]+)/.exec(requirement)?.[1] ?? null;
|
|
9764
9762
|
}
|
|
9763
|
+
function stringsIn(value) {
|
|
9764
|
+
return Array.isArray(value) ? value.filter((v) => typeof v === "string") : [];
|
|
9765
|
+
}
|
|
9765
9766
|
function isTable(value) {
|
|
9766
9767
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9767
9768
|
}
|
|
@@ -9853,9 +9854,12 @@ function isSourcesHeader(header) {
|
|
|
9853
9854
|
function workspaceMemberNames(instanceRoot) {
|
|
9854
9855
|
const rootPyproject = join30(instanceRoot, "pyproject.toml");
|
|
9855
9856
|
if (!existsSync30(rootPyproject)) return /* @__PURE__ */ new Set();
|
|
9856
|
-
const
|
|
9857
|
-
const
|
|
9858
|
-
const
|
|
9857
|
+
const doc = parsePyproject(readFileSync21(rootPyproject, "utf8"), rootPyproject);
|
|
9858
|
+
const tool = isTable(doc.tool) ? doc.tool : {};
|
|
9859
|
+
const uv = isTable(tool.uv) ? tool.uv : {};
|
|
9860
|
+
const workspace = isTable(uv.workspace) ? uv.workspace : {};
|
|
9861
|
+
const members = stringsIn(workspace.members);
|
|
9862
|
+
const excluded = new Set(stringsIn(workspace.exclude));
|
|
9859
9863
|
const dirs = [];
|
|
9860
9864
|
for (const member of members) {
|
|
9861
9865
|
if (member.endsWith("/*")) {
|
|
@@ -9879,7 +9883,7 @@ function workspaceMemberNames(instanceRoot) {
|
|
|
9879
9883
|
const pp = join30(instanceRoot, dir, "pyproject.toml");
|
|
9880
9884
|
if (!existsSync30(pp)) continue;
|
|
9881
9885
|
const name = readProjectName(readFileSync21(pp, "utf8"));
|
|
9882
|
-
if (name) names.add(name);
|
|
9886
|
+
if (name) names.add(normaliseName(name));
|
|
9883
9887
|
}
|
|
9884
9888
|
return names;
|
|
9885
9889
|
}
|
|
@@ -9887,13 +9891,12 @@ function ensureWorkspaceSources(pluginPyprojectPath, memberNames) {
|
|
|
9887
9891
|
if (!existsSync30(pluginPyprojectPath) || memberNames.size === 0) return [];
|
|
9888
9892
|
const text = readFileSync21(pluginPyprojectPath, "utf8");
|
|
9889
9893
|
const doc = parsePyproject(text, pluginPyprojectPath);
|
|
9890
|
-
const
|
|
9891
|
-
const
|
|
9892
|
-
const
|
|
9894
|
+
const members = new Set([...memberNames].map(normaliseName));
|
|
9895
|
+
const already = new Set([...existingSourceNames(doc)].map(normaliseName));
|
|
9896
|
+
const declared = new Set(readDeclaredDependencyNames(doc).map(normaliseName));
|
|
9897
|
+
const toAdd = [...declared].filter((n) => members.has(n) && !already.has(n));
|
|
9893
9898
|
if (toAdd.length === 0) return [];
|
|
9894
|
-
const lines = toAdd.map(
|
|
9895
|
-
(n) => `${/^[A-Za-z0-9_-]+$/.test(n) ? n : JSON.stringify(n)} = { workspace = true }`
|
|
9896
|
-
);
|
|
9899
|
+
const lines = toAdd.map((n) => `${n} = { workspace = true }`);
|
|
9897
9900
|
let updated;
|
|
9898
9901
|
if (hasSourcesTable(doc)) {
|
|
9899
9902
|
const insertAt = sourcesHeaderLineEnd(text);
|
|
@@ -9916,7 +9919,7 @@ ${lines.join("\n")}
|
|
|
9916
9919
|
}
|
|
9917
9920
|
let written = /* @__PURE__ */ new Set();
|
|
9918
9921
|
try {
|
|
9919
|
-
written = existingSourceNames(parseToml(updated));
|
|
9922
|
+
written = new Set([...existingSourceNames(parseToml(updated))].map(normaliseName));
|
|
9920
9923
|
} catch {
|
|
9921
9924
|
}
|
|
9922
9925
|
const missing = toAdd.filter((n) => !written.has(n));
|