Fixes the four context-classification edge cases reported in #7086, improving the accuracy of the XSS context analyzer introduced in #7076.
Note: This PR depends on #7076 being merged first, as it fixes issues in the XSS context analyzer code introduced there.
javascript: URIs → ContextScript — Attributes like href="javascript:..." on URL-capable attributes (href, src, action, formaction, etc.) are now correctly classified as ContextScript instead of ContextAttribute.
Non-executable <script> types — <script type="application/json">, <script type="application/ld+json">, <script type="text/template">, etc. are no longer treated as executable script context. Only known executable types (text/javascript, module, etc.) set inScript = true. MIME parameters like ; charset=utf-8 are stripped before matching.
Case-insensitive marker detection — The early-exit check in DetectReflections now uses case-insensitive comparison, matching the behavior of the rest of the detection logic.
srcdoc → ContextHTMLText — <iframe srcdoc="..."> attributes allow full HTML injection and are now classified as ContextHTMLText instead of ContextAttribute.
Word boundary in extractAttrFromRaw — Prevents data-type="application/json" from being matched when searching for the type attribute on <script> tags.
Before (on #7076 branch):
<a href="javascript:CANARY"> → ContextAttribute ❌
<script type="application/json">CANARY → ContextScript ❌
<iframe srcdoc="<b>CANARY</b>"> → ContextAttribute ❌
UPPERCASECANARY → not detected ❌
After (this PR):
<a href="javascript:CANARY"> → ContextScript ✅
<script type="application/json">CANARY → ContextHTMLText ✅
<iframe srcdoc="<b>CANARY</b>"> → ContextHTMLText ✅
UPPERCASECANARY → detected ✅
Test results:
$ go test ./pkg/fuzz/analyzers/xss/ -v -count=1
PASS
ok github.com/projectdiscovery/nuclei/v3/pkg/fuzz/analyzers/xss 0.678s
All 32 tests pass (24 existing + 8 new).
TestDetectReflections_JavascriptURI — href, src, formaction with javascript: URIsTestDetectReflections_ScriptTypeJSON — application/json not treated as executableTestDetectReflections_ScriptTypeLDJSON — application/ld+json not treated as executableTestDetectReflections_ScriptTypeExecutable — text/javascript, module, no-type still workTestDetectReflections_CaseInsensitiveMarker — uppercase marker detectionTestDetectReflections_SrcdocAttribute — srcdoc classified as HTMLTextTestDetectReflections_ScriptTypeWithParams — MIME parameters stripped correctlyTestDetectReflections_DataTypeCollision — data-type does not interfere with typedev branchgo vet, unit tests)/claim #7086
New Features
Improvements
Tests
Eunho Lee (Tony)
@lucky7323
Bishnu Prasad Sahu
@mebishnusahu0595