fix(api/audit): expect() on serde_json::to_writer in stream_json (closes #5360)#5361
Merged
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
#5360) audit: audit-export-malformed-json (Severity: High). routes/audit.rs:385 used: let _ = serde_json::to_writer(&mut buf, &value); If to_writer fails, the chunk contains only ',' — producing output like [ , {...}, , {...} ] which is invalid JSON. to_writer into Vec<u8> is practically infallible today (no I/O), but the let _ masks the invariant: any future refactor that swaps the writer for a real tokio::io::AsyncWrite (S3 streaming, gzip pipe, etc.) silently corrupts every export. .expect() makes the infallibility load-bearing — any future writer-swap that CAN fail is forced to handle the error. Regression test test_stream_json_multi_entry_is_well_formed pins the EXTERNAL contract: every 5-entry export round-trips through serde_json::from_str::<Vec<Value>>. cargo test + cargo clippy clean.
houko
force-pushed
the
fix/audit-export-json
branch
from
May 21, 2026 03:38
db74cc0 to
ebc2804
Compare
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
# Conflicts: # openapi.json # sdk/go/librefang.go # sdk/javascript/index.js # sdk/python/librefang/librefang_client.py # sdk/rust/src/lib.rs
# Conflicts: # xtask/baselines/openapi.sha256
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #5360
Summary
Audit:
docs/issues/audit-export-malformed-json.md(Severity: High).routes/audit.rs:385had:If
to_writerfailed, the chunk contained only,— producingoutput like
[ , {...}, , {...} ]which is invalid JSON.serde_json::to_writerinto aVec<u8>is practically infallibletoday (no I/O involved), but the
let _ =masked the invariant:any future refactor that swaps the writer for a real
tokio::io::AsyncWrite(S3 streaming, gzip pipe, network tee, …)would silently corrupt every export.
Fix
Makes the infallibility load-bearing — any future writer-swap
that CAN fail is forced to handle the error rather than inherit
the silent-corruption behaviour.
Regression guard
test_stream_json_multi_entry_is_well_formedbuilds a 5-entryexport and round-trips it through
serde_json::from_str::<Vec< serde_json::Value>>. The existingtest_stream_json_includes_prev_hashexercised the 1-entrycase; the new test pins the multi-entry separator handling that
the original
let _ =could corrupt under failure.Verification
Both green.
Test plan
GET /api/audit/export?format=jsonwith 10+ audit rows →body parses as
Vec<Value>(browser dev tools /jq .)