Medium Severity
Suspected Cross-Site Scripting (XSS) found in subject
Description
This rule detects Cross-Site Scripting (XSS) attempts within email subjects. It bypasses messages from highly trusted domains unless they fail authentication. However, the rule remains flexible, triggering even for trusted domains when emails are sent from Google Groups, ensuring thorough protection against potential threats while minimizing false positives.
References
No references.
Sublime Security
Created Feb 13th, 2025 • Last updated Feb 24th, 2025
Feed Source
Sublime Core Feed
Source
type.inbound
// subject contains suspected cross site scripting
and regex.icontains(subject.subject,
'(?:[<]|%3c|\\u003c|\\x3c|&[lg]t;|&n[vw][lg]t;)\/?(?:script(?:\s*/?\s*src\s*=)?|iframe|embed|object|style|form|meta|link|svg|img|audio|video|source|body|input|textarea|select|noscript|/?title|/?textarea|/?style|/?template|/?noembed)',
// constructor chain pattern
'constructor\.constructor|\[\s*constructor\s*\]|\.__proto__|\[constructor\]'
)
// and contains html or url encoded strings, hex escaped strings, opening or closing html tags, or escaped non word characters
and // subject contains common event handlers
regex.icontains(subject.subject,
'\b(?:on(?:abort|blur|change|click|dblclick|error|focus|load|mouse(?:over|out|move|down|up)|key(?:down|up|press)|reset|select|submit|unload)|srcdoc|src\s*=)',
// subject contains javascript funcitons
'\b(?:javascript|eval|settimeout|setinterval|document\.(?:cookie|write|location|createElement|body|appendChild)|fetch|constructor|__proto__|prototype|getScript)\b'
)
and regex.icontains(subject.subject,
// Pattern 1: Quote followed by various special characters in encoded/literal forms:
// - < > angle brackets (%3C, %3E, literal, <, >)
// - quotes (", ')
// - parentheses ((, ))
// - curly braces ({, })
// - square brackets ([, ])
// - equals sign (=)
// - forward/backward slashes (/, \)
// - colon (:)
// - semicolon (;)
'[\x27\x22](?:%3[CE]|[<>]|&(?:lt|gt|quot|apos|[lr](?:par|cub|sqb)|equals|[bs]ol|colon|semi)\x3b)',
// Pattern 2: Encoded/special characters followed by quote
// Same as above but in reverse order - special chars followed by quote
'(?:%3[CE]|[<>]|&(?:lt|gt|quot|apos|[lr](?:par|cub|sqb)|equals|[bs]ol|colon|semi)\x3b)[\x27\x22]',
// Pattern 3: Hexadecimal or decimal HTML entities with semicolon
// e.g., ' (hex) or ' (decimal)
'&#[xX]?[a-f0-9]+;',
// Pattern 4: Raw decimal HTML entities
// e.g., < (without semicolon)
'&#\d+',
// Pattern 5: URL encoded characters
// e.g., %3C for <, %3E for >, %22 for ", %27 for '
'%[a-f0-9]{2}',
// Pattern 6: Unicode/hex escapes
// e.g., \u003C for <, \x3C for
'\\[xXuU][a-f0-9]{4}',
// New patterns for this type of payload
'</[^>]+/[^>]+>', // Matches closing tags with slash delimiters
'//[^"\x27>\s]+', // Matches protocol-relative URLs
'xss\.report', // Specific known XSS domains
'/\*|\*/|\-\->', // comment chars (/*, */, -->)
)
// negate highly trusted sender domains unless they fail DMARC authentication
and (
(
sender.email.domain.root_domain in $high_trust_sender_root_domains
and (
any(distinct(headers.hops, .authentication_results.dmarc is not null),
strings.ilike(.authentication_results.dmarc, "*fail")
)
or (
strings.icontains(sender.display_name, "via")
and any(headers.hops,
any(.fields,
.name == "List-ID"
and strings.ends_with(.value,
strings.concat(sender.email.domain.domain,
">"
)
)
)
)
)
)
)
or sender.email.domain.root_domain not in $high_trust_sender_root_domains
)
Playground
Test against your own EMLs or sample data.