/claim #7086
Comprehensive fix for all 4 edge cases reported in the XSS context analyzer (#7086), plus additional hardening based on review feedback from CodeRabbit and Neo.
javascript: URIs misclassified as ContextAttributeAttributes like href="javascript:alert(1)" were classified as ContextAttribute instead of ContextScript. Added isJavascriptURI() helper that:
javascript: scheme detection<script> blocks treated as executable<script type="application/json">, <script type="importmap">, <script type="speculationrules">, etc. were classified as ContextScript. Replaced with WHATWG-aligned whitelist of executable JavaScript MIME types. Key details:
type="text/javascript; charset=utf-8" matches correctly)data-type="application/json" false positivesAll marker comparisons are now case-insensitive — both the early guard in Analyze() and DetectReflections() — so server-side casing transforms don’t cause missed detections.
srcdoc attributes treated as simple attribute context<iframe srcdoc="<script>injection</script>"> allows full HTML injection. Now classified as ContextHTMLText.
FuzzGenerated.Value via regex instead of shared AnalyzerParameters map, preventing concurrent request overwritesdata: URIs — text/html, text/javascript, application/javascript, application/xhtml+xml (Neo), image/svg+xmlisExecutableScriptTag strips ;charset=... before comparisondetectAttrQuoting handles whitespace around = and word-boundary disambiguationContextNone reflections66 top-level tests, 144 total test cases (including subtests) — all passing:
$ go test ./pkg/fuzz/analyzers/xss/ -v -count=1
--- PASS: TestDetectReflections_HTMLText
--- PASS: TestDetectReflections_AttributeDoubleQuoted
--- PASS: TestDetectReflections_AttributeSingleQuoted
--- PASS: TestDetectReflections_ScriptBlock
--- PASS: TestDetectReflections_ScriptStringDouble
--- PASS: TestDetectReflections_ScriptStringSingle
--- PASS: TestDetectReflections_ScriptStringBacktick
--- PASS: TestDetectReflections_HTMLComment
--- PASS: TestDetectReflections_StyleBlock
--- PASS: TestDetectReflections_EventHandler
--- PASS: TestDetectReflections_NoReflection
--- PASS: TestDetectReflections_MultipleContexts
--- PASS: TestDetectReflections_Textarea
--- PASS: TestDetectReflections_Title
--- PASS: TestDetectReflections_CaseInsensitive
--- PASS: TestDetectReflections_TagNameReflection
--- PASS: TestDetectReflections_JavascriptURI
--- PASS: TestDetectReflections_JavascriptURISingleQuoted
--- PASS: TestDetectReflections_JavascriptURIMixedCase
--- PASS: TestDetectReflections_JavascriptURILeadingWhitespace
--- PASS: TestDetectReflections_JavascriptURILeadingTab
--- PASS: TestDetectReflections_JavascriptURIInFormaction
--- PASS: TestDetectReflections_NonJavascriptHref
--- PASS: TestDetectReflections_JSONScriptBlock
--- PASS: TestDetectReflections_LDJSONScriptBlock
--- PASS: TestDetectReflections_ImportmapScriptBlock
--- PASS: TestDetectReflections_SpeculationrulesScriptBlock
--- PASS: TestDetectReflections_TextPlainScriptBlock
--- PASS: TestDetectReflections_TextTemplateScriptBlock
--- PASS: TestDetectReflections_ExecutableScriptStillWorks
--- PASS: TestDetectReflections_TextJavascriptType
--- PASS: TestDetectReflections_ModuleScriptType
--- PASS: TestDetectReflections_DataTypeAttrNotConfused
--- PASS: TestDetectReflections_CustomTypeAttrNotConfused
--- PASS: TestDetectReflections_UnknownScriptType
--- PASS: TestDetectReflections_CaseSensitiveMarker_Uppercase
--- PASS: TestDetectReflections_CaseSensitiveMarker_MixedCase
--- PASS: TestDetectReflections_CaseSensitiveMarker_Lowercase
--- PASS: TestDetectReflections_SrcdocAttribute
--- PASS: TestDetectReflections_SrcdocWithScript
--- PASS: TestDetectReflections_DataTextHTMLURI
--- PASS: TestDetectReflections_DataJavascriptURI
--- PASS: TestDetectReflections_DataSVGURI
--- PASS: TestDetectReflections_DataXHTMLURI
--- PASS: TestDetectReflections_DataPlainTextURI
--- PASS: TestBestReflection_Priority
--- PASS: TestBestReflection_SkipsNone
--- PASS: TestBestReflection_AllNone
--- PASS: TestBestReflection_Empty
--- PASS: TestDetectScriptStringContext (5 subtests)
--- PASS: TestIsEventHandler (10 subtests)
--- PASS: TestContextString (8 subtests)
--- PASS: TestSelectPayloads (8 subtests)
--- PASS: TestDetectCharacterSurvival
--- PASS: TestDetectCharacterSurvival_Encoded
--- PASS: TestDetectCharacterSurvival_Independent
--- PASS: TestIsHTMLResponse (5 subtests)
--- PASS: TestHasCSP (3 subtests)
--- PASS: TestIsExecutableScriptTag (21 subtests)
--- PASS: TestIsJavascriptURI (8 subtests)
--- PASS: TestIsDataExecutableURI (9 subtests)
--- PASS: TestDetectAttrQuoting (6 subtests)
PASS
ok github.com/projectdiscovery/nuclei/v3/pkg/fuzz/analyzers/xss 1.567s
Build compiles cleanly with zero errors.
dev branchnavkaran123
@navkaran123
Bishnu Prasad Sahu
@mebishnusahu0595