fix(osv): avoid panic in rustsec_refs_imported on malformed refs - #1686
Closed
li-jin-quan wants to merge 1 commit into
Closed
fix(osv): avoid panic in rustsec_refs_imported on malformed refs#1686li-jin-quan wants to merge 1 commit into
li-jin-quan wants to merge 1 commit into
Conversation
Replace the hardcoded byte-range slice [31..48] and .expect() in OsvAdvisory::rustsec_refs_imported with a strip_prefix-based parse that skips malformed references instead of panicking. Previously, a reference URL matching the https://rustsec.org/advisories/ prefix but shorter than 48 bytes caused an out-of-bounds slice panic, and a URL that was long enough but did not contain a valid advisory ID caused a panic via .expect(). Both inputs now result in the reference being ignored. Fixes: rustsec#1681
Member
|
There's already a fix in |
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.
Fixes #1681
Summary
OsvAdvisory::rustsec_refs_imported()previously hard-coded a byte slice ([31..48]) on each reference URL, and used.expect()after stripping thehttps://rustsec.org/advisories/prefix. Any advisory with a malformed reference URL (wrong path, empty id, URL outside the expected host) caused a panic, crashing cargo-audit / cargo-deny runs.This is reachable in real-world data because the OSV ecosystem has historical advisories from before the URL scheme was canonicalised, and imports from upstream sources (Rust advisory DB, OSV.dev) regularly surface entries with non-conforming URLs.
Repro (panic)
Changes
.expect()withstrip_prefix("https://rustsec.org/advisories/")+filter_map+Id::from_str(...).ok().Notes
rustsec/src/osv/advisory.rs, +79/-5.Vec<Id>preserved).filter_mapinstead ofexpect) is used elsewhere in the crate; aligning this function reduces attack surface for downstream scanners.