work in innerHTML?","acceptedAnswer":{"@type":"Answer","text":"Modern browsers do not execute script elements inserted via innerHTML for security reasons. Use event handlers like onerror or onload instead."}},{"@type":"Question","name":"What are common DOM XSS sinks?","acceptedAnswer":{"@type":"Answer","text":"Common sinks include innerHTML, outerHTML, document.write, eval, setTimeout, setInterval, and location properties."}},{"@type":"Question","name":"How can I bypass a filter that blocks 'alert'?","acceptedAnswer":{"@type":"Answer","text":"Use alternative functions like prompt, confirm, or use eval(atob('YWxlcnQoMSk=')) to decode Base64-encoded JavaScript."}},{"@type":"Question","name":"Can DOM XSS be exploited without user interaction?","acceptedAnswer":{"@type":"Answer","text":"Yes, if the vulnerable code executes on page load (e.g., from URL hash) or via autofocus events."}},{"@type":"Question","name":"What is the best defense against DOM XSS?","acceptedAnswer":{"@type":"Answer","text":"Avoid using innerHTML with user input. Use textContent or sanitize with DOMPurify. Also implement a strict CSP."}},{"@type":"Question","name":"Is DOM XSS still a problem in modern frameworks?","acceptedAnswer":{"@type":"Answer","text":"Yes, because developers can still use dangerous methods like innerHTML even in React or Angular."}},{"@type":"Question","name":"What tools can detect DOM XSS?","acceptedAnswer":{"@type":"Answer","text":"Burp Suite, OWASP ZAP, and browser developer tools can help. Static analysis tools like ESLint with security plugins also help."}},{"@type":"Question","name":"How do I exfiltrate data with DOM XSS?","acceptedAnswer":{"@type":"Answer","text":"Use fetch or XMLHttpRequest to send data to an attacker-controlled server. Example: "}},{"@type":"Question","name":"What is the role of CSP in preventing DOM XSS?","acceptedAnswer":{"@type":"Answer","text":"CSP can block inline event handlers and scripts, making it harder to execute XSS payloads even if the DOM is vulnerable."}},{"@type":"Question","name":"Can I use DOM XSS to steal CSRF tokens?","acceptedAnswer":{"@type":"Answer","text":"Yes, if the token is in the DOM (e.g., in a meta tag), you can read it with document.querySelector and exfiltrate it."}},{"@type":"Question","name":"What is the difference between innerHTML and textContent?","acceptedAnswer":{"@type":"Answer","text":"innerHTML parses and inserts HTML, while textContent sets the text content safely, escaping HTML special characters."}},{"@type":"Question","name":"Why do some DOM XSS payloads use
tags?","acceptedAnswer":{"@type":"Answer","text":"Because img tags with onerror fire automatically when the image fails to load, providing a way to execute JavaScript without user interaction."}},{"@type":"Question","name":"What is the 'onerror' event handler?","acceptedAnswer":{"@type":"Answer","text":"onerror is triggered when an element (like img) encounters an error during loading. It can be used to execute JavaScript."}},{"@type":"Question","name":"What is the 'onload' event handler?","acceptedAnswer":{"@type":"Answer","text":"onload fires when an element finishes loading. For example,

Loading module…