Skip to content

[MEDIUM] Multiple High-Risk Dependencies with Known Security Issues - 18 Crates Flagged #247

@evmparser

Description

@evmparser

Bug description

The dependency tree contains multiple crates flagged as "HIGH RISK" in the cargo-geiger security analysis. These dependencies have sections of code that use unsafe Rust, which can introduce memory safety vulnerabilities if not carefully audited. For a Key Management System, any dependency handling cryptographic operations or memory management should be carefully vetted.

Severity: MEDIUM

Location: Cargo.toml and transitive dependencies

Specific High-Risk Dependencies Found

During security analysis, the following 18 crates were flagged with high-risk unsafe code usage:

Direct and critical dependencies:

  1. block-buffer - Used in cryptographic operations
  2. crypto-common - Core crypto primitives
  3. digest - Hashing operations
  4. generic-array - Array handling
  5. subtle - Constant-time operations (critical for crypto)
  6. typenum - Type-level numbers
  7. zeroize - Memory zeroing (critical for key management)
  8. ppv-lite86 - SIMD operations
  9. rand_core - Random number generation (critical for crypto)
  10. getrandom - System randomness source

Additional flagged crates:
11. byteorder - Byte manipulation
12. cpufeatures - CPU feature detection
13. libc - C library bindings
14. opaque-debug - Debug trait implementations
15. proc-macro2 - Procedural macros
16. quote - Code generation
17. syn - Syn parsing
18. unicode-ident - Unicode handling

Security Implications

Why this matters for a KMS:

  • Unsafe code can bypass Rust's memory safety guarantees
  • Cryptographic operations require careful memory management
  • Key material must be properly zeroized
  • Random number generation must be cryptographically secure
  • Any memory corruption could leak sensitive keys

Potential vulnerabilities:

  • Buffer overflows in cryptographic operations
  • Memory leaks of sensitive key material
  • Timing attacks if constant-time operations fail
  • RNG predictability if getrandom has issues

To Reproduce

Run cargo-geiger to see unsafe code usage:

cargo install cargo-geiger
cargo geiger --output-format GitHubMarkdown

The output will show:

  • Functions marked as "unsafe" in each crate
  • Percentage of unsafe code
  • Risk assessment for each dependency

Expected behavior

Recommended actions:

  1. Audit critical dependencies:

    • Review unsafe blocks in crypto-related crates
    • Verify zeroize is working correctly
    • Check rand_core and getrandom implementations
    • Ensure subtle constant-time operations are sound
  2. Consider safer alternatives where available:

    # Some crates have safer alternatives
    # Research and evaluate:
    - Are there pure-safe Rust alternatives?
    - Can unsafe usage be minimized?
    - Are these crates well-audited?
  3. Pin versions of critical dependencies:

    [dependencies]
    # Pin exact versions for security-critical crates
    rand_core = "=0.6.4"  # Exact version
    zeroize = "=1.7.0"    # Exact version
  4. Document security audit status:
    Create SECURITY_AUDIT.md:

    ## Dependency Security Audit Status
    
    ### Audited Dependencies
    - [ ] block-buffer: Audit completed on YYYY-MM-DD
    - [ ] crypto-common: Audit completed on YYYY-MM-DD
    - [ ] zeroize: Audit completed on YYYY-MM-DD
    ...
  5. Set up automated monitoring:

    # GitHub Action to monitor unsafe code
    - name: Check unsafe code usage
      run: |
        cargo install cargo-geiger
        cargo geiger --output-format Json > geiger-report.json
        # Alert if unsafe usage increases

Suggested Fix

Security hardening checklist:

  1. Audit all crypto-related dependencies with unsafe code
  2. Document which unsafe blocks have been reviewed
  3. Pin versions of all security-critical dependencies
  4. Set up cargo-audit + cargo-geiger in CI
  5. Create dependency update policy:
    • Security patches: immediate
    • Minor updates: review + test
    • Major updates: full audit

Example audit process:

// For each high-risk dependency, document:
// 1. Why this dependency is needed
// 2. What unsafe code it contains
// 3. Whether it's been audited
// 4. Alternative considered
// 5. Mitigation measures in place

// Example for zeroize:
// - Required for: Memory zeroing of key material
// - Unsafe usage: Direct memory manipulation
// - Audit status: Well-known crate, widely used
// - Alternatives: None with same guarantees
// - Mitigation: Used only for critical sections

Dependency validation:

# Use cargo-deny to enforce policies
[bans]
# Deny crates with known vulnerabilities
deny = []

[advisories]
# Fail on any vulnerability
vulnerability = "deny"
unmaintained = "warn"

Additional Context

Why cargo-geiger analysis matters:

  • Identifies potential memory safety issues
  • Helps prioritize security audit efforts
  • Tracks unsafe code growth over time
  • Required for some security certifications

RustSec database statistics:

  • Many vulnerabilities come from unsafe code bugs
  • Crypto libraries are high-value targets
  • Regular audits catch issues early

Best practices for managing unsafe dependencies:

  1. Minimize unsafe code exposure
  2. Prefer well-audited crates (RustCrypto, Ring, etc.)
  3. Regular security reviews
  4. Track dependency changes in each release
  5. Use cargo-vet for supply chain verification

Recommended tools for dependency security:

  • cargo-audit - Vulnerability scanning
  • cargo-geiger - Unsafe code detection
  • cargo-deny - Dependency policy enforcement
  • cargo-vet - Supply chain verification
  • cargo-outdated - Update monitoring

References:

Impact:

  • High-risk dependencies increase attack surface

  • Unsafe code requires careful auditing

  • Crypto-related crates are critical to KMS security

  • Proper vetting reduces vulnerability risk

  • Would you like to work on a fix? [y/n] Yes, can help create comprehensive dependency audit documentation and security policies.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions