id: cookies-without-secure

info:
  name: Cookies without Secure attribute - Detect
  author: vthiery,RJ Coleman
  severity: info
  description: |
    Checks whether cookies in the HTTP response contain the Secure attribute. If the Secure flag is set, it means that the cookie can only be transmitted over HTTPS
  impact: |
    Lack of Secure flag on cookies allows the cookie to be sent over unsecure HTTP, making it vulnerable to man-in-the-middle (MITM) attacks.
  remediation: |
    Ensure that all cookies are set with the Secure attribute to prevent MITM attacks.
  reference:
    - https://owasp.org/www-community/controls/SecureCookieAttribute
  classification:
    cvss-metrics: CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:N
    cvss-score: 0
    cwe-id: CWE-614
  metadata:
    verified: true
    max-request: 1
  tags: misconfig,http,cookie,generic,vuln

flow: |
    http()
    javascript()

http:
  - method: GET
    path:
      - "{{BaseURL}}"
    host-redirects: true
    max-redirects: 2

javascript:
  - code: |
      content = template.http_all_headers
      const setCookieLines = content
        .split(/\r\n/)
        .filter(line => line.trim().toLowerCase().startsWith('set-cookie:'));
      const nonSecureCookies = setCookieLines.filter(line => !line.toLowerCase().includes('secure'));
      const cookieNames = nonSecureCookies.map(line => {
        const match = line.match(/set-cookie:\s*([^=]+)=/i);
        return match ? match[1] : null;
      }).filter(Boolean);
      cookieNames

    extractors:
      - type: regex
        regex:
          - '[a-zA-Z0-9_-]+'
# digest: 490a00463044022034b3c47ea5a6970a301fcdb74f365c6c16346d866be1359b7a1ebfab0a62803702205ac99c8e3c4011f43e8a145f7b6bc3f6fc4ab93849fda3fa593fa297458e77ff:922c64590222798bb761d5b6d8e72950