rules:
  - id: ruby-tls-version-too-old
    patterns:
      - pattern-either:
          - pattern: $CTX.min_version = OpenSSL::SSL::TLS1_VERSION
          - pattern: $CTX.min_version = OpenSSL::SSL::TLS1_1_VERSION
          - pattern: $CTX.max_version = OpenSSL::SSL::TLS1_VERSION
          - pattern: $CTX.max_version = OpenSSL::SSL::TLS1_1_VERSION
          - pattern: $CTX.ssl_version = "TLSv1"
          - pattern: $CTX.ssl_version = "TLSv1_1"
          - pattern: $CTX.ssl_version = :TLSv1
          - pattern: $CTX.ssl_version = :TLSv1_1
    message: >-
      TLS 1.0/1.1 use broken cipher suites (RC4, 3DES, EXPORT) and are prohibited by RFC 8996. Upgrade to
      TLS 1.3.
    severity: ERROR
    languages: [ruby]
    metadata:
      category: security
      technology: [ruby, tls, post-quantum]
      cwe:
        - "CWE-326: Inadequate Encryption Strength"
      owasp:
        - A02:2021 - Cryptographic Failures
      confidence: HIGH
      likelihood: HIGH
      impact: HIGH
      quantum_vulnerable: true
      quantum_attack: "Blocks PQC migration"
      quantum_risk_score: 8

  - id: ruby-tls-cert-validation-disabled
    patterns:
      - pattern-either:
          - pattern: $CTX.verify_mode = OpenSSL::SSL::VERIFY_NONE
          - pattern: OpenSSL::SSL::SSLContext.new.tap { |$CTX| $CTX.verify_mode = OpenSSL::SSL::VERIFY_NONE }
          - pattern: $HTTP.verify_mode = OpenSSL::SSL::VERIFY_NONE
    message: >-
      TLS certificate verification is disabled -- connections are vulnerable to MITM attacks. Always enable
      certificate validation.
    severity: ERROR
    languages: [ruby]
    metadata:
      category: security
      technology: [ruby, tls]
      cwe:
        - "CWE-295: Improper Certificate Validation"
      owasp:
        - A02:2021 - Cryptographic Failures
      confidence: HIGH
      likelihood: HIGH
      impact: CRITICAL
      quantum_vulnerable: false
      quantum_risk_score: 9

  - id: ruby-tls-weak-cipher-suite
    patterns:
      - pattern-either:
          - pattern: $CTX.ciphers = "RC4-SHA:..."
          - pattern: $CTX.ciphers = "DES-CBC-SHA:..."
          - pattern: $CTX.ciphers = "NULL-SHA:..."
          - pattern: $CTX.ciphers = "aNULL:..."
    message: >-
      Explicit weak cipher suite configuration bypasses secure TLS defaults. Use TLS 1.3 which negotiates
      cipher suites automatically.
    severity: ERROR
    languages: [ruby]
    metadata:
      category: security
      technology: [ruby, tls, post-quantum]
      cwe:
        - "CWE-327: Use of a Broken or Risky Cryptographic Algorithm"
      owasp:
        - A02:2021 - Cryptographic Failures
      confidence: HIGH
      likelihood: MEDIUM
      impact: HIGH
      quantum_vulnerable: true
      quantum_attack: "Blocks PQC migration"
      quantum_risk_score: 8
