[Paper Review] Auditing Rust Crates Effectively
The paper introduces Cargo Scan, an interactive static analysis tool that identifies potentially dangerous effects in Rust crates, enabling context-aware audits and reducing manual review effort. It shows substantial efficiency gains and scalable ecosystem coverage for auditing third-party Rust code.
We introduce Cargo Scan, the first interactive program analysis tool designed to help developers audit third-party Rust code. Real systems written in Rust rely on thousands of transitive dependencies. These dependencies are as dangerous in Rust as they are in other languages (e.g., C or JavaScript) -- and auditing these dependencies today means manually inspecting every line of code. Unlike for most industrial languages, though, we can take advantage of Rust's type and module system to minimize the amount of code that developers need to inspect to the code that is potentially dangerous. Cargo Scan models such potentially dangerous code as effects and performs a side-effects analysis, tailored to Rust, to identify effects and track them across crate and module boundaries. In most cases (69.2%) developers can inspect flagged effects and decide whether the code is potentially dangerous locally. In some cases, however, the safety of an effect depends on the calling context -- how a function is called, potentially by a crate the developer imports later. Hence, Cargo Scan tracks context-dependent information using a call-graph, and collects audit results into composable and reusable audit files. In this paper, we describe our experience auditing Rust crates with Cargo Scan. In particular, we audit the popular client and server HTTP crate, hyper, and all of its dependencies; our experience shows that Cargo Scan can reduce the auditing burden of potentially dangerous code to a median of 0.2% of lines of code when compared to auditing whole crates. Looking at the Rust ecosystem more broadly, we find that Cargo Scan can automatically classify ~3.5K of the top 10K crates on crates.io as safe; of the crates that do require manual inspection, we find that most of the potentially dangerous side-effects are concentrated in roughly 3% of these crates.
Motivation & Objective
- Motivate the need to audit third-party Rust crates due to transitive dependencies in real systems.
- Propose a Rust-specific, effect-based static analysis to identify potentially dangerous code.
- Provide an interactive auditing workflow that propagates context across call graphs.
- Evaluate Cargo Scan on popular crates and quantify auditing efficiency and coverage.
- Demonstrate whether Cargo Scan can classify crates as safe automatically and identify context-sensitive safety.
Proposed method
- Model potentially dangerous operations as effects and perform a Rust-tailored static analysis to map effects to function calls.
- Build a call graph and annotate effects with local or context-dependent safety using a taint-like analysis.
- Provide three safety annotations (safe, unsafe, caller-checked) and propagate caller-checked effects across dependencies.
- Implement an interactive auditing interface as a VSCode extension to navigate effects and call sites.
- Generate default, conservative audits that mark all effects as caller-checked to bound auditing scope across packages.
- Evaluate performance on top crates analyses and a case study auditing hyper and its dependencies.
Experimental results
Research questions
- RQ1What fraction of top Rust crates contain any side effects?
- RQ2How valuable are context-sensitive (caller-checked) effects for auditing accuracy?
- RQ3Can Cargo Scan reduce the amount of code auditors need to review compared with full manual auditing?
- RQ4How do effects propagate across crate boundaries and how many public APIs are affected?
- RQ5Can default audits adequately bound auditing effort across dependencies?
Key findings
- Approximately 34.34% of top crates are pure (no dangerous side effects).
- About 85% of all effects are concentrated in roughly 3% of crates.
- For hyper, 30.8% of functions’ safety is context-sensitive and 5.2% of functions’ safety is context-sensitive across package boundaries.
- Auditing with Cargo Scan reduces the median reviewed code to 0.2% of lines compared with auditing code without Cargo Scan.
- When auditing the hyper crate and dependencies, 13.1% (mean) and 0.4% (median) of lines across packages were reviewed under default audits, with cross-package audits showing reduced effort.
- Cargo Scan can automatically classify roughly 3.5K of the top 10K crates as safe.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.