Skip to content

Commit 611d91a

Browse files
committed
chore(audit): ignore yanked crate audit warnings
1 parent 2245e50 commit 611d91a

2 files changed

Lines changed: 27 additions & 5 deletions

File tree

.cargo/audit.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
[advisories]
22
ignore = [
3+
# Cargo.lock
4+
"RUSTSEC-2026-0186", # blame: floresta-chain@v0.5.0 -> memmap2@v0.9.10
5+
36
# Cargo-recent.lock
47
"RUSTSEC-2026-0097", # blame: floresta-wire@v0.5.0 -> bip324@v0.10.0 -> rand@v0.8.5
8+
"RUSTSEC-2026-0186", # blame: floresta-chain@v0.5.0 -> memmap2@v0.9.10
59

610
# Cargo-minimal.lock
711
"RUSTSEC-2024-0421", # blame: floresta-wire@v0.5.0 -> ureq@v3.1.0 -> cookie_store@v0.22.0 -> url@v2.3.1 -> idna@v0.3.0

contrib/run-cargo-audit.sh

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# Vulnerabilities and warnings which do not stem from direct
99
# dependencies show the full dependency tree for the affected package.
1010

11-
set -uo pipefail
11+
set -euo pipefail
1212

1313
# Check if `cargo-audit`, `cargo-rbmt`, `jq`, and `python3` are installed
1414
command -v cargo-audit >/dev/null 2>&1 || { echo "cargo-audit was not found on \$PATH"; exit 1; }
@@ -17,6 +17,7 @@ command -v jq >/dev/null 2>&1 || { echo "jq was not found on \$PATH"; exit 1; }
1717
command -v python3 >/dev/null 2>&1 || { echo "python3 was not found on \$PATH"; exit 1; }
1818

1919
WARNING_COUNTER=0
20+
WARNING_FAILURE_COUNTER=0
2021
VULNERABILITY_COUNTER=0
2122

2223
LOCKFILES=("Cargo.lock" "Cargo-recent.lock" "Cargo-minimal.lock")
@@ -141,10 +142,17 @@ format_findings() {
141142
local package_name
142143
local package_version
143144
local title
144-
advisory_id=$(echo "$finding" | jq -r '.advisory.id')
145+
advisory_id=$(echo "$finding" | jq -r '.advisory.id // (.kind | ascii_upcase) // "UNKNOWN"')
145146
package_name=$(echo "$finding" | jq -r '.package.name')
146147
package_version=$(echo "$finding" | jq -r '.package.version')
147-
title=$(echo "$finding" | jq -r '.advisory.title')
148+
title=$(echo "$finding" | jq -r '
149+
.advisory.title //
150+
if .kind == "yanked" then
151+
"crate version was yanked"
152+
else
153+
"non-advisory cargo-audit warning"
154+
end
155+
')
148156

149157
local branch
150158
local branch_transitive
@@ -170,6 +178,8 @@ format_findings() {
170178

171179
[ "$index" -lt $((total - 1)) ] && echo "${indent}"
172180
done
181+
182+
return 0
173183
}
174184

175185
# Copy the given lockfile to `Cargo.lock`, run `cargo audit`,
@@ -183,14 +193,22 @@ process_lockfile() {
183193

184194
local audit_output
185195
audit_output=$(cargo audit --json 2>/dev/null) || true
196+
if [ -z "$audit_output" ] || ! jq -e . >/dev/null <<< "$audit_output"; then
197+
echo "cargo audit failed for $lockfile" >&2
198+
exit 1
199+
fi
186200

187201
local vulnerabilities
188202
vulnerabilities=$(echo "$audit_output" | jq '.vulnerabilities.count // 0')
189203

190204
local warnings
191205
warnings=$(echo "$audit_output" | jq '[.warnings | to_entries[] | .value | length] | add // 0')
192206

207+
local warning_failures
208+
warning_failures=$(echo "$audit_output" | jq '[.warnings | to_entries[] | .value[] | select(.kind != "yanked")] | length')
209+
193210
WARNING_COUNTER=$((WARNING_COUNTER + warnings))
211+
WARNING_FAILURE_COUNTER=$((WARNING_FAILURE_COUNTER + warning_failures))
194212
VULNERABILITY_COUNTER=$((VULNERABILITY_COUNTER + vulnerabilities))
195213

196214
WARNING_COUNT[$lockfile]=$warnings
@@ -250,7 +268,7 @@ process_lockfile "Cargo-minimal.lock"
250268

251269
echo ""
252270

253-
if [ "$WARNING_COUNTER" -gt 0 ] || [ "$VULNERABILITY_COUNTER" -gt 0 ]; then
271+
if [ "$WARNING_FAILURE_COUNTER" -gt 0 ] || [ "$VULNERABILITY_COUNTER" -gt 0 ]; then
254272
echo "> Audit Status: FAILED"
255273
else
256274
echo "> Audit Status: SUCCESS"
@@ -282,6 +300,6 @@ for ((i=0; i<lockfile_total; i++)); do
282300
fi
283301
done
284302

285-
if [ "$WARNING_COUNTER" -gt 0 ] || [ "$VULNERABILITY_COUNTER" -gt 0 ]; then
303+
if [ "$WARNING_FAILURE_COUNTER" -gt 0 ] || [ "$VULNERABILITY_COUNTER" -gt 0 ]; then
286304
exit 1
287305
fi

0 commit comments

Comments
 (0)