Review 33438 of the PR: the guard's network hint matched the bare word
"index", which cargo prints on every run ("Updating crates.io index"), so a
manifest error was flagged as a possibly flaky run. The pattern now matches
cargo's network and index errors only. ADR 0018 and docs/architecture.md
said the guard runs `cargo update --dry-run`; it runs a real `cargo update`
in the scratch copy and reads the lock it writes there.
Refs #542
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
155 lines
6.8 KiB
Bash
Executable file
155 lines
6.8 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
# Guard for the RUSTSEC-2026-0459 entry of .cargo/audit.toml (#542, ADR 0018,
|
|
# amendment of 2026-11-14).
|
|
#
|
|
# That advisory is reachable: libsqlite3-sys 0.30.1 bundles SQLite 3.46 on both
|
|
# shipped targets. It is suppressed only because the fix (libsqlite3-sys >=
|
|
# 0.39) is out of reach of the graph: libsqlite3-sys declares
|
|
# `links = "sqlite3"`, so the graph holds one version of it, and sqlx-sqlite,
|
|
# pulled by tauri-plugin-sql through sqlx ^0.8, caps it below 0.38. The entry
|
|
# is justified for exactly as long as that block holds.
|
|
#
|
|
# The step asks cargo itself. It copies the manifest and the lockfile to a
|
|
# scratch directory, lifts every constraint this project owns on the SQLite
|
|
# stack (libsqlite3-sys >= 0.39, rusqlite, sqlx and tauri-plugin-sql at any
|
|
# stable version), and runs a full `cargo update` in that copy:
|
|
#
|
|
# - resolution fails on libsqlite3-sys: the block holds, the entry stays;
|
|
# - resolution succeeds: some upstream release now accepts the fix, so the
|
|
# suppression hides an advisory that a dependency update can fix. FAIL:
|
|
# update the SQLite stack and drop the entry;
|
|
# - resolution fails for any other reason: the guard cannot tell, FAIL.
|
|
#
|
|
# A canary runs the same probe without tauri-plugin-sql and sqlx, the two
|
|
# crates that carry the block. It must resolve libsqlite3-sys >= 0.39; if it
|
|
# does not, the probe cannot say "lifted" and its "blocked" means nothing.
|
|
#
|
|
# Blind spots, on purpose: "*" never selects a prerelease, and tauri stays at
|
|
# our "2". A fix shipped only in a tauri-plugin-sql 3.0.0-alpha, or one that
|
|
# needs tauri 3, reads as "blocked": it is not reachable by a dependency
|
|
# update. The follow-up issue watches those by hand.
|
|
#
|
|
# Never touches the repository: cargo resolves inside the scratch copy, which
|
|
# is removed on exit. Needs cargo and the network (crates.io index).
|
|
#
|
|
# Usage: scripts/check-sqlite-advisory-block.sh [path/to/src-tauri]
|
|
|
|
set -u
|
|
|
|
SRC_DIR="${1:-src-tauri}"
|
|
ADVISORY="RUSTSEC-2026-0459"
|
|
|
|
if [ ! -f "$SRC_DIR/Cargo.toml" ] || [ ! -f "$SRC_DIR/Cargo.lock" ]; then
|
|
echo "FAIL: $SRC_DIR/Cargo.toml or Cargo.lock not found — cannot verify the $ADVISORY suppression"
|
|
exit 1
|
|
fi
|
|
|
|
work=$(mktemp -d)
|
|
trap 'rm -rf "$work"' EXIT
|
|
|
|
# Copies the project manifest and lock into $1, with stub targets so cargo
|
|
# accepts the manifest, then lifts the SQLite-stack constraints. $2 = "canary"
|
|
# also removes the two crates that carry the block.
|
|
make_probe() {
|
|
local dir="$1" mode="$2"
|
|
mkdir -p "$dir/src"
|
|
cp "$SRC_DIR/Cargo.toml" "$SRC_DIR/Cargo.lock" "$dir/"
|
|
: > "$dir/src/lib.rs"
|
|
echo 'fn main() {}' > "$dir/src/main.rs"
|
|
sed -i -E \
|
|
-e 's/^libsqlite3-sys = \{ version = "[^"]*"/libsqlite3-sys = { version = ">=0.39"/' \
|
|
-e 's/^rusqlite = \{ version = "[^"]*"/rusqlite = { version = "*"/' \
|
|
-e 's/^sqlx = \{ version = "[^"]*"/sqlx = { version = "*"/' \
|
|
-e 's/^tauri-plugin-sql = \{ version = "[^"]*"/tauri-plugin-sql = { version = "*"/' \
|
|
"$dir/Cargo.toml"
|
|
if [ "$mode" = canary ]; then
|
|
sed -i -E '/^(tauri-plugin-sql|sqlx) = /d' "$dir/Cargo.toml"
|
|
fi
|
|
}
|
|
|
|
# Every edit must have landed, or the probe answers a different question.
|
|
check_edits() {
|
|
local dir="$1" mode="$2" missing=0 line
|
|
for line in 'libsqlite3-sys = { version = ">=0.39"' 'rusqlite = { version = "*"'; do
|
|
grep -qF "$line" "$dir/Cargo.toml" || { echo "FAIL: probe manifest ($mode) lacks: $line"; missing=1; }
|
|
done
|
|
if [ "$mode" = real ]; then
|
|
for line in 'sqlx = { version = "*"' 'tauri-plugin-sql = { version = "*"'; do
|
|
grep -qF "$line" "$dir/Cargo.toml" || { echo "FAIL: probe manifest ($mode) lacks: $line"; missing=1; }
|
|
done
|
|
else
|
|
if grep -qE '^(tauri-plugin-sql|sqlx) = ' "$dir/Cargo.toml"; then
|
|
echo "FAIL: canary manifest still declares tauri-plugin-sql or sqlx"
|
|
missing=1
|
|
fi
|
|
fi
|
|
return $missing
|
|
}
|
|
|
|
# Resolves the probe in $1 for real (the scratch copy only, never the
|
|
# repository) and prints the libsqlite3-sys version of the lock cargo wrote,
|
|
# empty if none. Reading the lock, not cargo's status lines, keeps the result
|
|
# independent of colours (check-rust.yml sets CARGO_TERM_COLOR=always) and of
|
|
# how a cargo version words its "Updating" lines.
|
|
resolve() {
|
|
local dir="$1"
|
|
out=$(cd "$dir" && cargo update --color never 2>&1)
|
|
status=$?
|
|
version=$(awk '/^name = "libsqlite3-sys"$/ { getline; gsub(/^version = "|"$/, ""); print; exit }' "$dir/Cargo.lock")
|
|
}
|
|
|
|
# 0.X.Y with X >= 39.
|
|
is_fixed() {
|
|
local v="$1" minor
|
|
case "$v" in 0.*.*) ;; *) return 1 ;; esac
|
|
minor=$(printf '%s' "$v" | cut -d. -f2)
|
|
[ "$minor" -ge 39 ] 2>/dev/null
|
|
}
|
|
|
|
network_hint() {
|
|
# cargo's network errors only: every run prints "Updating crates.io index",
|
|
# so a bare "index" would flag a manifest error as a flaky run.
|
|
if printf '%s\n' "$out" | grep -qiE 'failed to (download|fetch|query|get|load)|spurious network error|network failure|timed out|could not resolve host|ssl|connection (refused|reset)|failed to update the index'; then
|
|
echo " (the output reports a network or crates.io index error: a flaky run is possible, re-run before acting)"
|
|
fi
|
|
}
|
|
|
|
rc=0
|
|
|
|
# --- Canary: without the blockers, the fix must be reachable.
|
|
make_probe "$work/canary" canary
|
|
if check_edits "$work/canary" canary; then
|
|
resolve "$work/canary"
|
|
if [ "$status" -eq 0 ] && is_fixed "$version"; then
|
|
echo "ok: canary — without tauri-plugin-sql and sqlx, libsqlite3-sys resolves to $version"
|
|
else
|
|
echo "FAIL: canary — without tauri-plugin-sql and sqlx, libsqlite3-sys >= 0.39 did not resolve (exit $status, locked version '${version:-none}'). The probe cannot prove anything."
|
|
network_hint
|
|
printf '%s\n' "$out" | tail -20
|
|
rc=1
|
|
fi
|
|
else
|
|
rc=1
|
|
fi
|
|
|
|
# --- Real probe: with tauri-plugin-sql and sqlx, the fix must stay out of reach.
|
|
make_probe "$work/real" real
|
|
if check_edits "$work/real" real; then
|
|
resolve "$work/real"
|
|
if [ "$status" -eq 0 ]; then
|
|
echo "FAIL: libsqlite3-sys $version is now reachable with tauri-plugin-sql and sqlx. $ADVISORY can be fixed by a dependency update: update libsqlite3-sys, rusqlite, tauri-plugin-sql and our direct sqlx (db_pool_commands.rs, ADR 0027, may need code changes), then remove its entry from .cargo/audit.toml (#542, ADR 0018). Never edit this probe to make it green."
|
|
rc=1
|
|
elif printf '%s\n' "$out" | grep -qE 'links to the native library `sqlite3`|failed to select a version for `(libsqlite3-sys|sqlx-sqlite|rusqlite)`'; then
|
|
echo "ok: libsqlite3-sys >= 0.39 still unreachable with tauri-plugin-sql and sqlx (links = \"sqlite3\" conflict) — the $ADVISORY suppression stays justified"
|
|
else
|
|
echo "FAIL: cargo update failed for another reason (exit $status) — cannot verify the $ADVISORY suppression. A new cargo wording of the links conflict would also land here: read the output before touching anything."
|
|
network_hint
|
|
printf '%s\n' "$out" | tail -20
|
|
rc=1
|
|
fi
|
|
else
|
|
rc=1
|
|
fi
|
|
|
|
echo "SQLite advisory block guard: exit $rc"
|
|
exit $rc
|