rustsec / rustsec/rustsec

rustsec_refs_imported() could possibly panic on short or malformed rustsec.org URLs

Open Beginner friendly
#1,681 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
2k
Forks
198
Avg merge
2d 6h
Merged PRs (30d)
8

Description

Summary

I see hardcoded byte-range slice [31..48] usage in the function rustsec_refs_imported()

rustsec/src/osv/advisory.rs

    /// Try to extract RustSec alias id from OSV advisory metadata
    pub fn rustsec_refs_imported(&self) -> Vec<Id> {
        let mut refs: Vec<Id> = self
            .references
            .iter()
            .filter(|r| {
                r.url
                    .as_str()
                    .starts_with("https://rustsec.org/advisories/")
            })
            .map(|r| Id::from_str(&r.url.as_str()[31..48]).expect("Invalid rustsec url"))
            .collect();
        refs.sort();
        refs.dedup();
        refs
    }

It seems that the prefix "https://rustsec.org/advisories/" is 31 bytes.
The slice [31..48] assumes 17 more bytes for the following (the length of RUSTSEC-YYYY-NNNN) ?
URLs that match the prefix but are shorter than 48 bytes cause an out-of-bounds panic.
Also, URLs that are long enough but don't contain a valid advisory ID cause a panic from expect.

Reproduce

Create a reference URL that starts with https://rustsec.org/advisories/ but is shorter than 48 bytes, then call rustsec_refs_imported()

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in rustsec/src/osv/advisory.rs at rustsec_refs_imported() and inspect how advisory reference URLs are parsed. Reproduce the short and malformed rustsec.org URL cases described in the issue, then run the project's tests. Done means these inputs no longer panic while valid advisory references continue to produce IDs.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
security
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.