Skip to content

AD3035: RustEnableSecureSourceHash

Summary

Property Value
ID AD3035
Name RustEnableSecureSourceHash
Category Security
Severity Warning
Applies to ELF (Linux/Unix)

Description

When Rust compiles code with debug information, it can include hashes of source files to verify they haven't changed. The -Z src-hash-algorithm flag controls which hash algorithm is used. MD5 (the default in some configurations) is cryptographically broken and should not be used for any security-sensitive purpose.

Why This Matters

Source file hashes in debug information serve as a verification mechanism for the entire software supply chain. Using a broken hash algorithm like MD5 undermines this verification.

The MD5 Problem

MD5 has been cryptographically broken since 2004:

MD5 Weakness Impact
Collision attacks Two different files can have same hash
Prefix collisions Attacker can create malicious file with same hash
Speed of attack Collisions in seconds on modern hardware
Industry status Deprecated for all security uses

Supply Chain Attack Scenario

With MD5 hashes:
  1. Attacker finds source file hash in debug info
  2. Creates malicious file with same MD5 hash (collision)
  3. Substitutes malicious source in build cache
  4. Build system accepts it (hash matches)
  5. Malicious code compiled into binary

With SHA256 hashes:
  1. Creating collision is computationally infeasible
  2. Supply chain protected

Debug Information Integrity

Scenario MD5 Risk SHA256 Protection
Source tampering Undetected Detected
Build cache poisoning Possible Prevented
Reproducible builds Weak verification Strong verification
Forensic analysis Unreliable Reliable

Compliance Requirements

Standard MD5 Status
Microsoft SDL Prohibited
NIST Not approved for security
PCI DSS Must use strong crypto
FIPS 140-2 MD5 not allowed

Rust-Specific Considerations

Rust debug info may contain hashes for:

  • Source files (.rs)
  • Included files (proc macros)
  • Dependency sources
  • Build script outputs

All benefit from strong hashing.

Using SHA256 ensures: - Integrity verification: Source files can be reliably verified against their hashes - Resistance to collisions: SHA256 is resistant to collision attacks that could allow substitution of malicious source - SDL compliance: Meets Microsoft Security Development Lifecycle requirements for secure hash algorithms

Category

Security

Resolution

Enable SHA256 source hashing when building Rust binaries with debug information:

# In .cargo/config.toml
[build]
rustflags = ["-Z", "src-hash-algorithm=sha256"]

# Or directly with rustc
rustc -Z src-hash-algorithm=sha256 your_code.rs

# With cargo (nightly)
RUSTFLAGS="-Z src-hash-algorithm=sha256" cargo build

Note: The -Z flag requires nightly Rust or enabling unstable features.

Detection

This rule examines DWARF debug information in the binary to detect the source hash algorithm configuration: - Searches for src-hash-algorithm=sha256 in producer strings - Falls back to checking if MD5 is explicitly specified - Reports a note if no source hash information is found (may indicate release build)

Applicability

This rule applies to: - ELF binaries compiled with Rust (detected via rustc producer strings or Rust-specific symbols) - Binaries containing DWARF debug information

Examples

Pass

Binary compiled with: rustc -Z src-hash-algorithm=sha256

Fail

Binary compiled with default settings (MD5) or without specifying SHA256

References