Blue Team Companion

XSS Generator — Cross-Site Scripting Detection

CSP is usually sold as a prevention control, but its report-uri is a detection feed most teams never wire up. Every blocked injection becomes a structured alert from the browser itself — including DOM-based attacks your server logs cannot see.

Open in Red Team Toolkit — xss
CSP is usually sold as a prevention control, but its report-uri is a detection feed most teams never wire up. Every blocked injection becomes a structured alert from the browser itself — including DOM-based attacks your server logs cannot see.

Telemetry generated

Log sourceField / identifierWhat it shows
Web Access Loguri / request_bodyInjection point for reflected and stored XSS. Script tags, event-handler attributes, and javascript: scheme URIs appear here on the initial request. Stored XSS appears on the write request; subsequent reads that trigger execution do not contain the payload.
CSP report-uri / report-toviolated-directive / blocked-uriViolation reports sent by the BROWSER to your collector endpoint. A genuine structured detection feed that is chronically underused. Every blocked injection — including DOM-based attacks that never reach the server — generates a report with the violated directive, blocked URI, and source file. Wire this to your SIEM.
Proxy / DNS Logdst_host / query_nameExfiltration callback. A successful XSS payload exfiltrates cookies or tokens via fetch(), new Image(), or navigator.sendBeacon() to an attacker-controlled host. The outbound request appears in proxy logs and the DNS resolution appears in DNS query logs.
Application Databasestored_contentFor stored XSS, the persisted payload in the database keeps firing for every viewer until it is removed. The database record is the ground truth for what was injected and when.

Detection rules

Sigma — Webserver XSS Keyword Groups
title: Cross-Site Scripting Patterns in Web Request
id: c3d4e5f6-a7b8-9012-cdef-123456789012
status: experimental
description: >
  Matches normalised web request fields against XSS keyword groups covering
  script tags, event handlers, JavaScript schemes, and exfiltration primitives.
logsource:
  category: webserver
detection:
  tags_group:
    - '<script'
    - '</script>'
    - '<iframe'
    - '<svg'
  handlers_group:
    - 'onerror='
    - 'onload='
    - 'onclick='
    - 'onmouseover='
    - 'ontoggle='
    - 'onanimationstart='
  schemes_group:
    - 'javascript:'
    - 'vbscript:'
  exfil_group:
    - 'document.cookie'
    - 'fetch('
    - 'new Image('
    - 'navigator.sendBeacon'
  condition: tags_group or handlers_group or schemes_group or exfil_group
falsepositives:
  - Rich-text editors submitting legitimate HTML content
  - Authorised penetration testing
level: high
tags:
  - attack.execution
  - attack.t1059.007

Evasion & counters

Evasion

Event-handler payloads that avoid the literal <script> tag (e.g. <img onerror=...>).

Counter

Match the event-handler attribute pattern directly, and deploy CSP so execution is blocked regardless of how the injection is structured. The Suricata rule above covers img, svg, body, iframe, video, audio, object, embed, and details elements.

Evasion

Encoding and HTML entities to hide payload syntax from signature matching.

Counter

Match on normalised fields — Suricata's http.uri and http.request_body sticky buffers decode HTML entities and URL encoding automatically before matching.

Evasion

DOM-based XSS where the payload is processed entirely client-side and never reaches the server.

Counter

Server logs are blind to DOM-based XSS by definition. CSP violation reports and client-side RUM (Real User Monitoring) are the only visibility. This is exactly why wiring up the CSP report feed matters — it is the only detection channel that sees DOM-based attacks.

Evasion

Exfiltrating to a domain that matches a permissive connect-src wildcard (e.g. *.example.com).

Counter

Write CSP with explicit allowlists, never wildcards. A connect-src of 'self' https://api.example.com is far stronger than https://*.example.com, which an attacker can satisfy with a subdomain takeover.

Rule tuning

Preventive control

Context-aware output encoding at the template layer eliminates the vulnerability — encode for HTML context, attribute context, JavaScript context, and URL context separately. A restrictive CSP with no unsafe-inline and an explicit connect-src allowlist contains the damage when encoding fails. HttpOnly cookies remove the most common exfiltration target by making document.cookie return an empty string.

Back to Detection Library