Issue: #5838
This PR introduces a context-aware XSS analyzer for the fuzzing engine. It detects reflection contexts, selects payloads based on context and available characters, and verifies exploitability to reduce false positives.
[XSS_CANARY] placeholderpkg/fuzz/analyzers/xss/analyzer.goOrchestrates probe, detection, payload selection, and verification. Implements the Analyzer interface with:
ApplyInitialTransformation() — Handles [XSS_CANARY] placeholder replacementAnalyze() — Main flow: send canary → detect contexts → select payloads → verifysendRequest() — HTTP request handling with proper error handling for resp.Body.Close()verifyXSS() — Confirms exploitability by checking context compatibility and encodingpkg/fuzz/analyzers/xss/context_detector.gopkg/fuzz/analyzers/xss/payload_selector.gopkg/fuzz/analyzers/xss/types.goIncludes context/type definitions and analyzer constants:
ContextType enum with 9 context typesReflectionInfo struct with position, context, available charsCharacterSet for tracking < > ' " / \ availabilityDefaultCanary = "xSs9K7j<>'\"/()"AnalyzerName = "xss_context"integration_tests/fuzz/fuzz-xss-context-body.yaml
Tests XSS detection in HTML body context where input reflects inside <div> tags without encoding.
integration_tests/fuzz/fuzz-xss-context-attribute.yaml
Tests XSS detection in HTML attribute context where input reflects inside value="" attributes.
integration_tests/fuzz/fuzz-xss-context-script.yaml
Tests XSS detection in JavaScript context where input reflects inside <script>var x = "..."</script>.
integration_tests/fuzz/fuzz-xss-context-encoded.yaml
Negative test case — verifies analyzer correctly identifies when XSS is not exploitable due to HTML encoding.
cmd/integration-test/fuzz.go
Added 4 test handlers that create vulnerable/safe test servers:
xssContextBodyFuzz — Vulnerable HTML body reflectionxssContextAttributeFuzz — Vulnerable attribute reflectionxssContextScriptFuzz — Vulnerable script context reflectionxssContextEncodedFuzz — Safe (encoded) reflection for negative testingpkg/templates/templates_doc.go
xss_context to valid analyzer names listpkg/fuzz/analyzers/xss/analyzer_test.goComprehensive coverage including:
pkg/fuzz/analyzers/xss/context_detector_test.goCovers:
href, src, action, data, formaction, poster)pkg/fuzz/analyzers/xss/payload_selector_test.goTests:
< encoded> encodedid: xss-context-detection
info:
name: XSS Context Analyzer
author: pdteam
severity: high
http:
method: GET
path:
- "{{BaseURL}}"
fuzzing:
part: query
type: replace
mode: single
fuzz:
- "[XSS_CANARY]"
analyzer:
name: xss_context
parameters:
canary: "xSs9K7j<>'\"/()"
/claim #5838
New Features
Tests
Documentation
Chores
Orbin Sunny
@orbin123
ProjectDiscovery
@projectdiscovery