rules:
  - id: typescript-tls-version-too-old
    patterns:
      - pattern-either:
          - pattern: |
              tls.createServer({..., minVersion: "TLSv1", ...})
          - pattern: |
              tls.createServer({..., minVersion: "TLSv1.1", ...})
          - pattern: |
              tls.connect({..., minVersion: "TLSv1", ...})
          - pattern: |
              tls.connect({..., minVersion: "TLSv1.1", ...})
          - pattern: |
              https.createServer({..., minVersion: "TLSv1", ...})
          - pattern: |
              https.createServer({..., minVersion: "TLSv1.1", ...})
          - pattern: |
              tls.createServer({..., secureProtocol: "TLSv1_method", ...})
          - pattern: |
              tls.createServer({..., secureProtocol: "TLSv1_1_method", ...})
    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: [typescript]
    metadata:
      category: security
      technology: [typescript, nodejs, 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: typescript-tls-cert-validation-disabled
    patterns:
      - pattern-either:
          - pattern: |
              tls.connect({..., rejectUnauthorized: false, ...})
          - pattern: |
              https.request({..., rejectUnauthorized: false, ...})
          - pattern: |
              new https.Agent({..., rejectUnauthorized: false, ...})
          - pattern: process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"
          - pattern: process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = "0"
    message: >-
      SECURITY VULNERABILITY: TLS certificate validation is disabled. This allows man-in-the-middle
      attacks and completely defeats TLS security.
    severity: ERROR
    languages: [typescript]
    metadata:
      category: security
      technology: [typescript, nodejs, 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: typescript-tls-weak-cipher-suite
    patterns:
      - pattern-either:
          - pattern: |
              tls.createServer({..., ciphers: "RC4-SHA:...", ...})
          - pattern: |
              tls.createServer({..., ciphers: "DES-CBC-SHA:...", ...})
          - pattern: |
              tls.createServer({..., ciphers: "NULL-SHA:...", ...})
          - pattern: |
              tls.createServer({..., ciphers: "aNULL:...", ...})
    message: >-
      Explicit weak cipher suite configuration bypasses secure TLS defaults. Use TLS 1.3 which negotiates
      cipher suites automatically.
    severity: ERROR
    languages: [typescript]
    metadata:
      category: security
      technology: [typescript, nodejs, 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
