This vulnerability occurs when a web application fails to properly sanitize or block JavaScript URIs (like 'javascript:') within HTML tag attributes. Attackers can inject malicious code into attributes such as onmouseover, onload, onerror, or style, leading to cross-site scripting (XSS) attacks when the page renders.
This flaw is a specific type of Cross-Site Scripting (XSS) where the injection point is not within the main HTML content, but within an element's attribute values. Unlike standard reflected XSS, the malicious script is often triggered by a user interaction (like moving a mouse) or a page event (like an image failing to load), making it harder to detect during casual testing. Developers might overlook these attributes when implementing input validation or output encoding filters. To prevent this, you must treat all user-supplied data placed into HTML attributes as untrusted. Implement context-sensitive output encoding specifically for HTML attributes before inserting data. Use a reputable security library for this encoding, as different contexts (HTML, JavaScript, CSS) require different escaping rules. Additionally, consider implementing a Content Security Policy (CSP) as a robust defense-in-depth measure to block the execution of inline JavaScript.
Impact: Read Application DataExecute Unauthorized Code or Commands
Strategy: Output Encoding
Strategy: Attack Surface Reduction
Effectiveness: Defense in Depth