"""
NeuroSploit v3 - Comprehensive XSS Validator
Validates XSS with multiple proof techniques beyond alert(1):
- Alert/confirm/prompt popup detection (Playwright)
- Cookie access verification
- DOM modification detection
- Event handler firing confirmation
- CSP analysis for bypass opportunities
- Proof payload generation per context
"""
import re
import json
from dataclasses import dataclass, field
from typing import Dict, List, Optional, Tuple
try:
from core.browser_validator import BrowserValidator, HAS_PLAYWRIGHT
except ImportError:
HAS_PLAYWRIGHT = False
BrowserValidator = None
@dataclass
class XSSProof:
"""Result of comprehensive XSS validation."""
confirmed: bool = False
proof_type: str = "" # "alert", "cookie", "dom", "event", "fetch", "static"
detail: str = ""
payload_used: str = ""
screenshot: str = "" # base64 screenshot if browser available
cookie_accessed: bool = False
dom_modified: bool = False
alert_fired: bool = False
event_fired: bool = False
csp_bypassed: bool = False
confidence: float = 0.0 # 0.0 - 1.0
@dataclass
class CSPAnalysis:
"""CSP header analysis result."""
has_csp: bool = False
raw_policy: str = ""
allows_inline: bool = False
allows_eval: bool = False
has_wildcards: bool = False
nonce_based: bool = False
bypass_possible: bool = False
bypass_techniques: List[str] = field(default_factory=list)
weak_directives: List[str] = field(default_factory=list)
class XSSValidator:
"""Validates XSS with multiple proof techniques.
Goes beyond simple alert(1) detection to prove:
1. JavaScript execution (alert popup via Playwright)
2. Cookie theft capability (document.cookie access)
3. DOM manipulation (innerHTML changes)
4. Event handler execution
5. CSP bypass feasibility
"""
# Proof payloads for different validation goals
PROOF_PAYLOADS = {
"alert": [
"",
"
",
"