1---2name: rust-security3description: Use when auditing Rust dependencies for vulnerabilities, enforcing license and source policies with cargo-deny, reviewing RUSTSEC advisories, or fuzzing and testing unsafe code for security.4---56# Rust security78## Contract910| Field | Bound contract |11|---|---|12| Trigger | Rust supply chain, dependency auditing, `cargo-audit`, `cargo-deny`, RUSTSEC, safe FFI, or fuzzing for security. |13| Authority | Read-only. Chat output only. No remote mutation. |14| Side effect | Emits a security audit report with findings and recommendations; does not modify source files. |15| Done | A report is emitted that lists vulnerabilities, policy violations, FFI risks, and recommended tools. |1617## Inputs18191. **Audit target** (required): the Cargo project path or dependency list.202. **Tool** (required): `cargo-audit`, `cargo-deny`, `cargo-fuzz`, Miri, or manual review.213. **Policy context** (optional): license allowlist, banned crates, allowed sources, CI environment.2223## Procedure24251. **Run `cargo-audit`.** Install `cargo-audit 0.22.2` with `cargo install cargo-audit --locked`, then run `cargo audit`. Use `cargo audit --deny warnings`, `cargo audit --file Cargo.lock`, or `cargo audit --json` for CI. The `--format json` and `--format sarif` options are also available. Done when: the audit output lists advisories or reports none.262. **Run `cargo-deny`.** Install `cargo-deny 0.20.2` with `cargo install cargo-deny --locked`, run `cargo deny init` for a template, then run `cargo deny check [advisories|licenses|bans|sources|all]`. Configure `deny.toml` as shown below. Done when: the check runs and any policy violation is reported.2728```toml29[advisories]30yanked = "deny"31unmaintained = "workspace"32ignore = [33 "RUSTSEC-2021-0145",34]3536[licenses]37allow = [38 "MIT",39 "Apache-2.0",40 "Apache-2.0 WITH LLVM-exception",41 "BSD-2-Clause",42 "BSD-3-Clause",43 "ISC",44]4546[bans]47multiple-versions = "warn"48wildcards = "deny"49deny = [50 { crate = "openssl", use-instead = "rustls" },51]5253[sources]54unknown-registry = "deny"55unknown-git = "deny"56allow-git = [57 "https://github.com/my-org/private-crate",58]59```60613. **Check the RUSTSEC database.** Use `cargo audit` or browse `https://rustsec.org/`. Classify advisories as `vulnerability`, `unmaintained`, or `unsound`. Done when: the advisory list and categories are known.624. **Review FFI boundaries.** For each `extern "C"` function, validate pointer and length arguments, document the C invariant, and prefer safe wrapper crates. Done when: each FFI entry point has explicit validation.635. **Fuzz for security bugs.** Install `cargo-fuzz` with `cargo install cargo-fuzz`, run `cargo fuzz init`, `cargo fuzz add <target>`, and `cargo fuzz run --sanitizer address <target>`. Reproduce crashes with `cargo fuzz run <target> <artifact>`. Done when: a fuzz target runs or a crash is reproduced.646. **Confirm soundness with Miri.** Run `cargo +nightly miri test` on unsafe code. Use `MIRIFLAGS="-Zmiri-disable-isolation -Zmiri-backtrace=full"` when needed. Done when: Miri reports UB or completes cleanly.657. **Harden the supply chain.** Keep `Cargo.lock` for binaries, run `cargo fetch --locked`, review duplicates with `cargo tree -d`, consider `cargo vet` for peer-reviewing new dependencies, and use `cargo-machete` to find unused dependencies. Done when: the supply-chain state is reported.6667## Failure and recovery6869| Failure class | Behavior |70|---|---|71| `cargo-audit` reports a vulnerability | Upgrade, ignore with a rationale, or replace the dependency. |72| `cargo-deny` policy violation | Edit `deny.toml` or resolve the license, banned crate, or source issue. |73| FFI input cannot be validated | Add checks or change the C contract to require valid pointers and lengths. |74| Fuzz target finds no bugs | Let it run longer, add a seed corpus, or add a dictionary. |75| Miri reports unsupported FFI | Stub the foreign function under `#[cfg(miri)]`. |7677## Output78791. A security report with vulnerabilities, advisories, policy violations, and FFI risks.802. Recommended commands and configuration files.813. A fuzzing and Miri test plan.824. A prioritized remediation list.