rules:
  - id: scala-tls-version-too-old
    patterns:
      - pattern-either:
          - pattern: SSLContext.getInstance("TLSv1")
          - pattern: SSLContext.getInstance("TLSv1.1")
          - pattern: SSLContext.getInstance("SSLv3")
          - pattern: SSLContext.getInstance("SSLv2")
          - pattern: SSLContext.getInstance("SSL")
    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: [scala]
    metadata:
      category: security
      technology: [scala, jvm, 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: scala-tls-cert-validation-disabled
    patterns:
      - pattern-either:
          - pattern: |
              val $TM = Array(new X509TrustManager {
                def checkServerTrusted(...): Unit = {}
                ...
              })
          - pattern: $CTX.init(null, $TM, null)
    message: >-
      SECURITY VULNERABILITY: TLS certificate validation is disabled. This allows man-in-the-middle
      attacks and completely defeats TLS security.
    severity: ERROR
    languages: [scala]
    metadata:
      category: security
      technology: [scala, jvm, tls]
      cwe:
        - "CWE-295: Improper Certificate Validation"
      owasp:
        - A02:2021 - Cryptographic Failures
      confidence: MEDIUM
      likelihood: HIGH
      impact: CRITICAL
      quantum_vulnerable: false
      quantum_risk_score: 9

  - id: scala-tls-weak-cipher-suite
    patterns:
      - pattern-either:
          - pattern: $ENGINE.setEnabledCipherSuites(Array("SSL_RSA_WITH_RC4_128_SHA", ...))
          - pattern: $ENGINE.setEnabledCipherSuites(Array("SSL_RSA_WITH_DES_CBC_SHA", ...))
          - pattern: $ENGINE.setEnabledCipherSuites(Array("TLS_RSA_WITH_NULL_SHA", ...))
          - pattern: $SOCKET.setEnabledCipherSuites(Array("SSL_RSA_WITH_RC4_128_SHA", ...))
    message: >-
      Explicit weak cipher suite configuration bypasses secure TLS defaults. Use TLS 1.3 which negotiates
      cipher suites automatically.
    severity: ERROR
    languages: [scala]
    metadata:
      category: security
      technology: [scala, jvm, 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
