rules:
  - id: auth.csharp.crypto.weak-password-hash
    languages:
      - csharp
    severity: ERROR
    message: |
      A password is hashed with a fast general-purpose digest (`MD5`, `SHA1`,
      `SHA256`, `SHA512`) from System.Security.Cryptography. These are designed to
      be fast, which makes offline brute-force and rainbow-table attacks cheap;
      they are NOT suitable for storing passwords (CWE-916).

      Use ASP.NET Core Identity's `PasswordHasher<TUser>`, or a slow, salted
      password KDF: PBKDF2 (`Rfc2898DeriveBytes` with a high iteration count),
      bcrypt, or Argon2.
    patterns:
      - pattern-either:
          - pattern: System.Security.Cryptography.MD5.HashData($PW)
          - pattern: MD5.HashData($PW)
          - pattern: SHA1.HashData($PW)
          - pattern: SHA256.HashData($PW)
          - pattern: SHA512.HashData($PW)
          - pattern: $H.ComputeHash($PW)
      - metavariable-regex:
          metavariable: $PW
          regex: (?i).*(password|passwd|pwd|passphrase).*
    paths:
      exclude:
        - "**/test/**"
        - "**/*Test.cs"
        - "**/*Tests.cs"
    metadata:
      oauthlint-rule-id: AUTH-CSHARP-CRYPTO-002
      oauthlint-doc-url: https://oauthlint.dev/rules/csharp-crypto-weak-password-hash
      category: security
      cwe: CWE-916
      owasp: A02:2021
      llm-prevalence: HIGH
      technology:
        - dotnet
      references:
        - https://learn.microsoft.com/aspnet/core/security/data-protection/consumer-apis/password-hashing
        - https://cwe.mitre.org/data/definitions/916.html
