Improper Neutralization of Script in Attributes of IMG Tags in a Web Page

Incomplete Variant
Structure: Simple
Description

This vulnerability occurs when a web application fails to properly sanitize or escape script code within the attributes of HTML IMG tags, such as the 'src' attribute.

Extended Description

Attackers can inject malicious scripts (XSS) into seemingly harmless image tag attributes. When a victim's browser loads the compromised page, it processes the tainted attribute and executes the injected code, often without any visible indication to the user. This type of attack exploits the trust a browser has in content served by the application. To prevent it, developers must rigorously validate and encode all user-supplied data before it is inserted into HTML attributes, treating attribute values as untrusted by default.

Common Consequences 1
Scope: ConfidentialityIntegrityAvailability

Impact: Read Application DataExecute Unauthorized Code or Commands

Potential Mitigations 2
Phase: Implementation

Strategy: Output Encoding

Use and specify an output encoding that can be handled by the downstream component that is reading the output. Common encodings include ISO-8859-1, UTF-7, and UTF-8. When an encoding is not specified, a downstream component may choose a different encoding, either by assuming a default encoding or automatically inferring which encoding is being used, which can be erroneous. When the encodings are inconsistent, the downstream component might treat some character or byte sequences as special, even if they are not special in the original encoding. Attackers might then be able to exploit this discrepancy and conduct injection attacks; they even might be able to bypass protection mechanisms that assume the original encoding is also being used by the downstream component. The problem of inconsistent output encodings often arises in web pages. If an encoding is not specified in an HTTP header, web browsers often guess about which encoding is being used. This can open up the browser to subtle XSS attacks.
Phase: Implementation

Strategy: Attack Surface Reduction

To help mitigate XSS attacks against the user's session cookie, set the session cookie to be HttpOnly. In browsers that support the HttpOnly feature (such as more recent versions of Internet Explorer and Firefox), this attribute can prevent the user's session cookie from being accessible to malicious client-side scripts that use document.cookie. This is not a complete solution, since HttpOnly is not supported by all browsers. More importantly, XMLHTTPRequest and other powerful browser technologies provide read access to HTTP headers, including the Set-Cookie header in which the HttpOnly flag is set.

Effectiveness: Defense in Depth

Observed Examples 8
CVE-2006-3211Stored XSS in a guestbook application using a javascript: URI in a bbcode img tag.
CVE-2002-1649javascript URI scheme in IMG tag.
CVE-2002-1803javascript URI scheme in IMG tag.
CVE-2002-1804javascript URI scheme in IMG tag.
CVE-2002-1805javascript URI scheme in IMG tag.
CVE-2002-1806javascript URI scheme in IMG tag.
CVE-2002-1807javascript URI scheme in IMG tag.
CVE-2002-1808javascript URI scheme in IMG tag.
Applicable Platforms
Languages:
Not Language-Specific : Undetermined
Modes of Introduction
Implementation
Taxonomy Mapping
  • PLOVER
  • Software Fault Patterns