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 →
MEDIUM AI PREVALENCE: MEDIUM auth.csharp.crypto.ecb-mode

A symmetric cipher is configured with CipherMode.ECB.

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

Why this matters

ECB encrypts each block independently, so identical plaintext blocks produce identical ciphertext, leaking structure and enabling block-shuffling attacks (CWE-327). This matters for anything auth-related: encrypted tokens, cookies, or credentials.

Use an authenticated mode instead: prefer AES-GCM (AesGcm) or, failing that, CBC with a random IV and a separate MAC.

VULNERABLE
vulnerable.cs
using System.Security.Cryptography;

public class Crypto
{
    public byte[] Encrypt(byte[] data, byte[] key)
    {
        using var aes = Aes.Create();
        aes.Key = key;
        // ruleid: auth.csharp.crypto.ecb-mode
        aes.Mode = CipherMode.ECB;
        var enc = aes.CreateEncryptor();
        return enc.TransformFinalBlock(data, 0, data.Length);
    }
}
SAFE
safe.cs
using System.Security.Cryptography;

public class Crypto
{
    public byte[] Encrypt(byte[] data, byte[] key)
    {
        using var aes = Aes.Create();
        aes.Key = key;
        // ok: CBC with a random IV
        aes.Mode = CipherMode.CBC;
        aes.GenerateIV();
        var enc = aes.CreateEncryptor();
        return enc.TransformFinalBlock(data, 0, data.Length);
    }
}

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.csharp.crypto.ecb-mode -- <reason>

References

https://cwe.mitre.org/data/definitions/327.html ↗