rules:
  - id: lua-tls-version-too-old
    patterns:
      - pattern-either:
          - pattern-regex: 'ssl\.newcontext\s*\(\s*\{[^}]*protocol\s*=\s*[''"]tlsv1[''"]'
          - pattern-regex: 'ssl\.newcontext\s*\(\s*\{[^}]*protocol\s*=\s*[''"]tlsv1_1[''"]'
          - pattern-regex: 'ssl\.newcontext\s*\(\s*\{[^}]*protocol\s*=\s*[''"]sslv[23][''"]'
          - pattern-regex: 'ssl\.wrap\s*\([^,]+,\s*\{[^}]*protocol\s*=\s*[''"]tlsv1[''"]'
          - pattern-regex: 'ssl\.wrap\s*\([^,]+,\s*\{[^}]*protocol\s*=\s*[''"]sslv[23][''"]'
    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: [lua]
    metadata:
      category: security
      technology: [lua, luasec, openresty, 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: lua-tls-cert-validation-disabled
    patterns:
      - pattern-either:
          - pattern-regex: 'ssl\.newcontext\s*\(\s*\{[^}]*verify\s*=\s*[''"]none[''"]'
          - pattern-regex: 'ssl\.wrap\s*\([^,]+,\s*\{[^}]*verify\s*=\s*[''"]none[''"]'
    message: >-
      SECURITY VULNERABILITY: TLS certificate validation is disabled via verify="none". This allows
      man-in-the-middle attacks and completely defeats TLS security.
    severity: ERROR
    languages: [lua]
    metadata:
      category: security
      technology: [lua, luasec, openresty, 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: lua-tls-weak-cipher-suite
    patterns:
      - pattern-either:
          - pattern-regex: 'ssl\.newcontext\s*\(\s*\{[^}]*ciphers\s*=\s*[''"](?:RC4|DES|NULL|aNULL|eNULL)'
    message: >-
      Explicit weak cipher suite configuration bypasses secure TLS defaults. Use TLS 1.3 which negotiates
      cipher suites automatically.
    severity: ERROR
    languages: [lua]
    metadata:
      category: security
      technology: [lua, luasec, openresty, 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
