Secure Development Lifecycle
Use security controls from design through release and maintenance. Keep design decisions, test results, and release records. This guide uses the NIST SSDF (SP 800-218) and the ANSSI Secure Rust Guidelines for Edition 2024 Rust projects.
Secure design for Rust
- Before you write code, make a threat model. Identify assets, trust boundaries, attacker capabilities, and entry points for untrusted input. Identify privilege changes, dependencies, and resource exhaustion risks. Update the threat model when the architecture, protocols, or deployment boundaries change.
- Make network listeners, destructive file operations, telemetry, weak algorithms, and elevated privileges opt-in. Fail closed if authentication, authorization, or validation fails.
- Limit operating system privileges, public APIs, enabled features,
dependencies, and data retention. For filesystem isolation, use a
capability API such as
cap-stdwhen possible. ItsDirhandles use facilities such asopenat2orO_RESOLVE_BENEATH. A capability API can prevent path traversal and races during symlink resolution without manual checks of path strings. - Set limits before you parse external input. Limit payload size, allocation,
recursion depth, decompression ratio, timeouts, and concurrency. Do not use
unwrap,expect, or unchecked slice indexing on untrusted input. - Check integer arithmetic. By default,
+,-, and*panic on overflow in debug builds. In release builds, the value wraps. Use.checked_*(),.saturating_*(), orTryFromfor security-sensitive sizes, offsets, and quotas. If a panic or abort is safer than wraparound, setoverflow-checks = truein[profile.release]. - Set
unsafe_code = "forbid"in[lints.rust]when the crate uses only safe Rust. Ifunsafeis necessary in a reviewed module, setunsafe_code = "deny"in[lints.rust]. Use#[allow(unsafe_code)]only on that module. Give the module a small safe interface. Keep the Edition 2024 checks forunsafe_op_in_unsafe_fn,unsafe extern, and#[unsafe(...)]active. Setclippy::undocumented_unsafe_blocks = "deny". - Use reviewed cryptographic libraries. Do not write new cryptographic
primitives or TLS implementations. If possible, use a memory-safe TLS library such as
rustlswithaws-lc-rsorring. Clear key material on drop withzeroizeorsecrecy. Compare digests and tokens in constant time withsubtle. - Apply the same controls to code from coding agents and persons. Use human peer review, threat model checks, license and provenance checks, and CI security checks. Refer to NIST SP 800-218A.
Development and release checks
| When | Actions | Records |
|---|---|---|
| Design or major change | Make a threat model. Review trust boundaries and resource limits. | Architecture decision record, issue, or docs/security/threat-model.md |
| Each change | Get an independent review. Check the format, Clippy lints, tests, and locked dependencies. | Pull request, CI results, and review record |
| Change to a trust boundary | Add negative tests and proptest checks. Add cargo-fuzz targets for parsers and decoders. |
Tests, fuzz corpus, and scheduled fuzz tests |
unsafe or FFI change |
Get Code Owner review. Document the invariant in a // SAFETY: comment. Use Miri, sanitizers, or Kani. |
Review approval and job log |
| Dependency or workflow change | Examine licenses, sources, advisories, and minimum publication age. Update the audit records. Check workflows with zizmor. |
Pull request, deny.toml, and supply-chain/ |
| Release | Build with cargo-auditable and --locked. Publish with OIDC. Add an SBOM, SHA-256 checksums, and SLSA provenance. |
Protected release workflow and release files |
| Incident or defect | Assess the defect. Correct the cause. Coordinate disclosure with GitHub and RustSec. | Advisory and regression test |
Tests for security properties
Select the test method for the type of failure.
- Use
proptestto check invariants with random inputs. Make sure that parsers do not panic and that serialization preserves data. Check for quota overflow and make sure that access checks fail closed. - Use coverage-guided fuzzing for binary formats, network frames, archive
extractors, and foreign function interfaces. Use
cargo-fuzzwithlibFuzzer. Schedule the tests in CI or use OSS-Fuzz. Keep the initial test inputs in Git. - Use
cargo-mutantsto check that the suite finds missing authorization checks, boundary checks, and error branches. - Use
cargo +nightly miri testto find aliasing and pointer provenance defects inunsafeRust. Use LLVM sanitizers (ASAN,TSAN, andUBSAN) at C interfaces. Use Kani to check for panics and undefined behavior in critical state machines that the model covers.
Rust-specific policy decisions
Record the values and conditions for these policies in the repository documentation.
| Topic | Policy |
|---|---|
unsafe |
Locations that can use unsafe, Code Owner review, // SAFETY: comments, and Miri checks |
| Foreign function interface (FFI) | Tier 1 targets, pure-Rust alternatives (such as rustls and miniz_oxide), C compiler flags, ABI checks, and CVE ownership |
| Arithmetic and panics | Overflow checks, for example checked_* or [profile.release] overflow-checks. Rules for untrusted input and the choice of panic abort or unwind. |
| Features | Necessary default features, security effects of optional features, and feature combinations for CI |
| Network and files | Timeouts, payload limits, TLS 1.2 and 1.3 policy (rustls), directory access with cap-std, and removal of secrets from logs |
| Dependencies | Permitted registries, minimum publication age, rolling MSRV, and cargo vet exemption expiration dates |
SSDF crosswalk
The NIST SSDF has four groups. The table shows controls for each group.
| SSDF group | Controls for a Rust project |
|---|---|
| Prepare the Organization (PO) | Roles and procedures in GOVERNANCE.md, SECURITY.md, AGENTS.md, and CODEOWNERS. Threat model, lints, MSRV, and unsafe policy. |
| Protect the Software (PS) | Rulesets, multi-factor authentication, Push Protection, full commit SHAs for actions, zizmor, read-only tokens, and crates.io OIDC Trusted Publishing |
| Produce Well-Secured Software (PW) | Safe defaults, Edition 2024, Clippy, proptest, cargo-fuzz, Miri, and Kani. Dependency audits, minimum publication age, cargo-auditable, an SBOM, and SLSA provenance. |
| Respond to Vulnerabilities (RV) | Private reports, CRA and service-level deadlines, scheduled scans, cargo audit bin, RustSec disclosure, and regression tests |