v0.14 is out: a mobile auth pack for Swift/iOS and Android, catching insecure token storage, cleartext traffic, and OAuth in embedded WebViews. Read more →
HIGH AI PREVALENCE: MEDIUM auth.rust.crypto.weak-cipher

A broken or deprecated cipher from the RustCrypto ecosystem is used to protect data.

Why AI tools produce this: AI coding tools produce this regularly, typically when prompted for a shortcut or a quick fix.

Why this matters

DES (Des::new, crate des) and 3DES (TdesEde3::new / TdesEde2::new) have a 64-bit block and are considered insecure (Sweet32, brute-force), while RC4 (Rc4::new, crate rc4) has well-known keystream biases and is forbidden by RFC 7465. For OAuth/OIDC this means tokens, client secrets, and other sensitive material are not adequately protected and may be recovered by an attacker.

Use an authenticated AEAD cipher instead: AES-GCM via the aes-gcm crate (Aes256Gcm::new(key)) or ChaCha20-Poly1305 (ChaCha20Poly1305::new(key)), both of which provide confidentiality and integrity.

VULNERABLE
vulnerable.rs
use des::cipher::{BlockEncrypt, KeyInit};
use des::{Des, TdesEde3};
use rc4::{KeyInit as Rc4KeyInit, Rc4, StreamCipher};

fn encrypt_token_des(key: &[u8]) -> impl BlockEncrypt {
    // ruleid: auth.rust.crypto.weak-cipher
    let cipher = Des::new(key.into());
    cipher
}

fn encrypt_secret_3des(key: &[u8]) -> impl BlockEncrypt {
    // ruleid: auth.rust.crypto.weak-cipher
    let cipher = TdesEde3::new(key.into());
    cipher
}

fn encrypt_token_rc4(key: &[u8]) -> impl StreamCipher {
    // ruleid: auth.rust.crypto.weak-cipher
    let cipher = Rc4::new(key.into());
    cipher
}
SAFE
safe.rs
use aes_gcm::aead::KeyInit;
use aes_gcm::Aes256Gcm;
use chacha20poly1305::ChaCha20Poly1305;

fn encrypt_token_aes_gcm(key: &[u8]) -> Aes256Gcm {
    // ok: auth.rust.crypto.weak-cipher
    let cipher = Aes256Gcm::new(key.into());
    cipher
}

fn encrypt_secret_chacha(key: &[u8]) -> ChaCha20Poly1305 {
    // ok: auth.rust.crypto.weak-cipher
    let cipher = ChaCha20Poly1305::new(key.into());
    cipher
}

Suppressing this rule

If a finding is a genuine false positive, scope the suppression to the exact line and leave a reason, never disable the rule project-wide. Disable directives are line-scoped by design.

// oauthlint-disable-next-line auth.rust.crypto.weak-cipher -- <reason>

References

https://cwe.mitre.org/data/definitions/327.html ↗https://docs.rs/aes-gcm/latest/aes_gcm/ ↗https://datatracker.ietf.org/doc/html/rfc7465 ↗