<?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=Dimisec</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=Dimisec"/>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php/Special:Contributions/Dimisec"/>
		<updated>2026-04-21T05:03:44Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.27.2</generator>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Content_Security_Policy&amp;diff=169075</id>
		<title>Content Security Policy</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Content_Security_Policy&amp;diff=169075"/>
				<updated>2014-02-27T11:13:50Z</updated>
		
		<summary type="html">&lt;p&gt;Dimisec: fixed a minor typo (proper plural case)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Last revision (mm/dd/yy): '''08/31/2013'''&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
'''CSP''' stands for '''C'''ontent '''S'''ecurity '''P'''olicy. &lt;br /&gt;
&lt;br /&gt;
Is an W3C specification offering the possbility to instruct the client browser from which location and/or which type of resources are allowed to be loaded. To define a loading behavior, the CSP specification use &amp;quot;directive&amp;quot; where a directive defines a loading behavior for a target resource type.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This article is based on version [http://w3c.github.io/webappsec/specs/content-security-policy/csp-specification.dev.html 1.1] of the W3C specification.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Directives can be specified using HTTP response header (a server may send more than one CSP HTTP header field with a given resource representation and a server may send different CSP header field values with different representations of the same resource or with different resources) or HTML Meta tag, the HTTP headers below are defined by the specs:&lt;br /&gt;
* '''Content-Security-Policy''' : Defined by W3C Specs as standard header, used by Chrome version 25 and later, Firefox version 23 and later, Opera version 19 and later.&lt;br /&gt;
* '''X-Content-Security-Policy''' : Used by Firefox until version 23, and Internet Explorer version 10 (which partially implements Content Security Policy).&lt;br /&gt;
* '''X-WebKit-CSP''' : Used by Chrome until version 25&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The supported directives are:&lt;br /&gt;
* '''default-src''' : Define loading policy for all resources type in case of a resource type dedicated directive is not defined (fallback),&lt;br /&gt;
* '''script-src''' :  Define which scripts the protected resource can execute,&lt;br /&gt;
* '''object-src''' :  Define from where the protected resource can load plugins,&lt;br /&gt;
* '''style-src''' : Define which styles (CSS) the user applies to the protected resource,&lt;br /&gt;
* '''img-src''' : Define from where the protected resource can load images,&lt;br /&gt;
* '''media-src''' : Define from where the protected resource can load video and audio,&lt;br /&gt;
* '''frame-src''' : Define from where the protected resource can embed frames,&lt;br /&gt;
* '''font-src''' : Define from where the protected resource can load fonts,&lt;br /&gt;
* '''connect-src''' : Define which URIs the protected resource can load using script interfaces,&lt;br /&gt;
* '''form-action''' : Define which URIs can be used as the action of HTML form elements,&lt;br /&gt;
* '''sandbox''' : Specifies an HTML sandbox policy that the user agent applies to the protected resource,&lt;br /&gt;
* '''script-nonce''' : Define script execution by requiring the presence of the specified nonce on script elements,&lt;br /&gt;
* '''plugin-types''' : Define the set of plugins that can be invoked by the protected resource by limiting the types of resources that can be embedded,&lt;br /&gt;
* '''reflected-xss''' : Instructs a user agent to activate or disactivate any heuristics used to filter or block reflected cross-site scripting attacks, equivalent to the effects of the non-standard X-XSS-Protection header,&lt;br /&gt;
*  '''report-uri''' : Specifies a URI to which the user agent sends reports about policy violation&lt;br /&gt;
&lt;br /&gt;
An introduction to CSP is available on [http://www.html5rocks.com/en/tutorials/security/content-security-policy/ HTML5Rocks].  The browser support is shown on http://caniuse.com/#feat=contentsecuritypolicy&lt;br /&gt;
&lt;br /&gt;
== Risk ==&lt;br /&gt;
The risk with CSP can have 2 main sources:&lt;br /&gt;
# Policies misconfiguration,&lt;br /&gt;
# Too permissive policies.&lt;br /&gt;
&lt;br /&gt;
== Countermeasure ==&lt;br /&gt;
This article will focus on providing an sample implementation of a JEE Web Filter in order to apply a set of CSP policies on all HTTP response returned by server. &lt;br /&gt;
&lt;br /&gt;
The policies will instruct the browser to have the loading behavior below using all HTTP headers defined in W3C Specs:&lt;br /&gt;
* Explicit loading definition of each resource type,&lt;br /&gt;
* Resources are loaded only from source domain,&lt;br /&gt;
* Inline style is not allowed,&lt;br /&gt;
* For JavaScript:&lt;br /&gt;
** ''Inline script'' will be allowed because inline scripting is commonly used (can be disabled if target site does not use this type of scripting),&lt;br /&gt;
** ''eval()'' function will be allowed in order to not break use of popular JavaScript libraries (ex: JQuery, JQueryUI, Sencha, ...) because they use eval() function (it was the case last time I have checked the source code from CDN ;) ),&lt;br /&gt;
* Generation of a random not guessable script nonce to use into all script tags,&lt;br /&gt;
* Plugin types only allow PDF and Flash,&lt;br /&gt;
* No font loading (configurable),&lt;br /&gt;
* No Audio / Video loading (configurable),&lt;br /&gt;
* Enable browser XSS filtering feature.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:navy&amp;quot;&amp;gt;&lt;br /&gt;
The support for CSP directives is not the same level in major browsers (Firefox/Chrome/IE). It's recommanded to check the support &lt;br /&gt;
provided by target browsers  (using site provided in link section of this article) in order to configure CSP policies. The sample &lt;br /&gt;
below try to provide a set of policies from which your can add policies specific to your application context.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''This implementation provide an option to add CSP directives used by Firefox (Mozilla CSP directives).''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.security.MessageDigest;&lt;br /&gt;
import java.security.NoSuchAlgorithmException;&lt;br /&gt;
import java.security.SecureRandom;&lt;br /&gt;
import java.util.ArrayList;&lt;br /&gt;
import java.util.List;&lt;br /&gt;
&lt;br /&gt;
import javax.servlet.Filter;&lt;br /&gt;
import javax.servlet.FilterChain;&lt;br /&gt;
import javax.servlet.FilterConfig;&lt;br /&gt;
import javax.servlet.ServletException;&lt;br /&gt;
import javax.servlet.ServletRequest;&lt;br /&gt;
import javax.servlet.ServletResponse;&lt;br /&gt;
import javax.servlet.annotation.WebFilter;&lt;br /&gt;
import javax.servlet.http.HttpServletRequest;&lt;br /&gt;
import javax.servlet.http.HttpServletResponse;&lt;br /&gt;
&lt;br /&gt;
import org.apache.commons.codec.binary.Hex;&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * Sample filter implementation to define a set of Content Security Policies.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 * This implementation has a dependency on Commons Codec API.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 * This filter set CSP policies using all HTTP headers defined into W3C specification.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &amp;lt;br/&amp;gt;&lt;br /&gt;
 * This implementation is oriented to be easily understandable and easily adapted.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
@WebFilter(&amp;quot;/*&amp;quot;)&lt;br /&gt;
public class CSPPoliciesApplier implements Filter {&lt;br /&gt;
&lt;br /&gt;
	/** Configuration member to specify if web app use web fonts */&lt;br /&gt;
	public static final boolean APP_USE_WEBFONTS = false;&lt;br /&gt;
&lt;br /&gt;
	/** Configuration member to specify if web app use videos or audios */&lt;br /&gt;
	public static final boolean APP_USE_AUDIOS_OR_VIDEOS = false;&lt;br /&gt;
&lt;br /&gt;
	/** Configuration member to specify if filter must add CSP directive used by Mozilla (Firefox) */&lt;br /&gt;
	public static final boolean INCLUDE_MOZILLA_CSP_DIRECTIVES = true;&lt;br /&gt;
&lt;br /&gt;
	/** Filter configuration */&lt;br /&gt;
	@SuppressWarnings(&amp;quot;unused&amp;quot;)&lt;br /&gt;
	private FilterConfig filterConfig = null;&lt;br /&gt;
&lt;br /&gt;
	/** List CSP HTTP Headers */&lt;br /&gt;
	private List&amp;lt;String&amp;gt; cspHeaders = new ArrayList&amp;lt;String&amp;gt;();&lt;br /&gt;
&lt;br /&gt;
	/** Collection of CSP polcies that will be applied */&lt;br /&gt;
	private String policies = null;&lt;br /&gt;
&lt;br /&gt;
	/** Used for Script Nonce */&lt;br /&gt;
	private SecureRandom prng = null;&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Used to prepare (one time for all) set of CSP policies that will be applied on each HTTP response.&lt;br /&gt;
	 * &lt;br /&gt;
	 * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)&lt;br /&gt;
	 */&lt;br /&gt;
	@Override&lt;br /&gt;
	public void init(FilterConfig fConfig) throws ServletException {&lt;br /&gt;
		// Get filter configuration&lt;br /&gt;
		this.filterConfig = fConfig;&lt;br /&gt;
&lt;br /&gt;
		// Init secure random&lt;br /&gt;
		try {&lt;br /&gt;
			this.prng = SecureRandom.getInstance(&amp;quot;SHA1PRNG&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		catch (NoSuchAlgorithmException e) {&lt;br /&gt;
			throw new ServletException(e);&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		// Define list of CSP HTTP Headers&lt;br /&gt;
		this.cspHeaders.add(&amp;quot;Content-Security-Policy&amp;quot;);&lt;br /&gt;
		this.cspHeaders.add(&amp;quot;X-Content-Security-Policy&amp;quot;);&lt;br /&gt;
		this.cspHeaders.add(&amp;quot;X-WebKit-CSP&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
		// Define CSP policies&lt;br /&gt;
		// Loading policies for Frame and Sandboxing will be dynamically defined : We need to know if context use Frame&lt;br /&gt;
		List&amp;lt;String&amp;gt; cspPolicies = new ArrayList&amp;lt;String&amp;gt;();&lt;br /&gt;
		String originLocationRef = &amp;quot;'self'&amp;quot;;&lt;br /&gt;
		// --Disable default source in order to avoid browser fallback loading using 'default-src' locations&lt;br /&gt;
		cspPolicies.add(&amp;quot;default-src 'none'&amp;quot;);&lt;br /&gt;
		// --Define loading policies for Scripts&lt;br /&gt;
		cspPolicies.add(&amp;quot;script-src &amp;quot; + originLocationRef + &amp;quot; 'unsafe-inline' 'unsafe-eval'&amp;quot;);&lt;br /&gt;
		if (INCLUDE_MOZILLA_CSP_DIRECTIVES) {&lt;br /&gt;
			cspPolicies.add(&amp;quot;options inline-script eval-script&amp;quot;);&lt;br /&gt;
			cspPolicies.add(&amp;quot;xhr-src 'self'&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		// --Define loading policies for Plugins&lt;br /&gt;
		cspPolicies.add(&amp;quot;object-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Styles (CSS)&lt;br /&gt;
		cspPolicies.add(&amp;quot;style-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Images&lt;br /&gt;
		cspPolicies.add(&amp;quot;img-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Form&lt;br /&gt;
		cspPolicies.add(&amp;quot;form-action &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Audios/Videos&lt;br /&gt;
		if (APP_USE_AUDIOS_OR_VIDEOS) {&lt;br /&gt;
			cspPolicies.add(&amp;quot;media-src &amp;quot; + originLocationRef);&lt;br /&gt;
		}&lt;br /&gt;
		// --Define loading policies for Fonts&lt;br /&gt;
		if (APP_USE_WEBFONTS) {&lt;br /&gt;
			cspPolicies.add(&amp;quot;font-src &amp;quot; + originLocationRef);&lt;br /&gt;
		}&lt;br /&gt;
		// --Define loading policies for Connection&lt;br /&gt;
		cspPolicies.add(&amp;quot;connect-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Plugins Types&lt;br /&gt;
		cspPolicies.add(&amp;quot;plugin-types application/pdf application/x-shockwave-flash&amp;quot;);&lt;br /&gt;
		// --Define browser XSS filtering feature running mode&lt;br /&gt;
		cspPolicies.add(&amp;quot;reflected-xss block&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
		// Target formating&lt;br /&gt;
		this.policies = cspPolicies.toString().replaceAll(&amp;quot;(\\[|\\])&amp;quot;, &amp;quot;&amp;quot;).replaceAll(&amp;quot;,&amp;quot;, &amp;quot;;&amp;quot;).trim();&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Add CSP policies on each HTTP response.&lt;br /&gt;
	 * &lt;br /&gt;
	 * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)&lt;br /&gt;
	 */&lt;br /&gt;
	@Override&lt;br /&gt;
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain fchain) throws IOException, ServletException {&lt;br /&gt;
		HttpServletRequest httpRequest = ((HttpServletRequest) request);&lt;br /&gt;
		HttpServletResponse httpResponse = ((HttpServletResponse) response);&lt;br /&gt;
&lt;br /&gt;
		/* Step 1 : Detect if target resource is a Frame */&lt;br /&gt;
		// Customize here according to your context...&lt;br /&gt;
		boolean isFrame = true;&lt;br /&gt;
&lt;br /&gt;
		/* Step 2 : Add CSP policies to HTTP response */&lt;br /&gt;
		StringBuilder policiesBuffer = new StringBuilder(this.policies);&lt;br /&gt;
&lt;br /&gt;
		// If resource is a frame add Frame/Sandbox CSP policy&lt;br /&gt;
		if (isFrame) {&lt;br /&gt;
			// Frame + Sandbox : Here sandbox allow nothing, customize sandbox options depending on your app....&lt;br /&gt;
			policiesBuffer.append(&amp;quot;;&amp;quot;).append(&amp;quot;frame-src 'self';sandbox&amp;quot;);&lt;br /&gt;
			if (INCLUDE_MOZILLA_CSP_DIRECTIVES) {&lt;br /&gt;
				policiesBuffer.append(&amp;quot;;&amp;quot;).append(&amp;quot;frame-ancestors 'self'&amp;quot;);&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		// Add Script Nonce CSP Policy&lt;br /&gt;
		// --Generate a random number&lt;br /&gt;
		String randomNum = new Integer(this.prng.nextInt()).toString();&lt;br /&gt;
		// --Get its digest&lt;br /&gt;
		MessageDigest sha;&lt;br /&gt;
		try {&lt;br /&gt;
			sha = MessageDigest.getInstance(&amp;quot;SHA-1&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		catch (NoSuchAlgorithmException e) {&lt;br /&gt;
			throw new ServletException(e);&lt;br /&gt;
		}&lt;br /&gt;
		byte[] digest = sha.digest(randomNum.getBytes());&lt;br /&gt;
		// --Encode it into HEXA&lt;br /&gt;
		String scriptNonce = Hex.encodeHexString(digest);&lt;br /&gt;
		policiesBuffer.append(&amp;quot;;&amp;quot;).append(&amp;quot;script-nonce &amp;quot;).append(scriptNonce);&lt;br /&gt;
		// --Made available script nonce in view app layer&lt;br /&gt;
		httpRequest.setAttribute(&amp;quot;CSP_SCRIPT_NONCE&amp;quot;, scriptNonce);&lt;br /&gt;
&lt;br /&gt;
		// Add policies to all HTTP headers&lt;br /&gt;
		for (String header : this.cspHeaders) {&lt;br /&gt;
			httpResponse.setHeader(header, policiesBuffer.toString());&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		/* Step 3 : Let request continue chain filter */&lt;br /&gt;
		fchain.doFilter(request, response);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * {@inheritDoc}&lt;br /&gt;
	 * &lt;br /&gt;
	 * @see javax.servlet.Filter#destroy()&lt;br /&gt;
	 */&lt;br /&gt;
	@Override&lt;br /&gt;
	public void destroy() {&lt;br /&gt;
		// Not used&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
[[Automated Audit using w3af|w3af]] audit tools (http://w3af.org) contain [https://github.com/andresriancho/w3af/blob/master/plugins/grep/csp.py plugin] to automatically audit web application to check if they correctly implement CSP policies. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:#088A08&amp;quot;&amp;gt;&lt;br /&gt;
It's very useful to include this type of tools into a web application development process in order to &lt;br /&gt;
perform a regular automatic first level check (do not replace an manual audit and manual audit must be also conducted regularly).&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can also use  [https://www.oxdef.info/csp-tester CSP Tester (browser extension)] to build and test the policy for your web application.&lt;br /&gt;
&lt;br /&gt;
== Information links ==&lt;br /&gt;
* W3C Specifications: CSP 1.0  - http://www.w3.org/TR/CSP, CSP 1.1 - http://w3c.github.io/webappsec/specs/content-security-policy/csp-specification.dev.html&lt;br /&gt;
* Introduction to CSP: http://www.html5rocks.com/en/tutorials/security/content-security-policy&lt;br /&gt;
* CSP browser support: http://caniuse.com/#feat=contentsecuritypolicy&lt;br /&gt;
* CSP readiness browser testing: http://erlend.oftedal.no/blog/csp/readiness/&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP Java Project]]&lt;br /&gt;
[[Category: Injection]]&lt;br /&gt;
[[Category:Attack]]&lt;br /&gt;
[[Category:Injection Attack]]&lt;/div&gt;</summary>
		<author><name>Dimisec</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Content_Security_Policy&amp;diff=169071</id>
		<title>Content Security Policy</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Content_Security_Policy&amp;diff=169071"/>
				<updated>2014-02-27T11:11:19Z</updated>
		
		<summary type="html">&lt;p&gt;Dimisec: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Last revision (mm/dd/yy): '''08/31/2013'''&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
'''CSP''' stands for '''C'''ontent '''S'''ecurity '''P'''olicy. &lt;br /&gt;
&lt;br /&gt;
Is an W3C specification offering the possbility to instruct the client browser from which location and/or which type of resources are allowed to be loaded. To define a loading behavior, the CSP specification use &amp;quot;directive&amp;quot; where a directive defines a loading behavior for a target resource type.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This article is based on version [http://w3c.github.io/webappsec/specs/content-security-policy/csp-specification.dev.html 1.1] of the W3C specification.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Directives can be specified using HTTP response header (a server may send more than one CSP HTTP header field with a given resource representation and a server may send different CSP header field values with different representations of the same resource or with different resources) or HTML Meta tag, the HTTP headers below are defined by the specs:&lt;br /&gt;
* '''Content-Security-Policy''' : Defined by W3C Specs as standard header, used by Chrome version 25 and later, Firefox version 23 and later, Opera version 19 and later.&lt;br /&gt;
* '''X-Content-Security-Policy''' : Used by Firefox until version 23, and Internet Explorer version 10 (which partially implements Content Security Policy).&lt;br /&gt;
* '''X-WebKit-CSP''' : Used by Chrome until version 25&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The supported directives are:&lt;br /&gt;
* '''default-src''' : Define loading policy for all resources type in case of a resource type dedicated directive is not defined (fallback),&lt;br /&gt;
* '''script-src''' :  Define which scripts the protected resource can execute,&lt;br /&gt;
* '''object-src''' :  Define from where the protected resource can load plugins,&lt;br /&gt;
* '''style-src''' : Define which styles (CSS) the user applies to the protected resource,&lt;br /&gt;
* '''img-src''' : Define from where the protected resource can load images,&lt;br /&gt;
* '''media-src''' : Define from where the protected resource can load video and audio,&lt;br /&gt;
* '''frame-src''' : Define from where the protected resource can embed frames,&lt;br /&gt;
* '''font-src''' : Define from where the protected resource can load fonts,&lt;br /&gt;
* '''connect-src''' : Define which URIs the protected resource can load using script interfaces,&lt;br /&gt;
* '''form-action''' : Define which URIs can be used as the action of HTML form elements,&lt;br /&gt;
* '''sandbox''' : Specifies an HTML sandbox policy that the user agent applies to the protected resource,&lt;br /&gt;
* '''script-nonce''' : Define script execution by requiring the presence of the specified nonce on script elements,&lt;br /&gt;
* '''plugin-types''' : Define the set of plugins that can be invoked by the protected resource by limiting the types of resources that can be embedded,&lt;br /&gt;
* '''reflected-xss''' : Instructs a user agent to activate or disactivate any heuristics used to filter or block reflected cross-site scripting attacks, equivalent to the effects of the non-standard X-XSS-Protection header,&lt;br /&gt;
*  '''report-uri''' : Specifies a URI to which the user agent sends reports about policy violation&lt;br /&gt;
&lt;br /&gt;
An introduction to CSP is available on [http://www.html5rocks.com/en/tutorials/security/content-security-policy/ HTML5Rocks].  The browser support is shown on http://caniuse.com/#feat=contentsecuritypolicy&lt;br /&gt;
&lt;br /&gt;
== Risk ==&lt;br /&gt;
The risk with CSP can have 2 main sources:&lt;br /&gt;
# Policies misconfiguration,&lt;br /&gt;
# Too permissive policies.&lt;br /&gt;
&lt;br /&gt;
== Countermeasure ==&lt;br /&gt;
This article will focus on providing an sample implementation of a JEE Web Filter in order to apply a set of CSP policies on all HTTP response returned by server. &lt;br /&gt;
&lt;br /&gt;
The policies will instruct the browser to have the loading behavior below using all HTTP headers defined in W3C Specs:&lt;br /&gt;
* Explicit loading definition of each resource type,&lt;br /&gt;
* Resources are loaded only from source domain,&lt;br /&gt;
* Inline style is not allowed,&lt;br /&gt;
* For JavaScript:&lt;br /&gt;
** ''Inline script'' will be allowed because inline scripting is commonly used (can be disabled if target site does not use this type of scripting),&lt;br /&gt;
** ''eval()'' function will be allowed in order to not break use of popular JavaScript libraries (ex: JQuery, JQueryUI, Sencha, ...) because they use eval() function (it was the case last time I have checked the source code from CDN ;) ),&lt;br /&gt;
* Generation of a random not guessable script nonce to use into all script tag,&lt;br /&gt;
* Plugin types only allow PDF and Flash,&lt;br /&gt;
* No font loading (configurable),&lt;br /&gt;
* No Audio / Video loading (configurable),&lt;br /&gt;
* Enable browser XSS filtering feature.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:navy&amp;quot;&amp;gt;&lt;br /&gt;
The support for CSP directives is not the same level in major browsers (Firefox/Chrome/IE). It's recommanded to check the support &lt;br /&gt;
provided by target browsers  (using site provided in link section of this article) in order to configure CSP policies. The sample &lt;br /&gt;
below try to provide a set of policies from which your can add policies specific to your application context.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''This implementation provide an option to add CSP directives used by Firefox (Mozilla CSP directives).''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.security.MessageDigest;&lt;br /&gt;
import java.security.NoSuchAlgorithmException;&lt;br /&gt;
import java.security.SecureRandom;&lt;br /&gt;
import java.util.ArrayList;&lt;br /&gt;
import java.util.List;&lt;br /&gt;
&lt;br /&gt;
import javax.servlet.Filter;&lt;br /&gt;
import javax.servlet.FilterChain;&lt;br /&gt;
import javax.servlet.FilterConfig;&lt;br /&gt;
import javax.servlet.ServletException;&lt;br /&gt;
import javax.servlet.ServletRequest;&lt;br /&gt;
import javax.servlet.ServletResponse;&lt;br /&gt;
import javax.servlet.annotation.WebFilter;&lt;br /&gt;
import javax.servlet.http.HttpServletRequest;&lt;br /&gt;
import javax.servlet.http.HttpServletResponse;&lt;br /&gt;
&lt;br /&gt;
import org.apache.commons.codec.binary.Hex;&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * Sample filter implementation to define a set of Content Security Policies.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 * This implementation has a dependency on Commons Codec API.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 * This filter set CSP policies using all HTTP headers defined into W3C specification.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &amp;lt;br/&amp;gt;&lt;br /&gt;
 * This implementation is oriented to be easily understandable and easily adapted.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
@WebFilter(&amp;quot;/*&amp;quot;)&lt;br /&gt;
public class CSPPoliciesApplier implements Filter {&lt;br /&gt;
&lt;br /&gt;
	/** Configuration member to specify if web app use web fonts */&lt;br /&gt;
	public static final boolean APP_USE_WEBFONTS = false;&lt;br /&gt;
&lt;br /&gt;
	/** Configuration member to specify if web app use videos or audios */&lt;br /&gt;
	public static final boolean APP_USE_AUDIOS_OR_VIDEOS = false;&lt;br /&gt;
&lt;br /&gt;
	/** Configuration member to specify if filter must add CSP directive used by Mozilla (Firefox) */&lt;br /&gt;
	public static final boolean INCLUDE_MOZILLA_CSP_DIRECTIVES = true;&lt;br /&gt;
&lt;br /&gt;
	/** Filter configuration */&lt;br /&gt;
	@SuppressWarnings(&amp;quot;unused&amp;quot;)&lt;br /&gt;
	private FilterConfig filterConfig = null;&lt;br /&gt;
&lt;br /&gt;
	/** List CSP HTTP Headers */&lt;br /&gt;
	private List&amp;lt;String&amp;gt; cspHeaders = new ArrayList&amp;lt;String&amp;gt;();&lt;br /&gt;
&lt;br /&gt;
	/** Collection of CSP polcies that will be applied */&lt;br /&gt;
	private String policies = null;&lt;br /&gt;
&lt;br /&gt;
	/** Used for Script Nonce */&lt;br /&gt;
	private SecureRandom prng = null;&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Used to prepare (one time for all) set of CSP policies that will be applied on each HTTP response.&lt;br /&gt;
	 * &lt;br /&gt;
	 * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)&lt;br /&gt;
	 */&lt;br /&gt;
	@Override&lt;br /&gt;
	public void init(FilterConfig fConfig) throws ServletException {&lt;br /&gt;
		// Get filter configuration&lt;br /&gt;
		this.filterConfig = fConfig;&lt;br /&gt;
&lt;br /&gt;
		// Init secure random&lt;br /&gt;
		try {&lt;br /&gt;
			this.prng = SecureRandom.getInstance(&amp;quot;SHA1PRNG&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		catch (NoSuchAlgorithmException e) {&lt;br /&gt;
			throw new ServletException(e);&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		// Define list of CSP HTTP Headers&lt;br /&gt;
		this.cspHeaders.add(&amp;quot;Content-Security-Policy&amp;quot;);&lt;br /&gt;
		this.cspHeaders.add(&amp;quot;X-Content-Security-Policy&amp;quot;);&lt;br /&gt;
		this.cspHeaders.add(&amp;quot;X-WebKit-CSP&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
		// Define CSP policies&lt;br /&gt;
		// Loading policies for Frame and Sandboxing will be dynamically defined : We need to know if context use Frame&lt;br /&gt;
		List&amp;lt;String&amp;gt; cspPolicies = new ArrayList&amp;lt;String&amp;gt;();&lt;br /&gt;
		String originLocationRef = &amp;quot;'self'&amp;quot;;&lt;br /&gt;
		// --Disable default source in order to avoid browser fallback loading using 'default-src' locations&lt;br /&gt;
		cspPolicies.add(&amp;quot;default-src 'none'&amp;quot;);&lt;br /&gt;
		// --Define loading policies for Scripts&lt;br /&gt;
		cspPolicies.add(&amp;quot;script-src &amp;quot; + originLocationRef + &amp;quot; 'unsafe-inline' 'unsafe-eval'&amp;quot;);&lt;br /&gt;
		if (INCLUDE_MOZILLA_CSP_DIRECTIVES) {&lt;br /&gt;
			cspPolicies.add(&amp;quot;options inline-script eval-script&amp;quot;);&lt;br /&gt;
			cspPolicies.add(&amp;quot;xhr-src 'self'&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		// --Define loading policies for Plugins&lt;br /&gt;
		cspPolicies.add(&amp;quot;object-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Styles (CSS)&lt;br /&gt;
		cspPolicies.add(&amp;quot;style-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Images&lt;br /&gt;
		cspPolicies.add(&amp;quot;img-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Form&lt;br /&gt;
		cspPolicies.add(&amp;quot;form-action &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Audios/Videos&lt;br /&gt;
		if (APP_USE_AUDIOS_OR_VIDEOS) {&lt;br /&gt;
			cspPolicies.add(&amp;quot;media-src &amp;quot; + originLocationRef);&lt;br /&gt;
		}&lt;br /&gt;
		// --Define loading policies for Fonts&lt;br /&gt;
		if (APP_USE_WEBFONTS) {&lt;br /&gt;
			cspPolicies.add(&amp;quot;font-src &amp;quot; + originLocationRef);&lt;br /&gt;
		}&lt;br /&gt;
		// --Define loading policies for Connection&lt;br /&gt;
		cspPolicies.add(&amp;quot;connect-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Plugins Types&lt;br /&gt;
		cspPolicies.add(&amp;quot;plugin-types application/pdf application/x-shockwave-flash&amp;quot;);&lt;br /&gt;
		// --Define browser XSS filtering feature running mode&lt;br /&gt;
		cspPolicies.add(&amp;quot;reflected-xss block&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
		// Target formating&lt;br /&gt;
		this.policies = cspPolicies.toString().replaceAll(&amp;quot;(\\[|\\])&amp;quot;, &amp;quot;&amp;quot;).replaceAll(&amp;quot;,&amp;quot;, &amp;quot;;&amp;quot;).trim();&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Add CSP policies on each HTTP response.&lt;br /&gt;
	 * &lt;br /&gt;
	 * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)&lt;br /&gt;
	 */&lt;br /&gt;
	@Override&lt;br /&gt;
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain fchain) throws IOException, ServletException {&lt;br /&gt;
		HttpServletRequest httpRequest = ((HttpServletRequest) request);&lt;br /&gt;
		HttpServletResponse httpResponse = ((HttpServletResponse) response);&lt;br /&gt;
&lt;br /&gt;
		/* Step 1 : Detect if target resource is a Frame */&lt;br /&gt;
		// Customize here according to your context...&lt;br /&gt;
		boolean isFrame = true;&lt;br /&gt;
&lt;br /&gt;
		/* Step 2 : Add CSP policies to HTTP response */&lt;br /&gt;
		StringBuilder policiesBuffer = new StringBuilder(this.policies);&lt;br /&gt;
&lt;br /&gt;
		// If resource is a frame add Frame/Sandbox CSP policy&lt;br /&gt;
		if (isFrame) {&lt;br /&gt;
			// Frame + Sandbox : Here sandbox allow nothing, customize sandbox options depending on your app....&lt;br /&gt;
			policiesBuffer.append(&amp;quot;;&amp;quot;).append(&amp;quot;frame-src 'self';sandbox&amp;quot;);&lt;br /&gt;
			if (INCLUDE_MOZILLA_CSP_DIRECTIVES) {&lt;br /&gt;
				policiesBuffer.append(&amp;quot;;&amp;quot;).append(&amp;quot;frame-ancestors 'self'&amp;quot;);&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		// Add Script Nonce CSP Policy&lt;br /&gt;
		// --Generate a random number&lt;br /&gt;
		String randomNum = new Integer(this.prng.nextInt()).toString();&lt;br /&gt;
		// --Get its digest&lt;br /&gt;
		MessageDigest sha;&lt;br /&gt;
		try {&lt;br /&gt;
			sha = MessageDigest.getInstance(&amp;quot;SHA-1&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		catch (NoSuchAlgorithmException e) {&lt;br /&gt;
			throw new ServletException(e);&lt;br /&gt;
		}&lt;br /&gt;
		byte[] digest = sha.digest(randomNum.getBytes());&lt;br /&gt;
		// --Encode it into HEXA&lt;br /&gt;
		String scriptNonce = Hex.encodeHexString(digest);&lt;br /&gt;
		policiesBuffer.append(&amp;quot;;&amp;quot;).append(&amp;quot;script-nonce &amp;quot;).append(scriptNonce);&lt;br /&gt;
		// --Made available script nonce in view app layer&lt;br /&gt;
		httpRequest.setAttribute(&amp;quot;CSP_SCRIPT_NONCE&amp;quot;, scriptNonce);&lt;br /&gt;
&lt;br /&gt;
		// Add policies to all HTTP headers&lt;br /&gt;
		for (String header : this.cspHeaders) {&lt;br /&gt;
			httpResponse.setHeader(header, policiesBuffer.toString());&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		/* Step 3 : Let request continue chain filter */&lt;br /&gt;
		fchain.doFilter(request, response);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * {@inheritDoc}&lt;br /&gt;
	 * &lt;br /&gt;
	 * @see javax.servlet.Filter#destroy()&lt;br /&gt;
	 */&lt;br /&gt;
	@Override&lt;br /&gt;
	public void destroy() {&lt;br /&gt;
		// Not used&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
[[Automated Audit using w3af|w3af]] audit tools (http://w3af.org) contain [https://github.com/andresriancho/w3af/blob/master/plugins/grep/csp.py plugin] to automatically audit web application to check if they correctly implement CSP policies. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:#088A08&amp;quot;&amp;gt;&lt;br /&gt;
It's very useful to include this type of tools into a web application development process in order to &lt;br /&gt;
perform a regular automatic first level check (do not replace an manual audit and manual audit must be also conducted regularly).&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can also use  [https://www.oxdef.info/csp-tester CSP Tester (browser extension)] to build and test the policy for your web application.&lt;br /&gt;
&lt;br /&gt;
== Information links ==&lt;br /&gt;
* W3C Specifications: CSP 1.0  - http://www.w3.org/TR/CSP, CSP 1.1 - http://w3c.github.io/webappsec/specs/content-security-policy/csp-specification.dev.html&lt;br /&gt;
* Introduction to CSP: http://www.html5rocks.com/en/tutorials/security/content-security-policy&lt;br /&gt;
* CSP browser support: http://caniuse.com/#feat=contentsecuritypolicy&lt;br /&gt;
* CSP readiness browser testing: http://erlend.oftedal.no/blog/csp/readiness/&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP Java Project]]&lt;br /&gt;
[[Category: Injection]]&lt;br /&gt;
[[Category:Attack]]&lt;br /&gt;
[[Category:Injection Attack]]&lt;/div&gt;</summary>
		<author><name>Dimisec</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Content_Security_Policy&amp;diff=169069</id>
		<title>Content Security Policy</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Content_Security_Policy&amp;diff=169069"/>
				<updated>2014-02-27T11:10:14Z</updated>
		
		<summary type="html">&lt;p&gt;Dimisec: fixed a typo&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Last revision (mm/dd/yy): '''08/31/2013'''&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
'''CSP''' stands for '''C'''ontent '''S'''ecurity '''P'''olicy. &lt;br /&gt;
&lt;br /&gt;
Is an W3C specification offering the possbility to instruct the client browser from which location and/or which type of resources are allowed to be loaded. To define a loading behavior, the CSP specification use &amp;quot;directive&amp;quot; where a directive defines a loading behavior for a target resource type.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This article is based on version [http://w3c.github.io/webappsec/specs/content-security-policy/csp-specification.dev.html 1.1] of the W3C specification.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Directives can be specified using HTTP response header (a server may send more than one CSP HTTP header field with a given resource representation and a server may send different CSP header field values with different representations of the same resource or with different resources) or HTML Meta tag, the HTTP headers below are defined by the specs:&lt;br /&gt;
* '''Content-Security-Policy''' : Defined by W3C Specs as standard header, used by Chrome version 25 and later, Firefox version 23 and later, Opera version 19 and later.&lt;br /&gt;
* '''X-Content-Security-Policy''' : Used by Firefox until version 23, and Internet Explorer version 10 (which partially implements Content Security Policy).&lt;br /&gt;
* '''X-WebKit-CSP''' : Used by Chrome until version 25&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The supported directives are:&lt;br /&gt;
* '''default-src''' : Define loading policy for all resources type in case of a resource type dedicated directive is not defined (fallback),&lt;br /&gt;
* '''script-src''' :  Define which scripts the protected resource can execute,&lt;br /&gt;
* '''object-src''' :  Define from where the protected resource can load plugins,&lt;br /&gt;
* '''style-src''' : Define which styles (CSS) the user applies to the protected resource,&lt;br /&gt;
* '''img-src''' : Define from where the protected resource can load images,&lt;br /&gt;
* '''media-src''' : Define from where the protected resource can load video and audio,&lt;br /&gt;
* '''frame-src''' : Define from where the protected resource can embed frames,&lt;br /&gt;
* '''font-src''' : Define from where the protected resource can load fonts,&lt;br /&gt;
* '''connect-src''' : Define which URIs the protected resource can load using script interfaces,&lt;br /&gt;
* '''form-action''' : Define which URIs can be used as the action of HTML form elements,&lt;br /&gt;
* '''sandbox''' : Specifies an HTML sandbox policy that the user agent applies to the protected resource,&lt;br /&gt;
* '''script-nonce''' : Define script execution by requiring the presence of the specified nonce on script elements,&lt;br /&gt;
* '''plugin-types''' : Define the set of plugins that can be invoked by the protected resource by limiting the types of resources that can be embedded,&lt;br /&gt;
* '''reflected-xss''' : Instructs a user agent to activate or disactivate any heuristics used to filter or block reflected cross-site scripting attacks, equivalent to the effects of the non-standard X-XSS-Protection header,&lt;br /&gt;
*  '''report-uri''' : Specifies a URI to which the user agent sends reports about policy violation&lt;br /&gt;
&lt;br /&gt;
An introduction to CSP is available on [http://www.html5rocks.com/en/tutorials/security/content-security-policy/ HTML5Rocks].  The browser support is shown on http://caniuse.com/#feat=contentsecuritypolicy&lt;br /&gt;
&lt;br /&gt;
== Risk ==&lt;br /&gt;
The risk with CSP can have 2 main sources:&lt;br /&gt;
# Policies misconfiguration,&lt;br /&gt;
# Too permissive policies.&lt;br /&gt;
&lt;br /&gt;
== Countermeasure ==&lt;br /&gt;
This article will focus on providing an sample implementation of a JEE Web Filter in order to apply a set of CSP policies on all HTTP response returned by server. &lt;br /&gt;
&lt;br /&gt;
The policies will instruct the browser to have the loading behavior below using all HTTP headers defined in W3C Specs:&lt;br /&gt;
* Explicit loading definition of each resource type,&lt;br /&gt;
* Resources are loaded only from source domain,&lt;br /&gt;
* Inline style is not allowed,&lt;br /&gt;
* For JavaScript:&lt;br /&gt;
** ''Inline script'' will be allowed because inline scripting it's commonly used (can be disabled if target site do not use this type of scripting),&lt;br /&gt;
** ''eval()'' function will be allowed in order to not break use of popular JavaScript libraries (ex: JQuery, JQueryUI, Sencha, ...) because they use eval() function (it was the case last time I have checked the source code from CDN ;) ),&lt;br /&gt;
* Generation of a random not guessable script nonce to use into all script tag,&lt;br /&gt;
* Plugin types only allow PDF and Flash,&lt;br /&gt;
* No font loading (configurable),&lt;br /&gt;
* No Audio / Video loading (configurable),&lt;br /&gt;
* Enable browser XSS filtering feature.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:navy&amp;quot;&amp;gt;&lt;br /&gt;
The support for CSP directives is not the same level in major browsers (Firefox/Chrome/IE). It's recommanded to check the support &lt;br /&gt;
provided by target browsers  (using site provided in link section of this article) in order to configure CSP policies. The sample &lt;br /&gt;
below try to provide a set of policies from which your can add policies specific to your application context.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''This implementation provide an option to add CSP directives used by Firefox (Mozilla CSP directives).''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.security.MessageDigest;&lt;br /&gt;
import java.security.NoSuchAlgorithmException;&lt;br /&gt;
import java.security.SecureRandom;&lt;br /&gt;
import java.util.ArrayList;&lt;br /&gt;
import java.util.List;&lt;br /&gt;
&lt;br /&gt;
import javax.servlet.Filter;&lt;br /&gt;
import javax.servlet.FilterChain;&lt;br /&gt;
import javax.servlet.FilterConfig;&lt;br /&gt;
import javax.servlet.ServletException;&lt;br /&gt;
import javax.servlet.ServletRequest;&lt;br /&gt;
import javax.servlet.ServletResponse;&lt;br /&gt;
import javax.servlet.annotation.WebFilter;&lt;br /&gt;
import javax.servlet.http.HttpServletRequest;&lt;br /&gt;
import javax.servlet.http.HttpServletResponse;&lt;br /&gt;
&lt;br /&gt;
import org.apache.commons.codec.binary.Hex;&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * Sample filter implementation to define a set of Content Security Policies.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 * This implementation has a dependency on Commons Codec API.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 * This filter set CSP policies using all HTTP headers defined into W3C specification.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &amp;lt;br/&amp;gt;&lt;br /&gt;
 * This implementation is oriented to be easily understandable and easily adapted.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
@WebFilter(&amp;quot;/*&amp;quot;)&lt;br /&gt;
public class CSPPoliciesApplier implements Filter {&lt;br /&gt;
&lt;br /&gt;
	/** Configuration member to specify if web app use web fonts */&lt;br /&gt;
	public static final boolean APP_USE_WEBFONTS = false;&lt;br /&gt;
&lt;br /&gt;
	/** Configuration member to specify if web app use videos or audios */&lt;br /&gt;
	public static final boolean APP_USE_AUDIOS_OR_VIDEOS = false;&lt;br /&gt;
&lt;br /&gt;
	/** Configuration member to specify if filter must add CSP directive used by Mozilla (Firefox) */&lt;br /&gt;
	public static final boolean INCLUDE_MOZILLA_CSP_DIRECTIVES = true;&lt;br /&gt;
&lt;br /&gt;
	/** Filter configuration */&lt;br /&gt;
	@SuppressWarnings(&amp;quot;unused&amp;quot;)&lt;br /&gt;
	private FilterConfig filterConfig = null;&lt;br /&gt;
&lt;br /&gt;
	/** List CSP HTTP Headers */&lt;br /&gt;
	private List&amp;lt;String&amp;gt; cspHeaders = new ArrayList&amp;lt;String&amp;gt;();&lt;br /&gt;
&lt;br /&gt;
	/** Collection of CSP polcies that will be applied */&lt;br /&gt;
	private String policies = null;&lt;br /&gt;
&lt;br /&gt;
	/** Used for Script Nonce */&lt;br /&gt;
	private SecureRandom prng = null;&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Used to prepare (one time for all) set of CSP policies that will be applied on each HTTP response.&lt;br /&gt;
	 * &lt;br /&gt;
	 * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)&lt;br /&gt;
	 */&lt;br /&gt;
	@Override&lt;br /&gt;
	public void init(FilterConfig fConfig) throws ServletException {&lt;br /&gt;
		// Get filter configuration&lt;br /&gt;
		this.filterConfig = fConfig;&lt;br /&gt;
&lt;br /&gt;
		// Init secure random&lt;br /&gt;
		try {&lt;br /&gt;
			this.prng = SecureRandom.getInstance(&amp;quot;SHA1PRNG&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		catch (NoSuchAlgorithmException e) {&lt;br /&gt;
			throw new ServletException(e);&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		// Define list of CSP HTTP Headers&lt;br /&gt;
		this.cspHeaders.add(&amp;quot;Content-Security-Policy&amp;quot;);&lt;br /&gt;
		this.cspHeaders.add(&amp;quot;X-Content-Security-Policy&amp;quot;);&lt;br /&gt;
		this.cspHeaders.add(&amp;quot;X-WebKit-CSP&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
		// Define CSP policies&lt;br /&gt;
		// Loading policies for Frame and Sandboxing will be dynamically defined : We need to know if context use Frame&lt;br /&gt;
		List&amp;lt;String&amp;gt; cspPolicies = new ArrayList&amp;lt;String&amp;gt;();&lt;br /&gt;
		String originLocationRef = &amp;quot;'self'&amp;quot;;&lt;br /&gt;
		// --Disable default source in order to avoid browser fallback loading using 'default-src' locations&lt;br /&gt;
		cspPolicies.add(&amp;quot;default-src 'none'&amp;quot;);&lt;br /&gt;
		// --Define loading policies for Scripts&lt;br /&gt;
		cspPolicies.add(&amp;quot;script-src &amp;quot; + originLocationRef + &amp;quot; 'unsafe-inline' 'unsafe-eval'&amp;quot;);&lt;br /&gt;
		if (INCLUDE_MOZILLA_CSP_DIRECTIVES) {&lt;br /&gt;
			cspPolicies.add(&amp;quot;options inline-script eval-script&amp;quot;);&lt;br /&gt;
			cspPolicies.add(&amp;quot;xhr-src 'self'&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		// --Define loading policies for Plugins&lt;br /&gt;
		cspPolicies.add(&amp;quot;object-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Styles (CSS)&lt;br /&gt;
		cspPolicies.add(&amp;quot;style-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Images&lt;br /&gt;
		cspPolicies.add(&amp;quot;img-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Form&lt;br /&gt;
		cspPolicies.add(&amp;quot;form-action &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Audios/Videos&lt;br /&gt;
		if (APP_USE_AUDIOS_OR_VIDEOS) {&lt;br /&gt;
			cspPolicies.add(&amp;quot;media-src &amp;quot; + originLocationRef);&lt;br /&gt;
		}&lt;br /&gt;
		// --Define loading policies for Fonts&lt;br /&gt;
		if (APP_USE_WEBFONTS) {&lt;br /&gt;
			cspPolicies.add(&amp;quot;font-src &amp;quot; + originLocationRef);&lt;br /&gt;
		}&lt;br /&gt;
		// --Define loading policies for Connection&lt;br /&gt;
		cspPolicies.add(&amp;quot;connect-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Plugins Types&lt;br /&gt;
		cspPolicies.add(&amp;quot;plugin-types application/pdf application/x-shockwave-flash&amp;quot;);&lt;br /&gt;
		// --Define browser XSS filtering feature running mode&lt;br /&gt;
		cspPolicies.add(&amp;quot;reflected-xss block&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
		// Target formating&lt;br /&gt;
		this.policies = cspPolicies.toString().replaceAll(&amp;quot;(\\[|\\])&amp;quot;, &amp;quot;&amp;quot;).replaceAll(&amp;quot;,&amp;quot;, &amp;quot;;&amp;quot;).trim();&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Add CSP policies on each HTTP response.&lt;br /&gt;
	 * &lt;br /&gt;
	 * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)&lt;br /&gt;
	 */&lt;br /&gt;
	@Override&lt;br /&gt;
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain fchain) throws IOException, ServletException {&lt;br /&gt;
		HttpServletRequest httpRequest = ((HttpServletRequest) request);&lt;br /&gt;
		HttpServletResponse httpResponse = ((HttpServletResponse) response);&lt;br /&gt;
&lt;br /&gt;
		/* Step 1 : Detect if target resource is a Frame */&lt;br /&gt;
		// Customize here according to your context...&lt;br /&gt;
		boolean isFrame = true;&lt;br /&gt;
&lt;br /&gt;
		/* Step 2 : Add CSP policies to HTTP response */&lt;br /&gt;
		StringBuilder policiesBuffer = new StringBuilder(this.policies);&lt;br /&gt;
&lt;br /&gt;
		// If resource is a frame add Frame/Sandbox CSP policy&lt;br /&gt;
		if (isFrame) {&lt;br /&gt;
			// Frame + Sandbox : Here sandbox allow nothing, customize sandbox options depending on your app....&lt;br /&gt;
			policiesBuffer.append(&amp;quot;;&amp;quot;).append(&amp;quot;frame-src 'self';sandbox&amp;quot;);&lt;br /&gt;
			if (INCLUDE_MOZILLA_CSP_DIRECTIVES) {&lt;br /&gt;
				policiesBuffer.append(&amp;quot;;&amp;quot;).append(&amp;quot;frame-ancestors 'self'&amp;quot;);&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		// Add Script Nonce CSP Policy&lt;br /&gt;
		// --Generate a random number&lt;br /&gt;
		String randomNum = new Integer(this.prng.nextInt()).toString();&lt;br /&gt;
		// --Get its digest&lt;br /&gt;
		MessageDigest sha;&lt;br /&gt;
		try {&lt;br /&gt;
			sha = MessageDigest.getInstance(&amp;quot;SHA-1&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		catch (NoSuchAlgorithmException e) {&lt;br /&gt;
			throw new ServletException(e);&lt;br /&gt;
		}&lt;br /&gt;
		byte[] digest = sha.digest(randomNum.getBytes());&lt;br /&gt;
		// --Encode it into HEXA&lt;br /&gt;
		String scriptNonce = Hex.encodeHexString(digest);&lt;br /&gt;
		policiesBuffer.append(&amp;quot;;&amp;quot;).append(&amp;quot;script-nonce &amp;quot;).append(scriptNonce);&lt;br /&gt;
		// --Made available script nonce in view app layer&lt;br /&gt;
		httpRequest.setAttribute(&amp;quot;CSP_SCRIPT_NONCE&amp;quot;, scriptNonce);&lt;br /&gt;
&lt;br /&gt;
		// Add policies to all HTTP headers&lt;br /&gt;
		for (String header : this.cspHeaders) {&lt;br /&gt;
			httpResponse.setHeader(header, policiesBuffer.toString());&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		/* Step 3 : Let request continue chain filter */&lt;br /&gt;
		fchain.doFilter(request, response);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * {@inheritDoc}&lt;br /&gt;
	 * &lt;br /&gt;
	 * @see javax.servlet.Filter#destroy()&lt;br /&gt;
	 */&lt;br /&gt;
	@Override&lt;br /&gt;
	public void destroy() {&lt;br /&gt;
		// Not used&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
[[Automated Audit using w3af|w3af]] audit tools (http://w3af.org) contain [https://github.com/andresriancho/w3af/blob/master/plugins/grep/csp.py plugin] to automatically audit web application to check if they correctly implement CSP policies. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:#088A08&amp;quot;&amp;gt;&lt;br /&gt;
It's very useful to include this type of tools into a web application development process in order to &lt;br /&gt;
perform a regular automatic first level check (do not replace an manual audit and manual audit must be also conducted regularly).&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can also use  [https://www.oxdef.info/csp-tester CSP Tester (browser extension)] to build and test the policy for your web application.&lt;br /&gt;
&lt;br /&gt;
== Information links ==&lt;br /&gt;
* W3C Specifications: CSP 1.0  - http://www.w3.org/TR/CSP, CSP 1.1 - http://w3c.github.io/webappsec/specs/content-security-policy/csp-specification.dev.html&lt;br /&gt;
* Introduction to CSP: http://www.html5rocks.com/en/tutorials/security/content-security-policy&lt;br /&gt;
* CSP browser support: http://caniuse.com/#feat=contentsecuritypolicy&lt;br /&gt;
* CSP readiness browser testing: http://erlend.oftedal.no/blog/csp/readiness/&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP Java Project]]&lt;br /&gt;
[[Category: Injection]]&lt;br /&gt;
[[Category:Attack]]&lt;br /&gt;
[[Category:Injection Attack]]&lt;/div&gt;</summary>
		<author><name>Dimisec</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Content_Security_Policy&amp;diff=169068</id>
		<title>Content Security Policy</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Content_Security_Policy&amp;diff=169068"/>
				<updated>2014-02-27T11:09:18Z</updated>
		
		<summary type="html">&lt;p&gt;Dimisec: one more update of the link to the W3C spec&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Last revision (mm/dd/yy): '''08/31/2013'''&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
'''CSP''' stands for '''C'''ontent '''S'''ecurity '''P'''olicy. &lt;br /&gt;
&lt;br /&gt;
Is an W3C specification offering the possbility to instruct the client browser from which location and/or which type of resources are allowed to be loaded. To define a loading behavior, the CSP specification use &amp;quot;directive&amp;quot; where a directive defines a loading behavior for a target resource type.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This article is based on version [http://w3c.github.io/webappsec/specs/content-security-policy/csp-specification.dev.html 1.1] of the W3C specification.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Directives can be specified using HTTP response header (a server may send more than one CSP HTTP header field with a given resource representation and a server may send different CSP header field values with different representations of the same resource or with different resources) or HTML Meta tag, the HTTP headers below are defined by the specs:&lt;br /&gt;
* '''Content-Security-Policy''' : Defined by W3C Specs as standard header, used by Chrome version 25 and later, Firefox version 23 and later, Opera version 19 and later.&lt;br /&gt;
* '''X-Content-Security-Policy''' : Used by Firefox until version 23, and Internet Explorer version 10 (which partially implements Content Security Policy).&lt;br /&gt;
* '''X-WebKit-CSP''' : Used by Chrome until version 25&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The supported directives are:&lt;br /&gt;
* '''default-src''' : Define loading policy for all resources type in case of a resource type dedicated directive is not defined (fallback),&lt;br /&gt;
* '''script-src''' :  Define which scripts the protected resource can execute,&lt;br /&gt;
* '''object-src''' :  Define from where the protected resource can load plugins,&lt;br /&gt;
* '''style-src''' : Define which styles (CSS) the user applies to the protected resource,&lt;br /&gt;
* '''img-src''' : Define from where the protected resource can load images,&lt;br /&gt;
* '''media-src''' : Define from where the protected resource can load video and audio,&lt;br /&gt;
* '''frame-src''' : Define from where the protected resource can embed frames,&lt;br /&gt;
* '''font-src''' : Define from where the protected resource can load fonts,&lt;br /&gt;
* '''connect-src''' : Define which URIs the protected resource can load using script interfaces,&lt;br /&gt;
* '''form-action''' : Define which URIs can be used as the action of HTML form elements,&lt;br /&gt;
* '''sandbox''' : Specifies an HTML sandbox policy that the user agent applies to the protected resource,&lt;br /&gt;
* '''script-nonce''' : Define script execution by requiring the presence of the specified nonce on script elements,&lt;br /&gt;
* '''plugin-types''' : Define the set of plugins that can be invoked by the protected resource by limiting the types of resources that can be embedded,&lt;br /&gt;
* '''reflected-xss''' : Instructs a user agent to activate or disactivate any heuristics used to filter or block reflected cross-site scripting attacks, equivalent to the effects of the non-standard X-XSS-Protection header,&lt;br /&gt;
*  '''report-uri''' : Specifies a URI to which the user agent sends reports about policy violation&lt;br /&gt;
&lt;br /&gt;
An introduction to CSP is available on [http://www.html5rocks.com/en/tutorials/security/content-security-policy/ HTML5Rocks].  The browser support is shown on http://caniuse.com/#feat=contentsecuritypolicy&lt;br /&gt;
&lt;br /&gt;
== Risk ==&lt;br /&gt;
The risk with CSP can have 2 main sources:&lt;br /&gt;
# Policies misconfiguration,&lt;br /&gt;
# Too permissive policies.&lt;br /&gt;
&lt;br /&gt;
== Countermeasure ==&lt;br /&gt;
This article will focus on providing an sample implementation of a JEE Web Filter in order to apply a set of CSP policies on all HTTP response returned by server. &lt;br /&gt;
&lt;br /&gt;
The policies will instructs the browser to have the loading behavior below using all HTTP headers defined in W3C Specs:&lt;br /&gt;
* Explicit loading definition of each resource type,&lt;br /&gt;
* Resources are loaded only from source domain,&lt;br /&gt;
* Inline style is not allowed,&lt;br /&gt;
* For JavaScript:&lt;br /&gt;
** ''Inline script'' will be allowed because inline scripting it's commonly used (can be disabled if target site do not use this type of scripting),&lt;br /&gt;
** ''eval()'' function will be allowed in order to not break use of popular JavaScript libraries (ex: JQuery, JQueryUI, Sencha, ...) because they use eval() function (it was the case last time I have checked the source code from CDN ;) ),&lt;br /&gt;
* Generation of a random not guessable script nonce to use into all script tag,&lt;br /&gt;
* Plugin types only allow PDF and Flash,&lt;br /&gt;
* No font loading (configurable),&lt;br /&gt;
* No Audio / Video loading (configurable),&lt;br /&gt;
* Enable browser XSS filtering feature.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:navy&amp;quot;&amp;gt;&lt;br /&gt;
The support for CSP directives is not the same level in major browsers (Firefox/Chrome/IE). It's recommanded to check the support &lt;br /&gt;
provided by target browsers  (using site provided in link section of this article) in order to configure CSP policies. The sample &lt;br /&gt;
below try to provide a set of policies from which your can add policies specific to your application context.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''This implementation provide an option to add CSP directives used by Firefox (Mozilla CSP directives).''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.security.MessageDigest;&lt;br /&gt;
import java.security.NoSuchAlgorithmException;&lt;br /&gt;
import java.security.SecureRandom;&lt;br /&gt;
import java.util.ArrayList;&lt;br /&gt;
import java.util.List;&lt;br /&gt;
&lt;br /&gt;
import javax.servlet.Filter;&lt;br /&gt;
import javax.servlet.FilterChain;&lt;br /&gt;
import javax.servlet.FilterConfig;&lt;br /&gt;
import javax.servlet.ServletException;&lt;br /&gt;
import javax.servlet.ServletRequest;&lt;br /&gt;
import javax.servlet.ServletResponse;&lt;br /&gt;
import javax.servlet.annotation.WebFilter;&lt;br /&gt;
import javax.servlet.http.HttpServletRequest;&lt;br /&gt;
import javax.servlet.http.HttpServletResponse;&lt;br /&gt;
&lt;br /&gt;
import org.apache.commons.codec.binary.Hex;&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * Sample filter implementation to define a set of Content Security Policies.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 * This implementation has a dependency on Commons Codec API.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 * This filter set CSP policies using all HTTP headers defined into W3C specification.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &amp;lt;br/&amp;gt;&lt;br /&gt;
 * This implementation is oriented to be easily understandable and easily adapted.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
@WebFilter(&amp;quot;/*&amp;quot;)&lt;br /&gt;
public class CSPPoliciesApplier implements Filter {&lt;br /&gt;
&lt;br /&gt;
	/** Configuration member to specify if web app use web fonts */&lt;br /&gt;
	public static final boolean APP_USE_WEBFONTS = false;&lt;br /&gt;
&lt;br /&gt;
	/** Configuration member to specify if web app use videos or audios */&lt;br /&gt;
	public static final boolean APP_USE_AUDIOS_OR_VIDEOS = false;&lt;br /&gt;
&lt;br /&gt;
	/** Configuration member to specify if filter must add CSP directive used by Mozilla (Firefox) */&lt;br /&gt;
	public static final boolean INCLUDE_MOZILLA_CSP_DIRECTIVES = true;&lt;br /&gt;
&lt;br /&gt;
	/** Filter configuration */&lt;br /&gt;
	@SuppressWarnings(&amp;quot;unused&amp;quot;)&lt;br /&gt;
	private FilterConfig filterConfig = null;&lt;br /&gt;
&lt;br /&gt;
	/** List CSP HTTP Headers */&lt;br /&gt;
	private List&amp;lt;String&amp;gt; cspHeaders = new ArrayList&amp;lt;String&amp;gt;();&lt;br /&gt;
&lt;br /&gt;
	/** Collection of CSP polcies that will be applied */&lt;br /&gt;
	private String policies = null;&lt;br /&gt;
&lt;br /&gt;
	/** Used for Script Nonce */&lt;br /&gt;
	private SecureRandom prng = null;&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Used to prepare (one time for all) set of CSP policies that will be applied on each HTTP response.&lt;br /&gt;
	 * &lt;br /&gt;
	 * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)&lt;br /&gt;
	 */&lt;br /&gt;
	@Override&lt;br /&gt;
	public void init(FilterConfig fConfig) throws ServletException {&lt;br /&gt;
		// Get filter configuration&lt;br /&gt;
		this.filterConfig = fConfig;&lt;br /&gt;
&lt;br /&gt;
		// Init secure random&lt;br /&gt;
		try {&lt;br /&gt;
			this.prng = SecureRandom.getInstance(&amp;quot;SHA1PRNG&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		catch (NoSuchAlgorithmException e) {&lt;br /&gt;
			throw new ServletException(e);&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		// Define list of CSP HTTP Headers&lt;br /&gt;
		this.cspHeaders.add(&amp;quot;Content-Security-Policy&amp;quot;);&lt;br /&gt;
		this.cspHeaders.add(&amp;quot;X-Content-Security-Policy&amp;quot;);&lt;br /&gt;
		this.cspHeaders.add(&amp;quot;X-WebKit-CSP&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
		// Define CSP policies&lt;br /&gt;
		// Loading policies for Frame and Sandboxing will be dynamically defined : We need to know if context use Frame&lt;br /&gt;
		List&amp;lt;String&amp;gt; cspPolicies = new ArrayList&amp;lt;String&amp;gt;();&lt;br /&gt;
		String originLocationRef = &amp;quot;'self'&amp;quot;;&lt;br /&gt;
		// --Disable default source in order to avoid browser fallback loading using 'default-src' locations&lt;br /&gt;
		cspPolicies.add(&amp;quot;default-src 'none'&amp;quot;);&lt;br /&gt;
		// --Define loading policies for Scripts&lt;br /&gt;
		cspPolicies.add(&amp;quot;script-src &amp;quot; + originLocationRef + &amp;quot; 'unsafe-inline' 'unsafe-eval'&amp;quot;);&lt;br /&gt;
		if (INCLUDE_MOZILLA_CSP_DIRECTIVES) {&lt;br /&gt;
			cspPolicies.add(&amp;quot;options inline-script eval-script&amp;quot;);&lt;br /&gt;
			cspPolicies.add(&amp;quot;xhr-src 'self'&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		// --Define loading policies for Plugins&lt;br /&gt;
		cspPolicies.add(&amp;quot;object-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Styles (CSS)&lt;br /&gt;
		cspPolicies.add(&amp;quot;style-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Images&lt;br /&gt;
		cspPolicies.add(&amp;quot;img-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Form&lt;br /&gt;
		cspPolicies.add(&amp;quot;form-action &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Audios/Videos&lt;br /&gt;
		if (APP_USE_AUDIOS_OR_VIDEOS) {&lt;br /&gt;
			cspPolicies.add(&amp;quot;media-src &amp;quot; + originLocationRef);&lt;br /&gt;
		}&lt;br /&gt;
		// --Define loading policies for Fonts&lt;br /&gt;
		if (APP_USE_WEBFONTS) {&lt;br /&gt;
			cspPolicies.add(&amp;quot;font-src &amp;quot; + originLocationRef);&lt;br /&gt;
		}&lt;br /&gt;
		// --Define loading policies for Connection&lt;br /&gt;
		cspPolicies.add(&amp;quot;connect-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Plugins Types&lt;br /&gt;
		cspPolicies.add(&amp;quot;plugin-types application/pdf application/x-shockwave-flash&amp;quot;);&lt;br /&gt;
		// --Define browser XSS filtering feature running mode&lt;br /&gt;
		cspPolicies.add(&amp;quot;reflected-xss block&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
		// Target formating&lt;br /&gt;
		this.policies = cspPolicies.toString().replaceAll(&amp;quot;(\\[|\\])&amp;quot;, &amp;quot;&amp;quot;).replaceAll(&amp;quot;,&amp;quot;, &amp;quot;;&amp;quot;).trim();&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Add CSP policies on each HTTP response.&lt;br /&gt;
	 * &lt;br /&gt;
	 * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)&lt;br /&gt;
	 */&lt;br /&gt;
	@Override&lt;br /&gt;
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain fchain) throws IOException, ServletException {&lt;br /&gt;
		HttpServletRequest httpRequest = ((HttpServletRequest) request);&lt;br /&gt;
		HttpServletResponse httpResponse = ((HttpServletResponse) response);&lt;br /&gt;
&lt;br /&gt;
		/* Step 1 : Detect if target resource is a Frame */&lt;br /&gt;
		// Customize here according to your context...&lt;br /&gt;
		boolean isFrame = true;&lt;br /&gt;
&lt;br /&gt;
		/* Step 2 : Add CSP policies to HTTP response */&lt;br /&gt;
		StringBuilder policiesBuffer = new StringBuilder(this.policies);&lt;br /&gt;
&lt;br /&gt;
		// If resource is a frame add Frame/Sandbox CSP policy&lt;br /&gt;
		if (isFrame) {&lt;br /&gt;
			// Frame + Sandbox : Here sandbox allow nothing, customize sandbox options depending on your app....&lt;br /&gt;
			policiesBuffer.append(&amp;quot;;&amp;quot;).append(&amp;quot;frame-src 'self';sandbox&amp;quot;);&lt;br /&gt;
			if (INCLUDE_MOZILLA_CSP_DIRECTIVES) {&lt;br /&gt;
				policiesBuffer.append(&amp;quot;;&amp;quot;).append(&amp;quot;frame-ancestors 'self'&amp;quot;);&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		// Add Script Nonce CSP Policy&lt;br /&gt;
		// --Generate a random number&lt;br /&gt;
		String randomNum = new Integer(this.prng.nextInt()).toString();&lt;br /&gt;
		// --Get its digest&lt;br /&gt;
		MessageDigest sha;&lt;br /&gt;
		try {&lt;br /&gt;
			sha = MessageDigest.getInstance(&amp;quot;SHA-1&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		catch (NoSuchAlgorithmException e) {&lt;br /&gt;
			throw new ServletException(e);&lt;br /&gt;
		}&lt;br /&gt;
		byte[] digest = sha.digest(randomNum.getBytes());&lt;br /&gt;
		// --Encode it into HEXA&lt;br /&gt;
		String scriptNonce = Hex.encodeHexString(digest);&lt;br /&gt;
		policiesBuffer.append(&amp;quot;;&amp;quot;).append(&amp;quot;script-nonce &amp;quot;).append(scriptNonce);&lt;br /&gt;
		// --Made available script nonce in view app layer&lt;br /&gt;
		httpRequest.setAttribute(&amp;quot;CSP_SCRIPT_NONCE&amp;quot;, scriptNonce);&lt;br /&gt;
&lt;br /&gt;
		// Add policies to all HTTP headers&lt;br /&gt;
		for (String header : this.cspHeaders) {&lt;br /&gt;
			httpResponse.setHeader(header, policiesBuffer.toString());&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		/* Step 3 : Let request continue chain filter */&lt;br /&gt;
		fchain.doFilter(request, response);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * {@inheritDoc}&lt;br /&gt;
	 * &lt;br /&gt;
	 * @see javax.servlet.Filter#destroy()&lt;br /&gt;
	 */&lt;br /&gt;
	@Override&lt;br /&gt;
	public void destroy() {&lt;br /&gt;
		// Not used&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
[[Automated Audit using w3af|w3af]] audit tools (http://w3af.org) contain [https://github.com/andresriancho/w3af/blob/master/plugins/grep/csp.py plugin] to automatically audit web application to check if they correctly implement CSP policies. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:#088A08&amp;quot;&amp;gt;&lt;br /&gt;
It's very useful to include this type of tools into a web application development process in order to &lt;br /&gt;
perform a regular automatic first level check (do not replace an manual audit and manual audit must be also conducted regularly).&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can also use  [https://www.oxdef.info/csp-tester CSP Tester (browser extension)] to build and test the policy for your web application.&lt;br /&gt;
&lt;br /&gt;
== Information links ==&lt;br /&gt;
* W3C Specifications: CSP 1.0  - http://www.w3.org/TR/CSP, CSP 1.1 - http://w3c.github.io/webappsec/specs/content-security-policy/csp-specification.dev.html&lt;br /&gt;
* Introduction to CSP: http://www.html5rocks.com/en/tutorials/security/content-security-policy&lt;br /&gt;
* CSP browser support: http://caniuse.com/#feat=contentsecuritypolicy&lt;br /&gt;
* CSP readiness browser testing: http://erlend.oftedal.no/blog/csp/readiness/&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP Java Project]]&lt;br /&gt;
[[Category: Injection]]&lt;br /&gt;
[[Category:Attack]]&lt;br /&gt;
[[Category:Injection Attack]]&lt;/div&gt;</summary>
		<author><name>Dimisec</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Content_Security_Policy&amp;diff=169065</id>
		<title>Content Security Policy</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Content_Security_Policy&amp;diff=169065"/>
				<updated>2014-02-27T11:06:43Z</updated>
		
		<summary type="html">&lt;p&gt;Dimisec: removed the second link to caniuse (there is one later in the page, should be enough)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Last revision (mm/dd/yy): '''08/31/2013'''&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
'''CSP''' stands for '''C'''ontent '''S'''ecurity '''P'''olicy. &lt;br /&gt;
&lt;br /&gt;
Is an W3C specification offering the possbility to instruct the client browser from which location and/or which type of resources are allowed to be loaded. To define a loading behavior, the CSP specification use &amp;quot;directive&amp;quot; where a directive defines a loading behavior for a target resource type.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This article is based on version [http://w3c.github.io/webappsec/specs/content-security-policy/csp-specification.dev.html 1.1] of the W3C specification.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Directives can be specified using HTTP response header (a server may send more than one CSP HTTP header field with a given resource representation and a server may send different CSP header field values with different representations of the same resource or with different resources) or HTML Meta tag, the HTTP headers below are defined by the specs:&lt;br /&gt;
* '''Content-Security-Policy''' : Defined by W3C Specs as standard header, used by Chrome version 25 and later, Firefox version 23 and later, Opera version 19 and later.&lt;br /&gt;
* '''X-Content-Security-Policy''' : Used by Firefox until version 23, and Internet Explorer version 10 (which partially implements Content Security Policy).&lt;br /&gt;
* '''X-WebKit-CSP''' : Used by Chrome until version 25&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The supported directives are:&lt;br /&gt;
* '''default-src''' : Define loading policy for all resources type in case of a resource type dedicated directive is not defined (fallback),&lt;br /&gt;
* '''script-src''' :  Define which scripts the protected resource can execute,&lt;br /&gt;
* '''object-src''' :  Define from where the protected resource can load plugins,&lt;br /&gt;
* '''style-src''' : Define which styles (CSS) the user applies to the protected resource,&lt;br /&gt;
* '''img-src''' : Define from where the protected resource can load images,&lt;br /&gt;
* '''media-src''' : Define from where the protected resource can load video and audio,&lt;br /&gt;
* '''frame-src''' : Define from where the protected resource can embed frames,&lt;br /&gt;
* '''font-src''' : Define from where the protected resource can load fonts,&lt;br /&gt;
* '''connect-src''' : Define which URIs the protected resource can load using script interfaces,&lt;br /&gt;
* '''form-action''' : Define which URIs can be used as the action of HTML form elements,&lt;br /&gt;
* '''sandbox''' : Specifies an HTML sandbox policy that the user agent applies to the protected resource,&lt;br /&gt;
* '''script-nonce''' : Define script execution by requiring the presence of the specified nonce on script elements,&lt;br /&gt;
* '''plugin-types''' : Define the set of plugins that can be invoked by the protected resource by limiting the types of resources that can be embedded,&lt;br /&gt;
* '''reflected-xss''' : Instructs a user agent to activate or disactivate any heuristics used to filter or block reflected cross-site scripting attacks, equivalent to the effects of the non-standard X-XSS-Protection header,&lt;br /&gt;
*  '''report-uri''' : Specifies a URI to which the user agent sends reports about policy violation&lt;br /&gt;
&lt;br /&gt;
An introduction to CSP is available on [http://www.html5rocks.com/en/tutorials/security/content-security-policy/ HTML5Rocks].  The browser support is shown on http://caniuse.com/#feat=contentsecuritypolicy&lt;br /&gt;
&lt;br /&gt;
== Risk ==&lt;br /&gt;
The risk with CSP can have 2 main sources:&lt;br /&gt;
# Policies misconfiguration,&lt;br /&gt;
# Too permissive policies.&lt;br /&gt;
&lt;br /&gt;
== Countermeasure ==&lt;br /&gt;
This article will focus on providing an sample implementation of a JEE Web Filter in order to apply a set of CSP policies on all HTTP response returned by server. &lt;br /&gt;
&lt;br /&gt;
The policies will instructs the browser to have the loading behavior below using all HTTP headers defined in W3C Specs:&lt;br /&gt;
* Explicit loading definition of each resource type,&lt;br /&gt;
* Resources are loaded only from source domain,&lt;br /&gt;
* Inline style is not allowed,&lt;br /&gt;
* For JavaScript:&lt;br /&gt;
** ''Inline script'' will be allowed because inline scripting it's commonly used (can be disabled if target site do not use this type of scripting),&lt;br /&gt;
** ''eval()'' function will be allowed in order to not break use of popular JavaScript libraries (ex: JQuery, JQueryUI, Sencha, ...) because they use eval() function (it was the case last time I have checked the source code from CDN ;) ),&lt;br /&gt;
* Generation of a random not guessable script nonce to use into all script tag,&lt;br /&gt;
* Plugin types only allow PDF and Flash,&lt;br /&gt;
* No font loading (configurable),&lt;br /&gt;
* No Audio / Video loading (configurable),&lt;br /&gt;
* Enable browser XSS filtering feature.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:navy&amp;quot;&amp;gt;&lt;br /&gt;
The support for CSP directives is not the same level in major browsers (Firefox/Chrome/IE). It's recommanded to check the support &lt;br /&gt;
provided by target browsers  (using site provided in link section of this article) in order to configure CSP policies. The sample &lt;br /&gt;
below try to provide a set of policies from which your can add policies specific to your application context.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''This implementation provide an option to add CSP directives used by Firefox (Mozilla CSP directives).''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.security.MessageDigest;&lt;br /&gt;
import java.security.NoSuchAlgorithmException;&lt;br /&gt;
import java.security.SecureRandom;&lt;br /&gt;
import java.util.ArrayList;&lt;br /&gt;
import java.util.List;&lt;br /&gt;
&lt;br /&gt;
import javax.servlet.Filter;&lt;br /&gt;
import javax.servlet.FilterChain;&lt;br /&gt;
import javax.servlet.FilterConfig;&lt;br /&gt;
import javax.servlet.ServletException;&lt;br /&gt;
import javax.servlet.ServletRequest;&lt;br /&gt;
import javax.servlet.ServletResponse;&lt;br /&gt;
import javax.servlet.annotation.WebFilter;&lt;br /&gt;
import javax.servlet.http.HttpServletRequest;&lt;br /&gt;
import javax.servlet.http.HttpServletResponse;&lt;br /&gt;
&lt;br /&gt;
import org.apache.commons.codec.binary.Hex;&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * Sample filter implementation to define a set of Content Security Policies.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 * This implementation has a dependency on Commons Codec API.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 * This filter set CSP policies using all HTTP headers defined into W3C specification.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &amp;lt;br/&amp;gt;&lt;br /&gt;
 * This implementation is oriented to be easily understandable and easily adapted.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
@WebFilter(&amp;quot;/*&amp;quot;)&lt;br /&gt;
public class CSPPoliciesApplier implements Filter {&lt;br /&gt;
&lt;br /&gt;
	/** Configuration member to specify if web app use web fonts */&lt;br /&gt;
	public static final boolean APP_USE_WEBFONTS = false;&lt;br /&gt;
&lt;br /&gt;
	/** Configuration member to specify if web app use videos or audios */&lt;br /&gt;
	public static final boolean APP_USE_AUDIOS_OR_VIDEOS = false;&lt;br /&gt;
&lt;br /&gt;
	/** Configuration member to specify if filter must add CSP directive used by Mozilla (Firefox) */&lt;br /&gt;
	public static final boolean INCLUDE_MOZILLA_CSP_DIRECTIVES = true;&lt;br /&gt;
&lt;br /&gt;
	/** Filter configuration */&lt;br /&gt;
	@SuppressWarnings(&amp;quot;unused&amp;quot;)&lt;br /&gt;
	private FilterConfig filterConfig = null;&lt;br /&gt;
&lt;br /&gt;
	/** List CSP HTTP Headers */&lt;br /&gt;
	private List&amp;lt;String&amp;gt; cspHeaders = new ArrayList&amp;lt;String&amp;gt;();&lt;br /&gt;
&lt;br /&gt;
	/** Collection of CSP polcies that will be applied */&lt;br /&gt;
	private String policies = null;&lt;br /&gt;
&lt;br /&gt;
	/** Used for Script Nonce */&lt;br /&gt;
	private SecureRandom prng = null;&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Used to prepare (one time for all) set of CSP policies that will be applied on each HTTP response.&lt;br /&gt;
	 * &lt;br /&gt;
	 * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)&lt;br /&gt;
	 */&lt;br /&gt;
	@Override&lt;br /&gt;
	public void init(FilterConfig fConfig) throws ServletException {&lt;br /&gt;
		// Get filter configuration&lt;br /&gt;
		this.filterConfig = fConfig;&lt;br /&gt;
&lt;br /&gt;
		// Init secure random&lt;br /&gt;
		try {&lt;br /&gt;
			this.prng = SecureRandom.getInstance(&amp;quot;SHA1PRNG&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		catch (NoSuchAlgorithmException e) {&lt;br /&gt;
			throw new ServletException(e);&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		// Define list of CSP HTTP Headers&lt;br /&gt;
		this.cspHeaders.add(&amp;quot;Content-Security-Policy&amp;quot;);&lt;br /&gt;
		this.cspHeaders.add(&amp;quot;X-Content-Security-Policy&amp;quot;);&lt;br /&gt;
		this.cspHeaders.add(&amp;quot;X-WebKit-CSP&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
		// Define CSP policies&lt;br /&gt;
		// Loading policies for Frame and Sandboxing will be dynamically defined : We need to know if context use Frame&lt;br /&gt;
		List&amp;lt;String&amp;gt; cspPolicies = new ArrayList&amp;lt;String&amp;gt;();&lt;br /&gt;
		String originLocationRef = &amp;quot;'self'&amp;quot;;&lt;br /&gt;
		// --Disable default source in order to avoid browser fallback loading using 'default-src' locations&lt;br /&gt;
		cspPolicies.add(&amp;quot;default-src 'none'&amp;quot;);&lt;br /&gt;
		// --Define loading policies for Scripts&lt;br /&gt;
		cspPolicies.add(&amp;quot;script-src &amp;quot; + originLocationRef + &amp;quot; 'unsafe-inline' 'unsafe-eval'&amp;quot;);&lt;br /&gt;
		if (INCLUDE_MOZILLA_CSP_DIRECTIVES) {&lt;br /&gt;
			cspPolicies.add(&amp;quot;options inline-script eval-script&amp;quot;);&lt;br /&gt;
			cspPolicies.add(&amp;quot;xhr-src 'self'&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		// --Define loading policies for Plugins&lt;br /&gt;
		cspPolicies.add(&amp;quot;object-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Styles (CSS)&lt;br /&gt;
		cspPolicies.add(&amp;quot;style-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Images&lt;br /&gt;
		cspPolicies.add(&amp;quot;img-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Form&lt;br /&gt;
		cspPolicies.add(&amp;quot;form-action &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Audios/Videos&lt;br /&gt;
		if (APP_USE_AUDIOS_OR_VIDEOS) {&lt;br /&gt;
			cspPolicies.add(&amp;quot;media-src &amp;quot; + originLocationRef);&lt;br /&gt;
		}&lt;br /&gt;
		// --Define loading policies for Fonts&lt;br /&gt;
		if (APP_USE_WEBFONTS) {&lt;br /&gt;
			cspPolicies.add(&amp;quot;font-src &amp;quot; + originLocationRef);&lt;br /&gt;
		}&lt;br /&gt;
		// --Define loading policies for Connection&lt;br /&gt;
		cspPolicies.add(&amp;quot;connect-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Plugins Types&lt;br /&gt;
		cspPolicies.add(&amp;quot;plugin-types application/pdf application/x-shockwave-flash&amp;quot;);&lt;br /&gt;
		// --Define browser XSS filtering feature running mode&lt;br /&gt;
		cspPolicies.add(&amp;quot;reflected-xss block&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
		// Target formating&lt;br /&gt;
		this.policies = cspPolicies.toString().replaceAll(&amp;quot;(\\[|\\])&amp;quot;, &amp;quot;&amp;quot;).replaceAll(&amp;quot;,&amp;quot;, &amp;quot;;&amp;quot;).trim();&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Add CSP policies on each HTTP response.&lt;br /&gt;
	 * &lt;br /&gt;
	 * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)&lt;br /&gt;
	 */&lt;br /&gt;
	@Override&lt;br /&gt;
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain fchain) throws IOException, ServletException {&lt;br /&gt;
		HttpServletRequest httpRequest = ((HttpServletRequest) request);&lt;br /&gt;
		HttpServletResponse httpResponse = ((HttpServletResponse) response);&lt;br /&gt;
&lt;br /&gt;
		/* Step 1 : Detect if target resource is a Frame */&lt;br /&gt;
		// Customize here according to your context...&lt;br /&gt;
		boolean isFrame = true;&lt;br /&gt;
&lt;br /&gt;
		/* Step 2 : Add CSP policies to HTTP response */&lt;br /&gt;
		StringBuilder policiesBuffer = new StringBuilder(this.policies);&lt;br /&gt;
&lt;br /&gt;
		// If resource is a frame add Frame/Sandbox CSP policy&lt;br /&gt;
		if (isFrame) {&lt;br /&gt;
			// Frame + Sandbox : Here sandbox allow nothing, customize sandbox options depending on your app....&lt;br /&gt;
			policiesBuffer.append(&amp;quot;;&amp;quot;).append(&amp;quot;frame-src 'self';sandbox&amp;quot;);&lt;br /&gt;
			if (INCLUDE_MOZILLA_CSP_DIRECTIVES) {&lt;br /&gt;
				policiesBuffer.append(&amp;quot;;&amp;quot;).append(&amp;quot;frame-ancestors 'self'&amp;quot;);&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		// Add Script Nonce CSP Policy&lt;br /&gt;
		// --Generate a random number&lt;br /&gt;
		String randomNum = new Integer(this.prng.nextInt()).toString();&lt;br /&gt;
		// --Get its digest&lt;br /&gt;
		MessageDigest sha;&lt;br /&gt;
		try {&lt;br /&gt;
			sha = MessageDigest.getInstance(&amp;quot;SHA-1&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		catch (NoSuchAlgorithmException e) {&lt;br /&gt;
			throw new ServletException(e);&lt;br /&gt;
		}&lt;br /&gt;
		byte[] digest = sha.digest(randomNum.getBytes());&lt;br /&gt;
		// --Encode it into HEXA&lt;br /&gt;
		String scriptNonce = Hex.encodeHexString(digest);&lt;br /&gt;
		policiesBuffer.append(&amp;quot;;&amp;quot;).append(&amp;quot;script-nonce &amp;quot;).append(scriptNonce);&lt;br /&gt;
		// --Made available script nonce in view app layer&lt;br /&gt;
		httpRequest.setAttribute(&amp;quot;CSP_SCRIPT_NONCE&amp;quot;, scriptNonce);&lt;br /&gt;
&lt;br /&gt;
		// Add policies to all HTTP headers&lt;br /&gt;
		for (String header : this.cspHeaders) {&lt;br /&gt;
			httpResponse.setHeader(header, policiesBuffer.toString());&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		/* Step 3 : Let request continue chain filter */&lt;br /&gt;
		fchain.doFilter(request, response);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * {@inheritDoc}&lt;br /&gt;
	 * &lt;br /&gt;
	 * @see javax.servlet.Filter#destroy()&lt;br /&gt;
	 */&lt;br /&gt;
	@Override&lt;br /&gt;
	public void destroy() {&lt;br /&gt;
		// Not used&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
[[Automated Audit using w3af|w3af]] audit tools (http://w3af.org) contain [https://github.com/andresriancho/w3af/blob/master/plugins/grep/csp.py plugin] to automatically audit web application to check if they correctly implement CSP policies. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:#088A08&amp;quot;&amp;gt;&lt;br /&gt;
It's very useful to include this type of tools into a web application development process in order to &lt;br /&gt;
perform a regular automatic first level check (do not replace an manual audit and manual audit must be also conducted regularly).&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can also use  [https://www.oxdef.info/csp-tester CSP Tester (browser extension)] to build and test the policy for your web application.&lt;br /&gt;
&lt;br /&gt;
== Information links ==&lt;br /&gt;
* W3C Specifications: CSP 1.0  - http://www.w3.org/TR/CSP, CSP 1.1 - https://dvcs.w3.org/hg/content-security-policy/raw-file/tip/csp-specification.dev.html&lt;br /&gt;
* Introduction to CSP: http://www.html5rocks.com/en/tutorials/security/content-security-policy&lt;br /&gt;
* CSP browser support: http://caniuse.com/#feat=contentsecuritypolicy&lt;br /&gt;
* CSP readiness browser testing: http://erlend.oftedal.no/blog/csp/readiness/&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP Java Project]]&lt;br /&gt;
[[Category: Injection]]&lt;br /&gt;
[[Category:Attack]]&lt;br /&gt;
[[Category:Injection Attack]]&lt;/div&gt;</summary>
		<author><name>Dimisec</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Content_Security_Policy&amp;diff=169063</id>
		<title>Content Security Policy</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Content_Security_Policy&amp;diff=169063"/>
				<updated>2014-02-27T11:04:59Z</updated>
		
		<summary type="html">&lt;p&gt;Dimisec: updated the link to the W3C specification (moved to github pages)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Last revision (mm/dd/yy): '''08/31/2013'''&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
'''CSP''' stands for '''C'''ontent '''S'''ecurity '''P'''olicy. &lt;br /&gt;
&lt;br /&gt;
Is an W3C specification offering the possbility to instruct the client browser from which location and/or which type of resources are allowed to be loaded. To define a loading behavior, the CSP specification use &amp;quot;directive&amp;quot; where a directive defines a loading behavior for a target resource type.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This article is based on version [http://w3c.github.io/webappsec/specs/content-security-policy/csp-specification.dev.html 1.1] of the W3C specification.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Directives can be specified using HTTP response header (a server may send more than one CSP HTTP header field with a given resource representation and a server may send different CSP header field values with different representations of the same resource or with different resources) or HTML Meta tag, the HTTP headers below are defined by the specs:&lt;br /&gt;
* '''Content-Security-Policy''' : Defined by W3C Specs as standard header, used by Chrome version 25 and later, Firefox version 23 and later, Opera version 19 and later (http://caniuse.com/#search=csp)&lt;br /&gt;
* '''X-Content-Security-Policy''' : Used by Firefox until version 23, and Internet Explorer version 10 (which partially implements Content Security Policy).&lt;br /&gt;
* '''X-WebKit-CSP''' : Used by Chrome until version 25&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The supported directives are:&lt;br /&gt;
* '''default-src''' : Define loading policy for all resources type in case of a resource type dedicated directive is not defined (fallback),&lt;br /&gt;
* '''script-src''' :  Define which scripts the protected resource can execute,&lt;br /&gt;
* '''object-src''' :  Define from where the protected resource can load plugins,&lt;br /&gt;
* '''style-src''' : Define which styles (CSS) the user applies to the protected resource,&lt;br /&gt;
* '''img-src''' : Define from where the protected resource can load images,&lt;br /&gt;
* '''media-src''' : Define from where the protected resource can load video and audio,&lt;br /&gt;
* '''frame-src''' : Define from where the protected resource can embed frames,&lt;br /&gt;
* '''font-src''' : Define from where the protected resource can load fonts,&lt;br /&gt;
* '''connect-src''' : Define which URIs the protected resource can load using script interfaces,&lt;br /&gt;
* '''form-action''' : Define which URIs can be used as the action of HTML form elements,&lt;br /&gt;
* '''sandbox''' : Specifies an HTML sandbox policy that the user agent applies to the protected resource,&lt;br /&gt;
* '''script-nonce''' : Define script execution by requiring the presence of the specified nonce on script elements,&lt;br /&gt;
* '''plugin-types''' : Define the set of plugins that can be invoked by the protected resource by limiting the types of resources that can be embedded,&lt;br /&gt;
* '''reflected-xss''' : Instructs a user agent to activate or disactivate any heuristics used to filter or block reflected cross-site scripting attacks, equivalent to the effects of the non-standard X-XSS-Protection header,&lt;br /&gt;
*  '''report-uri''' : Specifies a URI to which the user agent sends reports about policy violation&lt;br /&gt;
&lt;br /&gt;
An introduction to CSP is available on [http://www.html5rocks.com/en/tutorials/security/content-security-policy/ HTML5Rocks].  The browser support is shown on http://caniuse.com/#feat=contentsecuritypolicy&lt;br /&gt;
&lt;br /&gt;
== Risk ==&lt;br /&gt;
The risk with CSP can have 2 main sources:&lt;br /&gt;
# Policies misconfiguration,&lt;br /&gt;
# Too permissive policies.&lt;br /&gt;
&lt;br /&gt;
== Countermeasure ==&lt;br /&gt;
This article will focus on providing an sample implementation of a JEE Web Filter in order to apply a set of CSP policies on all HTTP response returned by server. &lt;br /&gt;
&lt;br /&gt;
The policies will instructs the browser to have the loading behavior below using all HTTP headers defined in W3C Specs:&lt;br /&gt;
* Explicit loading definition of each resource type,&lt;br /&gt;
* Resources are loaded only from source domain,&lt;br /&gt;
* Inline style is not allowed,&lt;br /&gt;
* For JavaScript:&lt;br /&gt;
** ''Inline script'' will be allowed because inline scripting it's commonly used (can be disabled if target site do not use this type of scripting),&lt;br /&gt;
** ''eval()'' function will be allowed in order to not break use of popular JavaScript libraries (ex: JQuery, JQueryUI, Sencha, ...) because they use eval() function (it was the case last time I have checked the source code from CDN ;) ),&lt;br /&gt;
* Generation of a random not guessable script nonce to use into all script tag,&lt;br /&gt;
* Plugin types only allow PDF and Flash,&lt;br /&gt;
* No font loading (configurable),&lt;br /&gt;
* No Audio / Video loading (configurable),&lt;br /&gt;
* Enable browser XSS filtering feature.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:navy&amp;quot;&amp;gt;&lt;br /&gt;
The support for CSP directives is not the same level in major browsers (Firefox/Chrome/IE). It's recommanded to check the support &lt;br /&gt;
provided by target browsers  (using site provided in link section of this article) in order to configure CSP policies. The sample &lt;br /&gt;
below try to provide a set of policies from which your can add policies specific to your application context.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''This implementation provide an option to add CSP directives used by Firefox (Mozilla CSP directives).''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.security.MessageDigest;&lt;br /&gt;
import java.security.NoSuchAlgorithmException;&lt;br /&gt;
import java.security.SecureRandom;&lt;br /&gt;
import java.util.ArrayList;&lt;br /&gt;
import java.util.List;&lt;br /&gt;
&lt;br /&gt;
import javax.servlet.Filter;&lt;br /&gt;
import javax.servlet.FilterChain;&lt;br /&gt;
import javax.servlet.FilterConfig;&lt;br /&gt;
import javax.servlet.ServletException;&lt;br /&gt;
import javax.servlet.ServletRequest;&lt;br /&gt;
import javax.servlet.ServletResponse;&lt;br /&gt;
import javax.servlet.annotation.WebFilter;&lt;br /&gt;
import javax.servlet.http.HttpServletRequest;&lt;br /&gt;
import javax.servlet.http.HttpServletResponse;&lt;br /&gt;
&lt;br /&gt;
import org.apache.commons.codec.binary.Hex;&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * Sample filter implementation to define a set of Content Security Policies.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 * This implementation has a dependency on Commons Codec API.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 * This filter set CSP policies using all HTTP headers defined into W3C specification.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &amp;lt;br/&amp;gt;&lt;br /&gt;
 * This implementation is oriented to be easily understandable and easily adapted.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
@WebFilter(&amp;quot;/*&amp;quot;)&lt;br /&gt;
public class CSPPoliciesApplier implements Filter {&lt;br /&gt;
&lt;br /&gt;
	/** Configuration member to specify if web app use web fonts */&lt;br /&gt;
	public static final boolean APP_USE_WEBFONTS = false;&lt;br /&gt;
&lt;br /&gt;
	/** Configuration member to specify if web app use videos or audios */&lt;br /&gt;
	public static final boolean APP_USE_AUDIOS_OR_VIDEOS = false;&lt;br /&gt;
&lt;br /&gt;
	/** Configuration member to specify if filter must add CSP directive used by Mozilla (Firefox) */&lt;br /&gt;
	public static final boolean INCLUDE_MOZILLA_CSP_DIRECTIVES = true;&lt;br /&gt;
&lt;br /&gt;
	/** Filter configuration */&lt;br /&gt;
	@SuppressWarnings(&amp;quot;unused&amp;quot;)&lt;br /&gt;
	private FilterConfig filterConfig = null;&lt;br /&gt;
&lt;br /&gt;
	/** List CSP HTTP Headers */&lt;br /&gt;
	private List&amp;lt;String&amp;gt; cspHeaders = new ArrayList&amp;lt;String&amp;gt;();&lt;br /&gt;
&lt;br /&gt;
	/** Collection of CSP polcies that will be applied */&lt;br /&gt;
	private String policies = null;&lt;br /&gt;
&lt;br /&gt;
	/** Used for Script Nonce */&lt;br /&gt;
	private SecureRandom prng = null;&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Used to prepare (one time for all) set of CSP policies that will be applied on each HTTP response.&lt;br /&gt;
	 * &lt;br /&gt;
	 * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)&lt;br /&gt;
	 */&lt;br /&gt;
	@Override&lt;br /&gt;
	public void init(FilterConfig fConfig) throws ServletException {&lt;br /&gt;
		// Get filter configuration&lt;br /&gt;
		this.filterConfig = fConfig;&lt;br /&gt;
&lt;br /&gt;
		// Init secure random&lt;br /&gt;
		try {&lt;br /&gt;
			this.prng = SecureRandom.getInstance(&amp;quot;SHA1PRNG&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		catch (NoSuchAlgorithmException e) {&lt;br /&gt;
			throw new ServletException(e);&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		// Define list of CSP HTTP Headers&lt;br /&gt;
		this.cspHeaders.add(&amp;quot;Content-Security-Policy&amp;quot;);&lt;br /&gt;
		this.cspHeaders.add(&amp;quot;X-Content-Security-Policy&amp;quot;);&lt;br /&gt;
		this.cspHeaders.add(&amp;quot;X-WebKit-CSP&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
		// Define CSP policies&lt;br /&gt;
		// Loading policies for Frame and Sandboxing will be dynamically defined : We need to know if context use Frame&lt;br /&gt;
		List&amp;lt;String&amp;gt; cspPolicies = new ArrayList&amp;lt;String&amp;gt;();&lt;br /&gt;
		String originLocationRef = &amp;quot;'self'&amp;quot;;&lt;br /&gt;
		// --Disable default source in order to avoid browser fallback loading using 'default-src' locations&lt;br /&gt;
		cspPolicies.add(&amp;quot;default-src 'none'&amp;quot;);&lt;br /&gt;
		// --Define loading policies for Scripts&lt;br /&gt;
		cspPolicies.add(&amp;quot;script-src &amp;quot; + originLocationRef + &amp;quot; 'unsafe-inline' 'unsafe-eval'&amp;quot;);&lt;br /&gt;
		if (INCLUDE_MOZILLA_CSP_DIRECTIVES) {&lt;br /&gt;
			cspPolicies.add(&amp;quot;options inline-script eval-script&amp;quot;);&lt;br /&gt;
			cspPolicies.add(&amp;quot;xhr-src 'self'&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		// --Define loading policies for Plugins&lt;br /&gt;
		cspPolicies.add(&amp;quot;object-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Styles (CSS)&lt;br /&gt;
		cspPolicies.add(&amp;quot;style-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Images&lt;br /&gt;
		cspPolicies.add(&amp;quot;img-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Form&lt;br /&gt;
		cspPolicies.add(&amp;quot;form-action &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Audios/Videos&lt;br /&gt;
		if (APP_USE_AUDIOS_OR_VIDEOS) {&lt;br /&gt;
			cspPolicies.add(&amp;quot;media-src &amp;quot; + originLocationRef);&lt;br /&gt;
		}&lt;br /&gt;
		// --Define loading policies for Fonts&lt;br /&gt;
		if (APP_USE_WEBFONTS) {&lt;br /&gt;
			cspPolicies.add(&amp;quot;font-src &amp;quot; + originLocationRef);&lt;br /&gt;
		}&lt;br /&gt;
		// --Define loading policies for Connection&lt;br /&gt;
		cspPolicies.add(&amp;quot;connect-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Plugins Types&lt;br /&gt;
		cspPolicies.add(&amp;quot;plugin-types application/pdf application/x-shockwave-flash&amp;quot;);&lt;br /&gt;
		// --Define browser XSS filtering feature running mode&lt;br /&gt;
		cspPolicies.add(&amp;quot;reflected-xss block&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
		// Target formating&lt;br /&gt;
		this.policies = cspPolicies.toString().replaceAll(&amp;quot;(\\[|\\])&amp;quot;, &amp;quot;&amp;quot;).replaceAll(&amp;quot;,&amp;quot;, &amp;quot;;&amp;quot;).trim();&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Add CSP policies on each HTTP response.&lt;br /&gt;
	 * &lt;br /&gt;
	 * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)&lt;br /&gt;
	 */&lt;br /&gt;
	@Override&lt;br /&gt;
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain fchain) throws IOException, ServletException {&lt;br /&gt;
		HttpServletRequest httpRequest = ((HttpServletRequest) request);&lt;br /&gt;
		HttpServletResponse httpResponse = ((HttpServletResponse) response);&lt;br /&gt;
&lt;br /&gt;
		/* Step 1 : Detect if target resource is a Frame */&lt;br /&gt;
		// Customize here according to your context...&lt;br /&gt;
		boolean isFrame = true;&lt;br /&gt;
&lt;br /&gt;
		/* Step 2 : Add CSP policies to HTTP response */&lt;br /&gt;
		StringBuilder policiesBuffer = new StringBuilder(this.policies);&lt;br /&gt;
&lt;br /&gt;
		// If resource is a frame add Frame/Sandbox CSP policy&lt;br /&gt;
		if (isFrame) {&lt;br /&gt;
			// Frame + Sandbox : Here sandbox allow nothing, customize sandbox options depending on your app....&lt;br /&gt;
			policiesBuffer.append(&amp;quot;;&amp;quot;).append(&amp;quot;frame-src 'self';sandbox&amp;quot;);&lt;br /&gt;
			if (INCLUDE_MOZILLA_CSP_DIRECTIVES) {&lt;br /&gt;
				policiesBuffer.append(&amp;quot;;&amp;quot;).append(&amp;quot;frame-ancestors 'self'&amp;quot;);&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		// Add Script Nonce CSP Policy&lt;br /&gt;
		// --Generate a random number&lt;br /&gt;
		String randomNum = new Integer(this.prng.nextInt()).toString();&lt;br /&gt;
		// --Get its digest&lt;br /&gt;
		MessageDigest sha;&lt;br /&gt;
		try {&lt;br /&gt;
			sha = MessageDigest.getInstance(&amp;quot;SHA-1&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		catch (NoSuchAlgorithmException e) {&lt;br /&gt;
			throw new ServletException(e);&lt;br /&gt;
		}&lt;br /&gt;
		byte[] digest = sha.digest(randomNum.getBytes());&lt;br /&gt;
		// --Encode it into HEXA&lt;br /&gt;
		String scriptNonce = Hex.encodeHexString(digest);&lt;br /&gt;
		policiesBuffer.append(&amp;quot;;&amp;quot;).append(&amp;quot;script-nonce &amp;quot;).append(scriptNonce);&lt;br /&gt;
		// --Made available script nonce in view app layer&lt;br /&gt;
		httpRequest.setAttribute(&amp;quot;CSP_SCRIPT_NONCE&amp;quot;, scriptNonce);&lt;br /&gt;
&lt;br /&gt;
		// Add policies to all HTTP headers&lt;br /&gt;
		for (String header : this.cspHeaders) {&lt;br /&gt;
			httpResponse.setHeader(header, policiesBuffer.toString());&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		/* Step 3 : Let request continue chain filter */&lt;br /&gt;
		fchain.doFilter(request, response);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * {@inheritDoc}&lt;br /&gt;
	 * &lt;br /&gt;
	 * @see javax.servlet.Filter#destroy()&lt;br /&gt;
	 */&lt;br /&gt;
	@Override&lt;br /&gt;
	public void destroy() {&lt;br /&gt;
		// Not used&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
[[Automated Audit using w3af|w3af]] audit tools (http://w3af.org) contain [https://github.com/andresriancho/w3af/blob/master/plugins/grep/csp.py plugin] to automatically audit web application to check if they correctly implement CSP policies. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:#088A08&amp;quot;&amp;gt;&lt;br /&gt;
It's very useful to include this type of tools into a web application development process in order to &lt;br /&gt;
perform a regular automatic first level check (do not replace an manual audit and manual audit must be also conducted regularly).&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can also use  [https://www.oxdef.info/csp-tester CSP Tester (browser extension)] to build and test the policy for your web application.&lt;br /&gt;
&lt;br /&gt;
== Information links ==&lt;br /&gt;
* W3C Specifications: CSP 1.0  - http://www.w3.org/TR/CSP, CSP 1.1 - https://dvcs.w3.org/hg/content-security-policy/raw-file/tip/csp-specification.dev.html&lt;br /&gt;
* Introduction to CSP: http://www.html5rocks.com/en/tutorials/security/content-security-policy&lt;br /&gt;
* CSP browser support: http://caniuse.com/#feat=contentsecuritypolicy&lt;br /&gt;
* CSP readiness browser testing: http://erlend.oftedal.no/blog/csp/readiness/&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP Java Project]]&lt;br /&gt;
[[Category: Injection]]&lt;br /&gt;
[[Category:Attack]]&lt;br /&gt;
[[Category:Injection Attack]]&lt;/div&gt;</summary>
		<author><name>Dimisec</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Content_Security_Policy&amp;diff=169060</id>
		<title>Content Security Policy</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Content_Security_Policy&amp;diff=169060"/>
				<updated>2014-02-27T11:03:31Z</updated>
		
		<summary type="html">&lt;p&gt;Dimisec: a grammar nit (proper verb tense)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Last revision (mm/dd/yy): '''08/31/2013'''&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
'''CSP''' stands for '''C'''ontent '''S'''ecurity '''P'''olicy. &lt;br /&gt;
&lt;br /&gt;
Is an W3C specification offering the possbility to instruct the client browser from which location and/or which type of resources are allowed to be loaded. To define a loading behavior, the CSP specification use &amp;quot;directive&amp;quot; where a directive defines a loading behavior for a target resource type.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This article is based on version [https://dvcs.w3.org/hg/content-security-policy/raw-file/tip/csp-specification.dev.html 1.1] of the W3C specification.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Directives can be specified using HTTP response header (a server may send more than one CSP HTTP header field with a given resource representation and a server may send different CSP header field values with different representations of the same resource or with different resources) or HTML Meta tag, the HTTP headers below are defined by the specs:&lt;br /&gt;
* '''Content-Security-Policy''' : Defined by W3C Specs as standard header, used by Chrome version 25 and later, Firefox version 23 and later, Opera version 19 and later (http://caniuse.com/#search=csp)&lt;br /&gt;
* '''X-Content-Security-Policy''' : Used by Firefox until version 23, and Internet Explorer version 10 (which partially implements Content Security Policy).&lt;br /&gt;
* '''X-WebKit-CSP''' : Used by Chrome until version 25&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The supported directives are:&lt;br /&gt;
* '''default-src''' : Define loading policy for all resources type in case of a resource type dedicated directive is not defined (fallback),&lt;br /&gt;
* '''script-src''' :  Define which scripts the protected resource can execute,&lt;br /&gt;
* '''object-src''' :  Define from where the protected resource can load plugins,&lt;br /&gt;
* '''style-src''' : Define which styles (CSS) the user applies to the protected resource,&lt;br /&gt;
* '''img-src''' : Define from where the protected resource can load images,&lt;br /&gt;
* '''media-src''' : Define from where the protected resource can load video and audio,&lt;br /&gt;
* '''frame-src''' : Define from where the protected resource can embed frames,&lt;br /&gt;
* '''font-src''' : Define from where the protected resource can load fonts,&lt;br /&gt;
* '''connect-src''' : Define which URIs the protected resource can load using script interfaces,&lt;br /&gt;
* '''form-action''' : Define which URIs can be used as the action of HTML form elements,&lt;br /&gt;
* '''sandbox''' : Specifies an HTML sandbox policy that the user agent applies to the protected resource,&lt;br /&gt;
* '''script-nonce''' : Define script execution by requiring the presence of the specified nonce on script elements,&lt;br /&gt;
* '''plugin-types''' : Define the set of plugins that can be invoked by the protected resource by limiting the types of resources that can be embedded,&lt;br /&gt;
* '''reflected-xss''' : Instructs a user agent to activate or disactivate any heuristics used to filter or block reflected cross-site scripting attacks, equivalent to the effects of the non-standard X-XSS-Protection header,&lt;br /&gt;
*  '''report-uri''' : Specifies a URI to which the user agent sends reports about policy violation&lt;br /&gt;
&lt;br /&gt;
An introduction to CSP is available on [http://www.html5rocks.com/en/tutorials/security/content-security-policy/ HTML5Rocks].  The browser support is shown on http://caniuse.com/#feat=contentsecuritypolicy&lt;br /&gt;
&lt;br /&gt;
== Risk ==&lt;br /&gt;
The risk with CSP can have 2 main sources:&lt;br /&gt;
# Policies misconfiguration,&lt;br /&gt;
# Too permissive policies.&lt;br /&gt;
&lt;br /&gt;
== Countermeasure ==&lt;br /&gt;
This article will focus on providing an sample implementation of a JEE Web Filter in order to apply a set of CSP policies on all HTTP response returned by server. &lt;br /&gt;
&lt;br /&gt;
The policies will instructs the browser to have the loading behavior below using all HTTP headers defined in W3C Specs:&lt;br /&gt;
* Explicit loading definition of each resource type,&lt;br /&gt;
* Resources are loaded only from source domain,&lt;br /&gt;
* Inline style is not allowed,&lt;br /&gt;
* For JavaScript:&lt;br /&gt;
** ''Inline script'' will be allowed because inline scripting it's commonly used (can be disabled if target site do not use this type of scripting),&lt;br /&gt;
** ''eval()'' function will be allowed in order to not break use of popular JavaScript libraries (ex: JQuery, JQueryUI, Sencha, ...) because they use eval() function (it was the case last time I have checked the source code from CDN ;) ),&lt;br /&gt;
* Generation of a random not guessable script nonce to use into all script tag,&lt;br /&gt;
* Plugin types only allow PDF and Flash,&lt;br /&gt;
* No font loading (configurable),&lt;br /&gt;
* No Audio / Video loading (configurable),&lt;br /&gt;
* Enable browser XSS filtering feature.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:navy&amp;quot;&amp;gt;&lt;br /&gt;
The support for CSP directives is not the same level in major browsers (Firefox/Chrome/IE). It's recommanded to check the support &lt;br /&gt;
provided by target browsers  (using site provided in link section of this article) in order to configure CSP policies. The sample &lt;br /&gt;
below try to provide a set of policies from which your can add policies specific to your application context.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''This implementation provide an option to add CSP directives used by Firefox (Mozilla CSP directives).''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.security.MessageDigest;&lt;br /&gt;
import java.security.NoSuchAlgorithmException;&lt;br /&gt;
import java.security.SecureRandom;&lt;br /&gt;
import java.util.ArrayList;&lt;br /&gt;
import java.util.List;&lt;br /&gt;
&lt;br /&gt;
import javax.servlet.Filter;&lt;br /&gt;
import javax.servlet.FilterChain;&lt;br /&gt;
import javax.servlet.FilterConfig;&lt;br /&gt;
import javax.servlet.ServletException;&lt;br /&gt;
import javax.servlet.ServletRequest;&lt;br /&gt;
import javax.servlet.ServletResponse;&lt;br /&gt;
import javax.servlet.annotation.WebFilter;&lt;br /&gt;
import javax.servlet.http.HttpServletRequest;&lt;br /&gt;
import javax.servlet.http.HttpServletResponse;&lt;br /&gt;
&lt;br /&gt;
import org.apache.commons.codec.binary.Hex;&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * Sample filter implementation to define a set of Content Security Policies.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 * This implementation has a dependency on Commons Codec API.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 * This filter set CSP policies using all HTTP headers defined into W3C specification.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &amp;lt;br/&amp;gt;&lt;br /&gt;
 * This implementation is oriented to be easily understandable and easily adapted.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
@WebFilter(&amp;quot;/*&amp;quot;)&lt;br /&gt;
public class CSPPoliciesApplier implements Filter {&lt;br /&gt;
&lt;br /&gt;
	/** Configuration member to specify if web app use web fonts */&lt;br /&gt;
	public static final boolean APP_USE_WEBFONTS = false;&lt;br /&gt;
&lt;br /&gt;
	/** Configuration member to specify if web app use videos or audios */&lt;br /&gt;
	public static final boolean APP_USE_AUDIOS_OR_VIDEOS = false;&lt;br /&gt;
&lt;br /&gt;
	/** Configuration member to specify if filter must add CSP directive used by Mozilla (Firefox) */&lt;br /&gt;
	public static final boolean INCLUDE_MOZILLA_CSP_DIRECTIVES = true;&lt;br /&gt;
&lt;br /&gt;
	/** Filter configuration */&lt;br /&gt;
	@SuppressWarnings(&amp;quot;unused&amp;quot;)&lt;br /&gt;
	private FilterConfig filterConfig = null;&lt;br /&gt;
&lt;br /&gt;
	/** List CSP HTTP Headers */&lt;br /&gt;
	private List&amp;lt;String&amp;gt; cspHeaders = new ArrayList&amp;lt;String&amp;gt;();&lt;br /&gt;
&lt;br /&gt;
	/** Collection of CSP polcies that will be applied */&lt;br /&gt;
	private String policies = null;&lt;br /&gt;
&lt;br /&gt;
	/** Used for Script Nonce */&lt;br /&gt;
	private SecureRandom prng = null;&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Used to prepare (one time for all) set of CSP policies that will be applied on each HTTP response.&lt;br /&gt;
	 * &lt;br /&gt;
	 * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)&lt;br /&gt;
	 */&lt;br /&gt;
	@Override&lt;br /&gt;
	public void init(FilterConfig fConfig) throws ServletException {&lt;br /&gt;
		// Get filter configuration&lt;br /&gt;
		this.filterConfig = fConfig;&lt;br /&gt;
&lt;br /&gt;
		// Init secure random&lt;br /&gt;
		try {&lt;br /&gt;
			this.prng = SecureRandom.getInstance(&amp;quot;SHA1PRNG&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		catch (NoSuchAlgorithmException e) {&lt;br /&gt;
			throw new ServletException(e);&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		// Define list of CSP HTTP Headers&lt;br /&gt;
		this.cspHeaders.add(&amp;quot;Content-Security-Policy&amp;quot;);&lt;br /&gt;
		this.cspHeaders.add(&amp;quot;X-Content-Security-Policy&amp;quot;);&lt;br /&gt;
		this.cspHeaders.add(&amp;quot;X-WebKit-CSP&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
		// Define CSP policies&lt;br /&gt;
		// Loading policies for Frame and Sandboxing will be dynamically defined : We need to know if context use Frame&lt;br /&gt;
		List&amp;lt;String&amp;gt; cspPolicies = new ArrayList&amp;lt;String&amp;gt;();&lt;br /&gt;
		String originLocationRef = &amp;quot;'self'&amp;quot;;&lt;br /&gt;
		// --Disable default source in order to avoid browser fallback loading using 'default-src' locations&lt;br /&gt;
		cspPolicies.add(&amp;quot;default-src 'none'&amp;quot;);&lt;br /&gt;
		// --Define loading policies for Scripts&lt;br /&gt;
		cspPolicies.add(&amp;quot;script-src &amp;quot; + originLocationRef + &amp;quot; 'unsafe-inline' 'unsafe-eval'&amp;quot;);&lt;br /&gt;
		if (INCLUDE_MOZILLA_CSP_DIRECTIVES) {&lt;br /&gt;
			cspPolicies.add(&amp;quot;options inline-script eval-script&amp;quot;);&lt;br /&gt;
			cspPolicies.add(&amp;quot;xhr-src 'self'&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		// --Define loading policies for Plugins&lt;br /&gt;
		cspPolicies.add(&amp;quot;object-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Styles (CSS)&lt;br /&gt;
		cspPolicies.add(&amp;quot;style-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Images&lt;br /&gt;
		cspPolicies.add(&amp;quot;img-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Form&lt;br /&gt;
		cspPolicies.add(&amp;quot;form-action &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Audios/Videos&lt;br /&gt;
		if (APP_USE_AUDIOS_OR_VIDEOS) {&lt;br /&gt;
			cspPolicies.add(&amp;quot;media-src &amp;quot; + originLocationRef);&lt;br /&gt;
		}&lt;br /&gt;
		// --Define loading policies for Fonts&lt;br /&gt;
		if (APP_USE_WEBFONTS) {&lt;br /&gt;
			cspPolicies.add(&amp;quot;font-src &amp;quot; + originLocationRef);&lt;br /&gt;
		}&lt;br /&gt;
		// --Define loading policies for Connection&lt;br /&gt;
		cspPolicies.add(&amp;quot;connect-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Plugins Types&lt;br /&gt;
		cspPolicies.add(&amp;quot;plugin-types application/pdf application/x-shockwave-flash&amp;quot;);&lt;br /&gt;
		// --Define browser XSS filtering feature running mode&lt;br /&gt;
		cspPolicies.add(&amp;quot;reflected-xss block&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
		// Target formating&lt;br /&gt;
		this.policies = cspPolicies.toString().replaceAll(&amp;quot;(\\[|\\])&amp;quot;, &amp;quot;&amp;quot;).replaceAll(&amp;quot;,&amp;quot;, &amp;quot;;&amp;quot;).trim();&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Add CSP policies on each HTTP response.&lt;br /&gt;
	 * &lt;br /&gt;
	 * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)&lt;br /&gt;
	 */&lt;br /&gt;
	@Override&lt;br /&gt;
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain fchain) throws IOException, ServletException {&lt;br /&gt;
		HttpServletRequest httpRequest = ((HttpServletRequest) request);&lt;br /&gt;
		HttpServletResponse httpResponse = ((HttpServletResponse) response);&lt;br /&gt;
&lt;br /&gt;
		/* Step 1 : Detect if target resource is a Frame */&lt;br /&gt;
		// Customize here according to your context...&lt;br /&gt;
		boolean isFrame = true;&lt;br /&gt;
&lt;br /&gt;
		/* Step 2 : Add CSP policies to HTTP response */&lt;br /&gt;
		StringBuilder policiesBuffer = new StringBuilder(this.policies);&lt;br /&gt;
&lt;br /&gt;
		// If resource is a frame add Frame/Sandbox CSP policy&lt;br /&gt;
		if (isFrame) {&lt;br /&gt;
			// Frame + Sandbox : Here sandbox allow nothing, customize sandbox options depending on your app....&lt;br /&gt;
			policiesBuffer.append(&amp;quot;;&amp;quot;).append(&amp;quot;frame-src 'self';sandbox&amp;quot;);&lt;br /&gt;
			if (INCLUDE_MOZILLA_CSP_DIRECTIVES) {&lt;br /&gt;
				policiesBuffer.append(&amp;quot;;&amp;quot;).append(&amp;quot;frame-ancestors 'self'&amp;quot;);&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		// Add Script Nonce CSP Policy&lt;br /&gt;
		// --Generate a random number&lt;br /&gt;
		String randomNum = new Integer(this.prng.nextInt()).toString();&lt;br /&gt;
		// --Get its digest&lt;br /&gt;
		MessageDigest sha;&lt;br /&gt;
		try {&lt;br /&gt;
			sha = MessageDigest.getInstance(&amp;quot;SHA-1&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		catch (NoSuchAlgorithmException e) {&lt;br /&gt;
			throw new ServletException(e);&lt;br /&gt;
		}&lt;br /&gt;
		byte[] digest = sha.digest(randomNum.getBytes());&lt;br /&gt;
		// --Encode it into HEXA&lt;br /&gt;
		String scriptNonce = Hex.encodeHexString(digest);&lt;br /&gt;
		policiesBuffer.append(&amp;quot;;&amp;quot;).append(&amp;quot;script-nonce &amp;quot;).append(scriptNonce);&lt;br /&gt;
		// --Made available script nonce in view app layer&lt;br /&gt;
		httpRequest.setAttribute(&amp;quot;CSP_SCRIPT_NONCE&amp;quot;, scriptNonce);&lt;br /&gt;
&lt;br /&gt;
		// Add policies to all HTTP headers&lt;br /&gt;
		for (String header : this.cspHeaders) {&lt;br /&gt;
			httpResponse.setHeader(header, policiesBuffer.toString());&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		/* Step 3 : Let request continue chain filter */&lt;br /&gt;
		fchain.doFilter(request, response);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * {@inheritDoc}&lt;br /&gt;
	 * &lt;br /&gt;
	 * @see javax.servlet.Filter#destroy()&lt;br /&gt;
	 */&lt;br /&gt;
	@Override&lt;br /&gt;
	public void destroy() {&lt;br /&gt;
		// Not used&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
[[Automated Audit using w3af|w3af]] audit tools (http://w3af.org) contain [https://github.com/andresriancho/w3af/blob/master/plugins/grep/csp.py plugin] to automatically audit web application to check if they correctly implement CSP policies. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:#088A08&amp;quot;&amp;gt;&lt;br /&gt;
It's very useful to include this type of tools into a web application development process in order to &lt;br /&gt;
perform a regular automatic first level check (do not replace an manual audit and manual audit must be also conducted regularly).&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can also use  [https://www.oxdef.info/csp-tester CSP Tester (browser extension)] to build and test the policy for your web application.&lt;br /&gt;
&lt;br /&gt;
== Information links ==&lt;br /&gt;
* W3C Specifications: CSP 1.0  - http://www.w3.org/TR/CSP, CSP 1.1 - https://dvcs.w3.org/hg/content-security-policy/raw-file/tip/csp-specification.dev.html&lt;br /&gt;
* Introduction to CSP: http://www.html5rocks.com/en/tutorials/security/content-security-policy&lt;br /&gt;
* CSP browser support: http://caniuse.com/#feat=contentsecuritypolicy&lt;br /&gt;
* CSP readiness browser testing: http://erlend.oftedal.no/blog/csp/readiness/&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP Java Project]]&lt;br /&gt;
[[Category: Injection]]&lt;br /&gt;
[[Category:Attack]]&lt;br /&gt;
[[Category:Injection Attack]]&lt;/div&gt;</summary>
		<author><name>Dimisec</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Content_Security_Policy&amp;diff=169059</id>
		<title>Content Security Policy</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Content_Security_Policy&amp;diff=169059"/>
				<updated>2014-02-27T11:02:47Z</updated>
		
		<summary type="html">&lt;p&gt;Dimisec: added reference to Opera versions supporting CSP and a link to the source - caniuse.com&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Last revision (mm/dd/yy): '''08/31/2013'''&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
'''CSP''' stands for '''C'''ontent '''S'''ecurity '''P'''olicy. &lt;br /&gt;
&lt;br /&gt;
Is an W3C specification offering the possbility to instruct the client browser from which location and/or which type of resources are allowed to be loaded. To define a loading behavior, the CSP specification use &amp;quot;directive&amp;quot; where a directive define a loading behavior for a target resource type.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This article is based on version [https://dvcs.w3.org/hg/content-security-policy/raw-file/tip/csp-specification.dev.html 1.1] of the W3C specification.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Directives can be specified using HTTP response header (a server may send more than one CSP HTTP header field with a given resource representation and a server may send different CSP header field values with different representations of the same resource or with different resources) or HTML Meta tag, the HTTP headers below are defined by the specs:&lt;br /&gt;
* '''Content-Security-Policy''' : Defined by W3C Specs as standard header, used by Chrome version 25 and later, Firefox version 23 and later, Opera version 19 and later (http://caniuse.com/#search=csp)&lt;br /&gt;
* '''X-Content-Security-Policy''' : Used by Firefox until version 23, and Internet Explorer version 10 (which partially implements Content Security Policy).&lt;br /&gt;
* '''X-WebKit-CSP''' : Used by Chrome until version 25&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The supported directives are:&lt;br /&gt;
* '''default-src''' : Define loading policy for all resources type in case of a resource type dedicated directive is not defined (fallback),&lt;br /&gt;
* '''script-src''' :  Define which scripts the protected resource can execute,&lt;br /&gt;
* '''object-src''' :  Define from where the protected resource can load plugins,&lt;br /&gt;
* '''style-src''' : Define which styles (CSS) the user applies to the protected resource,&lt;br /&gt;
* '''img-src''' : Define from where the protected resource can load images,&lt;br /&gt;
* '''media-src''' : Define from where the protected resource can load video and audio,&lt;br /&gt;
* '''frame-src''' : Define from where the protected resource can embed frames,&lt;br /&gt;
* '''font-src''' : Define from where the protected resource can load fonts,&lt;br /&gt;
* '''connect-src''' : Define which URIs the protected resource can load using script interfaces,&lt;br /&gt;
* '''form-action''' : Define which URIs can be used as the action of HTML form elements,&lt;br /&gt;
* '''sandbox''' : Specifies an HTML sandbox policy that the user agent applies to the protected resource,&lt;br /&gt;
* '''script-nonce''' : Define script execution by requiring the presence of the specified nonce on script elements,&lt;br /&gt;
* '''plugin-types''' : Define the set of plugins that can be invoked by the protected resource by limiting the types of resources that can be embedded,&lt;br /&gt;
* '''reflected-xss''' : Instructs a user agent to activate or disactivate any heuristics used to filter or block reflected cross-site scripting attacks, equivalent to the effects of the non-standard X-XSS-Protection header,&lt;br /&gt;
*  '''report-uri''' : Specifies a URI to which the user agent sends reports about policy violation&lt;br /&gt;
&lt;br /&gt;
An introduction to CSP is available on [http://www.html5rocks.com/en/tutorials/security/content-security-policy/ HTML5Rocks].  The browser support is shown on http://caniuse.com/#feat=contentsecuritypolicy&lt;br /&gt;
&lt;br /&gt;
== Risk ==&lt;br /&gt;
The risk with CSP can have 2 main sources:&lt;br /&gt;
# Policies misconfiguration,&lt;br /&gt;
# Too permissive policies.&lt;br /&gt;
&lt;br /&gt;
== Countermeasure ==&lt;br /&gt;
This article will focus on providing an sample implementation of a JEE Web Filter in order to apply a set of CSP policies on all HTTP response returned by server. &lt;br /&gt;
&lt;br /&gt;
The policies will instructs the browser to have the loading behavior below using all HTTP headers defined in W3C Specs:&lt;br /&gt;
* Explicit loading definition of each resource type,&lt;br /&gt;
* Resources are loaded only from source domain,&lt;br /&gt;
* Inline style is not allowed,&lt;br /&gt;
* For JavaScript:&lt;br /&gt;
** ''Inline script'' will be allowed because inline scripting it's commonly used (can be disabled if target site do not use this type of scripting),&lt;br /&gt;
** ''eval()'' function will be allowed in order to not break use of popular JavaScript libraries (ex: JQuery, JQueryUI, Sencha, ...) because they use eval() function (it was the case last time I have checked the source code from CDN ;) ),&lt;br /&gt;
* Generation of a random not guessable script nonce to use into all script tag,&lt;br /&gt;
* Plugin types only allow PDF and Flash,&lt;br /&gt;
* No font loading (configurable),&lt;br /&gt;
* No Audio / Video loading (configurable),&lt;br /&gt;
* Enable browser XSS filtering feature.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:navy&amp;quot;&amp;gt;&lt;br /&gt;
The support for CSP directives is not the same level in major browsers (Firefox/Chrome/IE). It's recommanded to check the support &lt;br /&gt;
provided by target browsers  (using site provided in link section of this article) in order to configure CSP policies. The sample &lt;br /&gt;
below try to provide a set of policies from which your can add policies specific to your application context.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''This implementation provide an option to add CSP directives used by Firefox (Mozilla CSP directives).''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.security.MessageDigest;&lt;br /&gt;
import java.security.NoSuchAlgorithmException;&lt;br /&gt;
import java.security.SecureRandom;&lt;br /&gt;
import java.util.ArrayList;&lt;br /&gt;
import java.util.List;&lt;br /&gt;
&lt;br /&gt;
import javax.servlet.Filter;&lt;br /&gt;
import javax.servlet.FilterChain;&lt;br /&gt;
import javax.servlet.FilterConfig;&lt;br /&gt;
import javax.servlet.ServletException;&lt;br /&gt;
import javax.servlet.ServletRequest;&lt;br /&gt;
import javax.servlet.ServletResponse;&lt;br /&gt;
import javax.servlet.annotation.WebFilter;&lt;br /&gt;
import javax.servlet.http.HttpServletRequest;&lt;br /&gt;
import javax.servlet.http.HttpServletResponse;&lt;br /&gt;
&lt;br /&gt;
import org.apache.commons.codec.binary.Hex;&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * Sample filter implementation to define a set of Content Security Policies.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 * This implementation has a dependency on Commons Codec API.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 * This filter set CSP policies using all HTTP headers defined into W3C specification.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &amp;lt;br/&amp;gt;&lt;br /&gt;
 * This implementation is oriented to be easily understandable and easily adapted.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
@WebFilter(&amp;quot;/*&amp;quot;)&lt;br /&gt;
public class CSPPoliciesApplier implements Filter {&lt;br /&gt;
&lt;br /&gt;
	/** Configuration member to specify if web app use web fonts */&lt;br /&gt;
	public static final boolean APP_USE_WEBFONTS = false;&lt;br /&gt;
&lt;br /&gt;
	/** Configuration member to specify if web app use videos or audios */&lt;br /&gt;
	public static final boolean APP_USE_AUDIOS_OR_VIDEOS = false;&lt;br /&gt;
&lt;br /&gt;
	/** Configuration member to specify if filter must add CSP directive used by Mozilla (Firefox) */&lt;br /&gt;
	public static final boolean INCLUDE_MOZILLA_CSP_DIRECTIVES = true;&lt;br /&gt;
&lt;br /&gt;
	/** Filter configuration */&lt;br /&gt;
	@SuppressWarnings(&amp;quot;unused&amp;quot;)&lt;br /&gt;
	private FilterConfig filterConfig = null;&lt;br /&gt;
&lt;br /&gt;
	/** List CSP HTTP Headers */&lt;br /&gt;
	private List&amp;lt;String&amp;gt; cspHeaders = new ArrayList&amp;lt;String&amp;gt;();&lt;br /&gt;
&lt;br /&gt;
	/** Collection of CSP polcies that will be applied */&lt;br /&gt;
	private String policies = null;&lt;br /&gt;
&lt;br /&gt;
	/** Used for Script Nonce */&lt;br /&gt;
	private SecureRandom prng = null;&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Used to prepare (one time for all) set of CSP policies that will be applied on each HTTP response.&lt;br /&gt;
	 * &lt;br /&gt;
	 * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)&lt;br /&gt;
	 */&lt;br /&gt;
	@Override&lt;br /&gt;
	public void init(FilterConfig fConfig) throws ServletException {&lt;br /&gt;
		// Get filter configuration&lt;br /&gt;
		this.filterConfig = fConfig;&lt;br /&gt;
&lt;br /&gt;
		// Init secure random&lt;br /&gt;
		try {&lt;br /&gt;
			this.prng = SecureRandom.getInstance(&amp;quot;SHA1PRNG&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		catch (NoSuchAlgorithmException e) {&lt;br /&gt;
			throw new ServletException(e);&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		// Define list of CSP HTTP Headers&lt;br /&gt;
		this.cspHeaders.add(&amp;quot;Content-Security-Policy&amp;quot;);&lt;br /&gt;
		this.cspHeaders.add(&amp;quot;X-Content-Security-Policy&amp;quot;);&lt;br /&gt;
		this.cspHeaders.add(&amp;quot;X-WebKit-CSP&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
		// Define CSP policies&lt;br /&gt;
		// Loading policies for Frame and Sandboxing will be dynamically defined : We need to know if context use Frame&lt;br /&gt;
		List&amp;lt;String&amp;gt; cspPolicies = new ArrayList&amp;lt;String&amp;gt;();&lt;br /&gt;
		String originLocationRef = &amp;quot;'self'&amp;quot;;&lt;br /&gt;
		// --Disable default source in order to avoid browser fallback loading using 'default-src' locations&lt;br /&gt;
		cspPolicies.add(&amp;quot;default-src 'none'&amp;quot;);&lt;br /&gt;
		// --Define loading policies for Scripts&lt;br /&gt;
		cspPolicies.add(&amp;quot;script-src &amp;quot; + originLocationRef + &amp;quot; 'unsafe-inline' 'unsafe-eval'&amp;quot;);&lt;br /&gt;
		if (INCLUDE_MOZILLA_CSP_DIRECTIVES) {&lt;br /&gt;
			cspPolicies.add(&amp;quot;options inline-script eval-script&amp;quot;);&lt;br /&gt;
			cspPolicies.add(&amp;quot;xhr-src 'self'&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		// --Define loading policies for Plugins&lt;br /&gt;
		cspPolicies.add(&amp;quot;object-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Styles (CSS)&lt;br /&gt;
		cspPolicies.add(&amp;quot;style-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Images&lt;br /&gt;
		cspPolicies.add(&amp;quot;img-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Form&lt;br /&gt;
		cspPolicies.add(&amp;quot;form-action &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Audios/Videos&lt;br /&gt;
		if (APP_USE_AUDIOS_OR_VIDEOS) {&lt;br /&gt;
			cspPolicies.add(&amp;quot;media-src &amp;quot; + originLocationRef);&lt;br /&gt;
		}&lt;br /&gt;
		// --Define loading policies for Fonts&lt;br /&gt;
		if (APP_USE_WEBFONTS) {&lt;br /&gt;
			cspPolicies.add(&amp;quot;font-src &amp;quot; + originLocationRef);&lt;br /&gt;
		}&lt;br /&gt;
		// --Define loading policies for Connection&lt;br /&gt;
		cspPolicies.add(&amp;quot;connect-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Plugins Types&lt;br /&gt;
		cspPolicies.add(&amp;quot;plugin-types application/pdf application/x-shockwave-flash&amp;quot;);&lt;br /&gt;
		// --Define browser XSS filtering feature running mode&lt;br /&gt;
		cspPolicies.add(&amp;quot;reflected-xss block&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
		// Target formating&lt;br /&gt;
		this.policies = cspPolicies.toString().replaceAll(&amp;quot;(\\[|\\])&amp;quot;, &amp;quot;&amp;quot;).replaceAll(&amp;quot;,&amp;quot;, &amp;quot;;&amp;quot;).trim();&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Add CSP policies on each HTTP response.&lt;br /&gt;
	 * &lt;br /&gt;
	 * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)&lt;br /&gt;
	 */&lt;br /&gt;
	@Override&lt;br /&gt;
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain fchain) throws IOException, ServletException {&lt;br /&gt;
		HttpServletRequest httpRequest = ((HttpServletRequest) request);&lt;br /&gt;
		HttpServletResponse httpResponse = ((HttpServletResponse) response);&lt;br /&gt;
&lt;br /&gt;
		/* Step 1 : Detect if target resource is a Frame */&lt;br /&gt;
		// Customize here according to your context...&lt;br /&gt;
		boolean isFrame = true;&lt;br /&gt;
&lt;br /&gt;
		/* Step 2 : Add CSP policies to HTTP response */&lt;br /&gt;
		StringBuilder policiesBuffer = new StringBuilder(this.policies);&lt;br /&gt;
&lt;br /&gt;
		// If resource is a frame add Frame/Sandbox CSP policy&lt;br /&gt;
		if (isFrame) {&lt;br /&gt;
			// Frame + Sandbox : Here sandbox allow nothing, customize sandbox options depending on your app....&lt;br /&gt;
			policiesBuffer.append(&amp;quot;;&amp;quot;).append(&amp;quot;frame-src 'self';sandbox&amp;quot;);&lt;br /&gt;
			if (INCLUDE_MOZILLA_CSP_DIRECTIVES) {&lt;br /&gt;
				policiesBuffer.append(&amp;quot;;&amp;quot;).append(&amp;quot;frame-ancestors 'self'&amp;quot;);&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		// Add Script Nonce CSP Policy&lt;br /&gt;
		// --Generate a random number&lt;br /&gt;
		String randomNum = new Integer(this.prng.nextInt()).toString();&lt;br /&gt;
		// --Get its digest&lt;br /&gt;
		MessageDigest sha;&lt;br /&gt;
		try {&lt;br /&gt;
			sha = MessageDigest.getInstance(&amp;quot;SHA-1&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		catch (NoSuchAlgorithmException e) {&lt;br /&gt;
			throw new ServletException(e);&lt;br /&gt;
		}&lt;br /&gt;
		byte[] digest = sha.digest(randomNum.getBytes());&lt;br /&gt;
		// --Encode it into HEXA&lt;br /&gt;
		String scriptNonce = Hex.encodeHexString(digest);&lt;br /&gt;
		policiesBuffer.append(&amp;quot;;&amp;quot;).append(&amp;quot;script-nonce &amp;quot;).append(scriptNonce);&lt;br /&gt;
		// --Made available script nonce in view app layer&lt;br /&gt;
		httpRequest.setAttribute(&amp;quot;CSP_SCRIPT_NONCE&amp;quot;, scriptNonce);&lt;br /&gt;
&lt;br /&gt;
		// Add policies to all HTTP headers&lt;br /&gt;
		for (String header : this.cspHeaders) {&lt;br /&gt;
			httpResponse.setHeader(header, policiesBuffer.toString());&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		/* Step 3 : Let request continue chain filter */&lt;br /&gt;
		fchain.doFilter(request, response);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * {@inheritDoc}&lt;br /&gt;
	 * &lt;br /&gt;
	 * @see javax.servlet.Filter#destroy()&lt;br /&gt;
	 */&lt;br /&gt;
	@Override&lt;br /&gt;
	public void destroy() {&lt;br /&gt;
		// Not used&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
&lt;br /&gt;
[[Automated Audit using w3af|w3af]] audit tools (http://w3af.org) contain [https://github.com/andresriancho/w3af/blob/master/plugins/grep/csp.py plugin] to automatically audit web application to check if they correctly implement CSP policies. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:#088A08&amp;quot;&amp;gt;&lt;br /&gt;
It's very useful to include this type of tools into a web application development process in order to &lt;br /&gt;
perform a regular automatic first level check (do not replace an manual audit and manual audit must be also conducted regularly).&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can also use  [https://www.oxdef.info/csp-tester CSP Tester (browser extension)] to build and test the policy for your web application.&lt;br /&gt;
&lt;br /&gt;
== Information links ==&lt;br /&gt;
* W3C Specifications: CSP 1.0  - http://www.w3.org/TR/CSP, CSP 1.1 - https://dvcs.w3.org/hg/content-security-policy/raw-file/tip/csp-specification.dev.html&lt;br /&gt;
* Introduction to CSP: http://www.html5rocks.com/en/tutorials/security/content-security-policy&lt;br /&gt;
* CSP browser support: http://caniuse.com/#feat=contentsecuritypolicy&lt;br /&gt;
* CSP readiness browser testing: http://erlend.oftedal.no/blog/csp/readiness/&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP Java Project]]&lt;br /&gt;
[[Category: Injection]]&lt;br /&gt;
[[Category:Attack]]&lt;br /&gt;
[[Category:Injection Attack]]&lt;/div&gt;</summary>
		<author><name>Dimisec</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Talk:Content_Security_Policy&amp;diff=150707</id>
		<title>Talk:Content Security Policy</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Talk:Content_Security_Policy&amp;diff=150707"/>
				<updated>2013-04-30T09:49:00Z</updated>
		
		<summary type="html">&lt;p&gt;Dimisec: 1.0 vs 1.1 W3C spec&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;I don't think this belongs correctly to the OWASP Java Project since CSP deals with browser security and server-client protocol (HTTP headers), independently of the specific server implementation. You can send the CSP headers from any possible HTTP server - Java, ASP, PHP/Apache, NodeJS etc.  Personally, I find that the lengthy Java implementation example may distract from the main issues and the choices / tradeoffs that people thinking about implementing the CSP in their sites would have to make.  Also, regarding the following:&lt;br /&gt;
&lt;br /&gt;
&amp;gt; Inline script will be allowed because inline scripting it's commonly used (can be disabled if target site do not use this type of scripting)&lt;br /&gt;
&lt;br /&gt;
I think this does not make it clear that unsafe-inline removes a lot of anti-XSS protection and therefore most of the benefits of using the CSP.&lt;br /&gt;
&lt;br /&gt;
&amp;gt; This article is based on version 1.1 of the W3C specification.&lt;br /&gt;
I believe 1.1 is not yet fully complete, and the implementations are based mostly on 1.0 (need to double-check).  I think 1.0 would be the better fit for this page - need to look into how significant the changes are.&lt;/div&gt;</summary>
		<author><name>Dimisec</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Talk:Content_Security_Policy&amp;diff=150705</id>
		<title>Talk:Content Security Policy</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Talk:Content_Security_Policy&amp;diff=150705"/>
				<updated>2013-04-30T09:44:52Z</updated>
		
		<summary type="html">&lt;p&gt;Dimisec: discussion of the CSP page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;I don't think this belongs correctly to the OWASP Java Project since CSP deals with browser security and server-client protocol (HTTP headers), independently of the specific server implementation. You can send the CSP headers from any possible HTTP server - Java, ASP, PHP/Apache, NodeJS etc.  Personally, I find that the lengthy Java implementation example may distract from the main issues and the choices / tradeoffs that people thinking about implementing the CSP in their sites would have to make.  Also, regarding the following:&lt;br /&gt;
&lt;br /&gt;
&amp;gt; Inline script will be allowed because inline scripting it's commonly used (can be disabled if target site do not use this type of scripting)&lt;br /&gt;
&lt;br /&gt;
I think this does not make it clear that unsafe-inline removes a lot of anti-XSS protection and therefore most of the benefits of using the CSP.&lt;/div&gt;</summary>
		<author><name>Dimisec</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Content_Security_Policy&amp;diff=150704</id>
		<title>Content Security Policy</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Content_Security_Policy&amp;diff=150704"/>
				<updated>2013-04-30T09:32:39Z</updated>
		
		<summary type="html">&lt;p&gt;Dimisec: removed the deprecated Mozilla CSP proposal (clearly superseded by the the W3C spec)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Last revision (mm/dd/yy): '''02/03/2013'''&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
'''CSP''' stands for '''C'''ontent '''S'''ecurity '''P'''olicy. &lt;br /&gt;
&lt;br /&gt;
Is an W3C specification offering the possbility to instruct the client browser from which location and/or which type of resources are allowed to be loaded. To define a loading behavior, the CSP specification use &amp;quot;directive&amp;quot; where a directive define a loading behavior for a target resource type.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This article is based on version [https://dvcs.w3.org/hg/content-security-policy/raw-file/tip/csp-specification.dev.html 1.1] of the W3C specification.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Directives can be specified using HTTP response header (a server may send more than one CSP HTTP header field with a given resource representation and a server may send different CSP header field values with different representations of the same resource or with different resources) or HTML Meta tag, the HTTP headers below are defined by the specs:&lt;br /&gt;
* '''Content-Security-Policy''' : Defined by W3C Specs as standard header, used by Chrome starting with version 25&lt;br /&gt;
* '''X-Content-Security-Policy''' : Used by Firefox and Internet Explorer,&lt;br /&gt;
* '''X-WebKit-CSP''' : Used by Chrome (will transition to Content-Security-Policy)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The supported directives are:&lt;br /&gt;
* '''default-src''' : Define loading policy for all resources type in case of a resource type dedicated directive is not defined (fallback),&lt;br /&gt;
* '''script-src''' :  Define which scripts the protected resource can execute,&lt;br /&gt;
* '''object-src''' :  Define from where the protected resource can load plugins,&lt;br /&gt;
* '''style-src''' : Define which styles (CSS) the user applies to the protected resource,&lt;br /&gt;
* '''img-src''' : Define from where the protected resource can load images,&lt;br /&gt;
* '''media-src''' : Define from where the protected resource can load video and audio,&lt;br /&gt;
* '''frame-src''' : Define from where the protected resource can embed frames,&lt;br /&gt;
* '''font-src''' : Define from where the protected resource can load fonts,&lt;br /&gt;
* '''connect-src''' : Define which URIs the protected resource can load using script interfaces,&lt;br /&gt;
* '''form-action''' : Define which URIs can be used as the action of HTML form elements,&lt;br /&gt;
* '''sandbox''' : Specifies an HTML sandbox policy that the user agent applies to the protected resource,&lt;br /&gt;
* '''script-nonce''' : Define script execution by requiring the presence of the specified nonce on script elements,&lt;br /&gt;
* '''plugin-types''' : Define the set of plugins that can be invoked by the protected resource by limiting the types of resources that can be embedded,&lt;br /&gt;
* '''reflected-xss''' : Instructs a user agent to activate or disactivate any heuristics used to filter or block reflected cross-site scripting attacks, equivalent to the effects of the non-standard X-XSS-Protection header,&lt;br /&gt;
*  '''report-uri''' : Specifies a URI to which the user agent sends reports about policy violation&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An introduction to CSP is available on [http://www.html5rocks.com/en/tutorials/security/content-security-policy/ HTML5Rocks].  The browser support is shown on http://caniuse.com/#feat=contentsecuritypolicy&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Risk ==&lt;br /&gt;
The risk with CSP can have 2 main sources:&lt;br /&gt;
# Policies misconfiguration,&lt;br /&gt;
# Too permissive policies.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Countermeasure ==&lt;br /&gt;
This article will focus on providing an sample implementation of a JEE Web Filter in order to apply a set of CSP policies on all HTTP response returned by server. &lt;br /&gt;
&lt;br /&gt;
The policies will instructs the browser to have the loading behavior below using all HTTP headers defined in W3C Specs:&lt;br /&gt;
* Explicit loading definition of each resource type,&lt;br /&gt;
* Resources are loaded only from source domain,&lt;br /&gt;
* Inline style is not allowed,&lt;br /&gt;
* For JavaScript:&lt;br /&gt;
** ''Inline script'' will be allowed because inline scripting it's commonly used (can be disabled if target site do not use this type of scripting),&lt;br /&gt;
** ''eval()'' function will be allowed in order to not break use of popular JavaScript libraries (ex: JQuery, JQueryUI, Sencha, ...) because they use eval() function (it was the case last time I have checked the source code from CDN ;) ),&lt;br /&gt;
* Generation of a random not guessable script nonce to use into all script tag,&lt;br /&gt;
* Plugin types only allow PDF and Flash,&lt;br /&gt;
* No font loading (configurable),&lt;br /&gt;
* No Audio / Video loading (configurable),&lt;br /&gt;
* Enable browser XSS filtering feature.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:navy&amp;quot;&amp;gt;&lt;br /&gt;
The support for CSP directives is not the same level in major browsers (Firefox/Chrome/IE). It's recommanded to check the support &lt;br /&gt;
provided by target browsers  (using site provided in link section of this article) in order to configure CSP policies. The sample &lt;br /&gt;
below try to provide a set of policies from which your can add policies specific to your application context.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''This implementation provide an option to add CSP directives used by Firefox (Mozilla CSP directives).''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.security.MessageDigest;&lt;br /&gt;
import java.security.NoSuchAlgorithmException;&lt;br /&gt;
import java.security.SecureRandom;&lt;br /&gt;
import java.util.ArrayList;&lt;br /&gt;
import java.util.List;&lt;br /&gt;
&lt;br /&gt;
import javax.servlet.Filter;&lt;br /&gt;
import javax.servlet.FilterChain;&lt;br /&gt;
import javax.servlet.FilterConfig;&lt;br /&gt;
import javax.servlet.ServletException;&lt;br /&gt;
import javax.servlet.ServletRequest;&lt;br /&gt;
import javax.servlet.ServletResponse;&lt;br /&gt;
import javax.servlet.annotation.WebFilter;&lt;br /&gt;
import javax.servlet.http.HttpServletRequest;&lt;br /&gt;
import javax.servlet.http.HttpServletResponse;&lt;br /&gt;
&lt;br /&gt;
import org.apache.commons.codec.binary.Hex;&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * Sample filter implementation to define a set of Content Security Policies.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 * This implementation has a dependency on Commons Codec API.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 * This filter set CSP policies using all HTTP headers defined into W3C specification.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &amp;lt;br/&amp;gt;&lt;br /&gt;
 * This implementation is oriented to be easily understandable and easily adapted.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
@WebFilter(&amp;quot;/*&amp;quot;)&lt;br /&gt;
public class CSPPoliciesApplier implements Filter {&lt;br /&gt;
&lt;br /&gt;
	/** Configuration member to specify if web app use web fonts */&lt;br /&gt;
	public static final boolean APP_USE_WEBFONTS = false;&lt;br /&gt;
&lt;br /&gt;
	/** Configuration member to specify if web app use videos or audios */&lt;br /&gt;
	public static final boolean APP_USE_AUDIOS_OR_VIDEOS = false;&lt;br /&gt;
&lt;br /&gt;
	/** Configuration member to specify if filter must add CSP directive used by Mozilla (Firefox) */&lt;br /&gt;
	public static final boolean INCLUDE_MOZILLA_CSP_DIRECTIVES = true;&lt;br /&gt;
&lt;br /&gt;
	/** Filter configuration */&lt;br /&gt;
	@SuppressWarnings(&amp;quot;unused&amp;quot;)&lt;br /&gt;
	private FilterConfig filterConfig = null;&lt;br /&gt;
&lt;br /&gt;
	/** List CSP HTTP Headers */&lt;br /&gt;
	private List&amp;lt;String&amp;gt; cspHeaders = new ArrayList&amp;lt;String&amp;gt;();&lt;br /&gt;
&lt;br /&gt;
	/** Collection of CSP polcies that will be applied */&lt;br /&gt;
	private String policies = null;&lt;br /&gt;
&lt;br /&gt;
	/** Used for Script Nonce */&lt;br /&gt;
	private SecureRandom prng = null;&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Used to prepare (one time for all) set of CSP policies that will be applied on each HTTP response.&lt;br /&gt;
	 * &lt;br /&gt;
	 * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)&lt;br /&gt;
	 */&lt;br /&gt;
	@Override&lt;br /&gt;
	public void init(FilterConfig fConfig) throws ServletException {&lt;br /&gt;
		// Get filter configuration&lt;br /&gt;
		this.filterConfig = fConfig;&lt;br /&gt;
&lt;br /&gt;
		// Init secure random&lt;br /&gt;
		try {&lt;br /&gt;
			this.prng = SecureRandom.getInstance(&amp;quot;SHA1PRNG&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		catch (NoSuchAlgorithmException e) {&lt;br /&gt;
			throw new ServletException(e);&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		// Define list of CSP HTTP Headers&lt;br /&gt;
		this.cspHeaders.add(&amp;quot;Content-Security-Policy&amp;quot;);&lt;br /&gt;
		this.cspHeaders.add(&amp;quot;X-Content-Security-Policy&amp;quot;);&lt;br /&gt;
		this.cspHeaders.add(&amp;quot;X-WebKit-CSP&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
		// Define CSP policies&lt;br /&gt;
		// Loading policies for Frame and Sandboxing will be dynamically defined : We need to know if context use Frame&lt;br /&gt;
		List&amp;lt;String&amp;gt; cspPolicies = new ArrayList&amp;lt;String&amp;gt;();&lt;br /&gt;
		String originLocationRef = &amp;quot;'self'&amp;quot;;&lt;br /&gt;
		// --Disable default source in order to avoid browser fallback loading using 'default-src' locations&lt;br /&gt;
		cspPolicies.add(&amp;quot;default-src 'none'&amp;quot;);&lt;br /&gt;
		// --Define loading policies for Scripts&lt;br /&gt;
		cspPolicies.add(&amp;quot;script-src &amp;quot; + originLocationRef + &amp;quot; 'unsafe-inline' 'unsafe-eval'&amp;quot;);&lt;br /&gt;
		if (INCLUDE_MOZILLA_CSP_DIRECTIVES) {&lt;br /&gt;
			cspPolicies.add(&amp;quot;options inline-script eval-script&amp;quot;);&lt;br /&gt;
			cspPolicies.add(&amp;quot;xhr-src 'self'&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		// --Define loading policies for Plugins&lt;br /&gt;
		cspPolicies.add(&amp;quot;object-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Styles (CSS)&lt;br /&gt;
		cspPolicies.add(&amp;quot;style-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Images&lt;br /&gt;
		cspPolicies.add(&amp;quot;img-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Form&lt;br /&gt;
		cspPolicies.add(&amp;quot;form-action &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Audios/Videos&lt;br /&gt;
		if (APP_USE_AUDIOS_OR_VIDEOS) {&lt;br /&gt;
			cspPolicies.add(&amp;quot;media-src &amp;quot; + originLocationRef);&lt;br /&gt;
		}&lt;br /&gt;
		// --Define loading policies for Fonts&lt;br /&gt;
		if (APP_USE_WEBFONTS) {&lt;br /&gt;
			cspPolicies.add(&amp;quot;font-src &amp;quot; + originLocationRef);&lt;br /&gt;
		}&lt;br /&gt;
		// --Define loading policies for Connection&lt;br /&gt;
		cspPolicies.add(&amp;quot;connect-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Plugins Types&lt;br /&gt;
		cspPolicies.add(&amp;quot;plugin-types application/pdf application/x-shockwave-flash&amp;quot;);&lt;br /&gt;
		// --Define browser XSS filtering feature running mode&lt;br /&gt;
		cspPolicies.add(&amp;quot;reflected-xss block&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
		// Target formating&lt;br /&gt;
		this.policies = cspPolicies.toString().replaceAll(&amp;quot;(\\[|\\])&amp;quot;, &amp;quot;&amp;quot;).replaceAll(&amp;quot;,&amp;quot;, &amp;quot;;&amp;quot;).trim();&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Add CSP policies on each HTTP response.&lt;br /&gt;
	 * &lt;br /&gt;
	 * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)&lt;br /&gt;
	 */&lt;br /&gt;
	@Override&lt;br /&gt;
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain fchain) throws IOException, ServletException {&lt;br /&gt;
		HttpServletRequest httpRequest = ((HttpServletRequest) request);&lt;br /&gt;
		HttpServletResponse httpResponse = ((HttpServletResponse) response);&lt;br /&gt;
&lt;br /&gt;
		/* Step 1 : Detect if target resource is a Frame */&lt;br /&gt;
		// Customize here according to your context...&lt;br /&gt;
		boolean isFrame = true;&lt;br /&gt;
&lt;br /&gt;
		/* Step 2 : Add CSP policies to HTTP response */&lt;br /&gt;
		StringBuilder policiesBuffer = new StringBuilder(this.policies);&lt;br /&gt;
&lt;br /&gt;
		// If resource is a frame add Frame/Sandbox CSP policy&lt;br /&gt;
		if (isFrame) {&lt;br /&gt;
			// Frame + Sandbox : Here sandbox allow nothing, customize sandbox options depending on your app....&lt;br /&gt;
			policiesBuffer.append(&amp;quot;;&amp;quot;).append(&amp;quot;frame-src 'self';sandbox&amp;quot;);&lt;br /&gt;
			if (INCLUDE_MOZILLA_CSP_DIRECTIVES) {&lt;br /&gt;
				policiesBuffer.append(&amp;quot;;&amp;quot;).append(&amp;quot;frame-ancestors 'self'&amp;quot;);&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		// Add Script Nonce CSP Policy&lt;br /&gt;
		// --Generate a random number&lt;br /&gt;
		String randomNum = new Integer(this.prng.nextInt()).toString();&lt;br /&gt;
		// --Get its digest&lt;br /&gt;
		MessageDigest sha;&lt;br /&gt;
		try {&lt;br /&gt;
			sha = MessageDigest.getInstance(&amp;quot;SHA-1&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		catch (NoSuchAlgorithmException e) {&lt;br /&gt;
			throw new ServletException(e);&lt;br /&gt;
		}&lt;br /&gt;
		byte[] digest = sha.digest(randomNum.getBytes());&lt;br /&gt;
		// --Encode it into HEXA&lt;br /&gt;
		String scriptNonce = Hex.encodeHexString(digest);&lt;br /&gt;
		policiesBuffer.append(&amp;quot;;&amp;quot;).append(&amp;quot;script-nonce &amp;quot;).append(scriptNonce);&lt;br /&gt;
		// --Made available script nonce in view app layer&lt;br /&gt;
		httpRequest.setAttribute(&amp;quot;CSP_SCRIPT_NONCE&amp;quot;, scriptNonce);&lt;br /&gt;
&lt;br /&gt;
		// Add policies to all HTTP headers&lt;br /&gt;
		for (String header : this.cspHeaders) {&lt;br /&gt;
			httpResponse.setHeader(header, policiesBuffer.toString());&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		/* Step 3 : Let request continue chain filter */&lt;br /&gt;
		fchain.doFilter(request, response);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * {@inheritDoc}&lt;br /&gt;
	 * &lt;br /&gt;
	 * @see javax.servlet.Filter#destroy()&lt;br /&gt;
	 */&lt;br /&gt;
	@Override&lt;br /&gt;
	public void destroy() {&lt;br /&gt;
		// Not used&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:'''&lt;br /&gt;
[[Automated Audit using W3AF|W3AF]] audit tools (http://w3af.org) contain plugins to automatically audit web application to check if they correctly implement CSP policies. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:#088A08&amp;quot;&amp;gt;&lt;br /&gt;
It's very useful to include this type of tools into a web application development process in order to &lt;br /&gt;
perform a regular automatic first level check (do not replace an manual audit and manual audit must be also conducted regularly).&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Information links ==&lt;br /&gt;
* W3C Specifications: CSP 1.0  - http://www.w3.org/TR/CSP, CSP 1.1 - https://dvcs.w3.org/hg/content-security-policy/raw-file/tip/csp-specification.dev.html&lt;br /&gt;
* Introduction to CSP: http://www.html5rocks.com/en/tutorials/security/content-security-policy&lt;br /&gt;
* CSP browser support: http://caniuse.com/#feat=contentsecuritypolicy&lt;br /&gt;
* CSP readiness browser testing: http://erlend.oftedal.no/blog/csp/readiness/&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP Java Project]]&lt;br /&gt;
[[Category: Injection]]&lt;br /&gt;
[[Category:Attack]]&lt;br /&gt;
[[Category:Injection Attack]]&lt;/div&gt;</summary>
		<author><name>Dimisec</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=User:Dimisec&amp;diff=150703</id>
		<title>User:Dimisec</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=User:Dimisec&amp;diff=150703"/>
				<updated>2013-04-30T09:29:08Z</updated>
		
		<summary type="html">&lt;p&gt;Dimisec: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Web Security enthusiast, Yahoo! Paranoid, father, avid learner of computer and natural languages.&lt;/div&gt;</summary>
		<author><name>Dimisec</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Content_Security_Policy&amp;diff=150702</id>
		<title>Content Security Policy</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Content_Security_Policy&amp;diff=150702"/>
				<updated>2013-04-30T09:27:40Z</updated>
		
		<summary type="html">&lt;p&gt;Dimisec: added reference to the CSP 1.1 standard draft&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Last revision (mm/dd/yy): '''02/03/2013'''&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
'''CSP''' stands for '''C'''ontent '''S'''ecurity '''P'''olicy. &lt;br /&gt;
&lt;br /&gt;
Is an W3C specification offering the possbility to instruct the client browser from which location and/or which type of resources are allowed to be loaded. To define a loading behavior, the CSP specification use &amp;quot;directive&amp;quot; where a directive define a loading behavior for a target resource type.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This article is based on version [https://dvcs.w3.org/hg/content-security-policy/raw-file/tip/csp-specification.dev.html 1.1] of the W3C specification.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Directives can be specified using HTTP response header (a server may send more than one CSP HTTP header field with a given resource representation and a server may send different CSP header field values with different representations of the same resource or with different resources) or HTML Meta tag, the HTTP headers below are defined by the specs:&lt;br /&gt;
* '''Content-Security-Policy''' : Defined by W3C Specs as standard header, used by Chrome starting with version 25&lt;br /&gt;
* '''X-Content-Security-Policy''' : Used by Firefox and Internet Explorer,&lt;br /&gt;
* '''X-WebKit-CSP''' : Used by Chrome (will transition to Content-Security-Policy)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The supported directives are:&lt;br /&gt;
* '''default-src''' : Define loading policy for all resources type in case of a resource type dedicated directive is not defined (fallback),&lt;br /&gt;
* '''script-src''' :  Define which scripts the protected resource can execute,&lt;br /&gt;
* '''object-src''' :  Define from where the protected resource can load plugins,&lt;br /&gt;
* '''style-src''' : Define which styles (CSS) the user applies to the protected resource,&lt;br /&gt;
* '''img-src''' : Define from where the protected resource can load images,&lt;br /&gt;
* '''media-src''' : Define from where the protected resource can load video and audio,&lt;br /&gt;
* '''frame-src''' : Define from where the protected resource can embed frames,&lt;br /&gt;
* '''font-src''' : Define from where the protected resource can load fonts,&lt;br /&gt;
* '''connect-src''' : Define which URIs the protected resource can load using script interfaces,&lt;br /&gt;
* '''form-action''' : Define which URIs can be used as the action of HTML form elements,&lt;br /&gt;
* '''sandbox''' : Specifies an HTML sandbox policy that the user agent applies to the protected resource,&lt;br /&gt;
* '''script-nonce''' : Define script execution by requiring the presence of the specified nonce on script elements,&lt;br /&gt;
* '''plugin-types''' : Define the set of plugins that can be invoked by the protected resource by limiting the types of resources that can be embedded,&lt;br /&gt;
* '''reflected-xss''' : Instructs a user agent to activate or disactivate any heuristics used to filter or block reflected cross-site scripting attacks, equivalent to the effects of the non-standard X-XSS-Protection header,&lt;br /&gt;
*  '''report-uri''' : Specifies a URI to which the user agent sends reports about policy violation&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An introduction to CSP is available on [http://www.html5rocks.com/en/tutorials/security/content-security-policy/ HTML5Rocks].  The browser support is shown on http://caniuse.com/#feat=contentsecuritypolicy&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Risk ==&lt;br /&gt;
The risk with CSP can have 2 main sources:&lt;br /&gt;
# Policies misconfiguration,&lt;br /&gt;
# Too permissive policies.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Countermeasure ==&lt;br /&gt;
This article will focus on providing an sample implementation of a JEE Web Filter in order to apply a set of CSP policies on all HTTP response returned by server. &lt;br /&gt;
&lt;br /&gt;
The policies will instructs the browser to have the loading behavior below using all HTTP headers defined in W3C Specs:&lt;br /&gt;
* Explicit loading definition of each resource type,&lt;br /&gt;
* Resources are loaded only from source domain,&lt;br /&gt;
* Inline style is not allowed,&lt;br /&gt;
* For JavaScript:&lt;br /&gt;
** ''Inline script'' will be allowed because inline scripting it's commonly used (can be disabled if target site do not use this type of scripting),&lt;br /&gt;
** ''eval()'' function will be allowed in order to not break use of popular JavaScript libraries (ex: JQuery, JQueryUI, Sencha, ...) because they use eval() function (it was the case last time I have checked the source code from CDN ;) ),&lt;br /&gt;
* Generation of a random not guessable script nonce to use into all script tag,&lt;br /&gt;
* Plugin types only allow PDF and Flash,&lt;br /&gt;
* No font loading (configurable),&lt;br /&gt;
* No Audio / Video loading (configurable),&lt;br /&gt;
* Enable browser XSS filtering feature.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:navy&amp;quot;&amp;gt;&lt;br /&gt;
The support for CSP directives is not the same level in major browsers (Firefox/Chrome/IE). It's recommanded to check the support &lt;br /&gt;
provided by target browsers  (using site provided in link section of this article) in order to configure CSP policies. The sample &lt;br /&gt;
below try to provide a set of policies from which your can add policies specific to your application context.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''This implementation provide an option to add CSP directives used by Firefox (Mozilla CSP directives).''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.security.MessageDigest;&lt;br /&gt;
import java.security.NoSuchAlgorithmException;&lt;br /&gt;
import java.security.SecureRandom;&lt;br /&gt;
import java.util.ArrayList;&lt;br /&gt;
import java.util.List;&lt;br /&gt;
&lt;br /&gt;
import javax.servlet.Filter;&lt;br /&gt;
import javax.servlet.FilterChain;&lt;br /&gt;
import javax.servlet.FilterConfig;&lt;br /&gt;
import javax.servlet.ServletException;&lt;br /&gt;
import javax.servlet.ServletRequest;&lt;br /&gt;
import javax.servlet.ServletResponse;&lt;br /&gt;
import javax.servlet.annotation.WebFilter;&lt;br /&gt;
import javax.servlet.http.HttpServletRequest;&lt;br /&gt;
import javax.servlet.http.HttpServletResponse;&lt;br /&gt;
&lt;br /&gt;
import org.apache.commons.codec.binary.Hex;&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * Sample filter implementation to define a set of Content Security Policies.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 * This implementation has a dependency on Commons Codec API.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 * This filter set CSP policies using all HTTP headers defined into W3C specification.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &amp;lt;br/&amp;gt;&lt;br /&gt;
 * This implementation is oriented to be easily understandable and easily adapted.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
@WebFilter(&amp;quot;/*&amp;quot;)&lt;br /&gt;
public class CSPPoliciesApplier implements Filter {&lt;br /&gt;
&lt;br /&gt;
	/** Configuration member to specify if web app use web fonts */&lt;br /&gt;
	public static final boolean APP_USE_WEBFONTS = false;&lt;br /&gt;
&lt;br /&gt;
	/** Configuration member to specify if web app use videos or audios */&lt;br /&gt;
	public static final boolean APP_USE_AUDIOS_OR_VIDEOS = false;&lt;br /&gt;
&lt;br /&gt;
	/** Configuration member to specify if filter must add CSP directive used by Mozilla (Firefox) */&lt;br /&gt;
	public static final boolean INCLUDE_MOZILLA_CSP_DIRECTIVES = true;&lt;br /&gt;
&lt;br /&gt;
	/** Filter configuration */&lt;br /&gt;
	@SuppressWarnings(&amp;quot;unused&amp;quot;)&lt;br /&gt;
	private FilterConfig filterConfig = null;&lt;br /&gt;
&lt;br /&gt;
	/** List CSP HTTP Headers */&lt;br /&gt;
	private List&amp;lt;String&amp;gt; cspHeaders = new ArrayList&amp;lt;String&amp;gt;();&lt;br /&gt;
&lt;br /&gt;
	/** Collection of CSP polcies that will be applied */&lt;br /&gt;
	private String policies = null;&lt;br /&gt;
&lt;br /&gt;
	/** Used for Script Nonce */&lt;br /&gt;
	private SecureRandom prng = null;&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Used to prepare (one time for all) set of CSP policies that will be applied on each HTTP response.&lt;br /&gt;
	 * &lt;br /&gt;
	 * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)&lt;br /&gt;
	 */&lt;br /&gt;
	@Override&lt;br /&gt;
	public void init(FilterConfig fConfig) throws ServletException {&lt;br /&gt;
		// Get filter configuration&lt;br /&gt;
		this.filterConfig = fConfig;&lt;br /&gt;
&lt;br /&gt;
		// Init secure random&lt;br /&gt;
		try {&lt;br /&gt;
			this.prng = SecureRandom.getInstance(&amp;quot;SHA1PRNG&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		catch (NoSuchAlgorithmException e) {&lt;br /&gt;
			throw new ServletException(e);&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		// Define list of CSP HTTP Headers&lt;br /&gt;
		this.cspHeaders.add(&amp;quot;Content-Security-Policy&amp;quot;);&lt;br /&gt;
		this.cspHeaders.add(&amp;quot;X-Content-Security-Policy&amp;quot;);&lt;br /&gt;
		this.cspHeaders.add(&amp;quot;X-WebKit-CSP&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
		// Define CSP policies&lt;br /&gt;
		// Loading policies for Frame and Sandboxing will be dynamically defined : We need to know if context use Frame&lt;br /&gt;
		List&amp;lt;String&amp;gt; cspPolicies = new ArrayList&amp;lt;String&amp;gt;();&lt;br /&gt;
		String originLocationRef = &amp;quot;'self'&amp;quot;;&lt;br /&gt;
		// --Disable default source in order to avoid browser fallback loading using 'default-src' locations&lt;br /&gt;
		cspPolicies.add(&amp;quot;default-src 'none'&amp;quot;);&lt;br /&gt;
		// --Define loading policies for Scripts&lt;br /&gt;
		cspPolicies.add(&amp;quot;script-src &amp;quot; + originLocationRef + &amp;quot; 'unsafe-inline' 'unsafe-eval'&amp;quot;);&lt;br /&gt;
		if (INCLUDE_MOZILLA_CSP_DIRECTIVES) {&lt;br /&gt;
			cspPolicies.add(&amp;quot;options inline-script eval-script&amp;quot;);&lt;br /&gt;
			cspPolicies.add(&amp;quot;xhr-src 'self'&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		// --Define loading policies for Plugins&lt;br /&gt;
		cspPolicies.add(&amp;quot;object-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Styles (CSS)&lt;br /&gt;
		cspPolicies.add(&amp;quot;style-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Images&lt;br /&gt;
		cspPolicies.add(&amp;quot;img-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Form&lt;br /&gt;
		cspPolicies.add(&amp;quot;form-action &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Audios/Videos&lt;br /&gt;
		if (APP_USE_AUDIOS_OR_VIDEOS) {&lt;br /&gt;
			cspPolicies.add(&amp;quot;media-src &amp;quot; + originLocationRef);&lt;br /&gt;
		}&lt;br /&gt;
		// --Define loading policies for Fonts&lt;br /&gt;
		if (APP_USE_WEBFONTS) {&lt;br /&gt;
			cspPolicies.add(&amp;quot;font-src &amp;quot; + originLocationRef);&lt;br /&gt;
		}&lt;br /&gt;
		// --Define loading policies for Connection&lt;br /&gt;
		cspPolicies.add(&amp;quot;connect-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Plugins Types&lt;br /&gt;
		cspPolicies.add(&amp;quot;plugin-types application/pdf application/x-shockwave-flash&amp;quot;);&lt;br /&gt;
		// --Define browser XSS filtering feature running mode&lt;br /&gt;
		cspPolicies.add(&amp;quot;reflected-xss block&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
		// Target formating&lt;br /&gt;
		this.policies = cspPolicies.toString().replaceAll(&amp;quot;(\\[|\\])&amp;quot;, &amp;quot;&amp;quot;).replaceAll(&amp;quot;,&amp;quot;, &amp;quot;;&amp;quot;).trim();&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Add CSP policies on each HTTP response.&lt;br /&gt;
	 * &lt;br /&gt;
	 * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)&lt;br /&gt;
	 */&lt;br /&gt;
	@Override&lt;br /&gt;
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain fchain) throws IOException, ServletException {&lt;br /&gt;
		HttpServletRequest httpRequest = ((HttpServletRequest) request);&lt;br /&gt;
		HttpServletResponse httpResponse = ((HttpServletResponse) response);&lt;br /&gt;
&lt;br /&gt;
		/* Step 1 : Detect if target resource is a Frame */&lt;br /&gt;
		// Customize here according to your context...&lt;br /&gt;
		boolean isFrame = true;&lt;br /&gt;
&lt;br /&gt;
		/* Step 2 : Add CSP policies to HTTP response */&lt;br /&gt;
		StringBuilder policiesBuffer = new StringBuilder(this.policies);&lt;br /&gt;
&lt;br /&gt;
		// If resource is a frame add Frame/Sandbox CSP policy&lt;br /&gt;
		if (isFrame) {&lt;br /&gt;
			// Frame + Sandbox : Here sandbox allow nothing, customize sandbox options depending on your app....&lt;br /&gt;
			policiesBuffer.append(&amp;quot;;&amp;quot;).append(&amp;quot;frame-src 'self';sandbox&amp;quot;);&lt;br /&gt;
			if (INCLUDE_MOZILLA_CSP_DIRECTIVES) {&lt;br /&gt;
				policiesBuffer.append(&amp;quot;;&amp;quot;).append(&amp;quot;frame-ancestors 'self'&amp;quot;);&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		// Add Script Nonce CSP Policy&lt;br /&gt;
		// --Generate a random number&lt;br /&gt;
		String randomNum = new Integer(this.prng.nextInt()).toString();&lt;br /&gt;
		// --Get its digest&lt;br /&gt;
		MessageDigest sha;&lt;br /&gt;
		try {&lt;br /&gt;
			sha = MessageDigest.getInstance(&amp;quot;SHA-1&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		catch (NoSuchAlgorithmException e) {&lt;br /&gt;
			throw new ServletException(e);&lt;br /&gt;
		}&lt;br /&gt;
		byte[] digest = sha.digest(randomNum.getBytes());&lt;br /&gt;
		// --Encode it into HEXA&lt;br /&gt;
		String scriptNonce = Hex.encodeHexString(digest);&lt;br /&gt;
		policiesBuffer.append(&amp;quot;;&amp;quot;).append(&amp;quot;script-nonce &amp;quot;).append(scriptNonce);&lt;br /&gt;
		// --Made available script nonce in view app layer&lt;br /&gt;
		httpRequest.setAttribute(&amp;quot;CSP_SCRIPT_NONCE&amp;quot;, scriptNonce);&lt;br /&gt;
&lt;br /&gt;
		// Add policies to all HTTP headers&lt;br /&gt;
		for (String header : this.cspHeaders) {&lt;br /&gt;
			httpResponse.setHeader(header, policiesBuffer.toString());&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		/* Step 3 : Let request continue chain filter */&lt;br /&gt;
		fchain.doFilter(request, response);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * {@inheritDoc}&lt;br /&gt;
	 * &lt;br /&gt;
	 * @see javax.servlet.Filter#destroy()&lt;br /&gt;
	 */&lt;br /&gt;
	@Override&lt;br /&gt;
	public void destroy() {&lt;br /&gt;
		// Not used&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:'''&lt;br /&gt;
[[Automated Audit using W3AF|W3AF]] audit tools (http://w3af.org) contain plugins to automatically audit web application to check if they correctly implement CSP policies. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:#088A08&amp;quot;&amp;gt;&lt;br /&gt;
It's very useful to include this type of tools into a web application development process in order to &lt;br /&gt;
perform a regular automatic first level check (do not replace an manual audit and manual audit must be also conducted regularly).&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Information links ==&lt;br /&gt;
* W3C Specifications: CSP 1.0  - http://www.w3.org/TR/CSP, CSP 1.1 - https://dvcs.w3.org/hg/content-security-policy/raw-file/tip/csp-specification.dev.html&lt;br /&gt;
* Introduction to CSP: http://www.html5rocks.com/en/tutorials/security/content-security-policy&lt;br /&gt;
* CSP browser support: http://caniuse.com/#feat=contentsecuritypolicy&lt;br /&gt;
* CSP readiness browser testing: http://erlend.oftedal.no/blog/csp/readiness/&lt;br /&gt;
* CSP proposal by Mozilla Security ('''deprecated''', use W3C specs): https://wiki.mozilla.org/Security/CSP/Specification&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP Java Project]]&lt;br /&gt;
[[Category: Injection]]&lt;br /&gt;
[[Category:Attack]]&lt;br /&gt;
[[Category:Injection Attack]]&lt;/div&gt;</summary>
		<author><name>Dimisec</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Content_Security_Policy&amp;diff=150701</id>
		<title>Content Security Policy</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Content_Security_Policy&amp;diff=150701"/>
				<updated>2013-04-30T09:23:40Z</updated>
		
		<summary type="html">&lt;p&gt;Dimisec: note about reflected-xss and its relationship to X-XSS-Protection header; added report-uri directive&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Last revision (mm/dd/yy): '''02/03/2013'''&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
'''CSP''' stands for '''C'''ontent '''S'''ecurity '''P'''olicy. &lt;br /&gt;
&lt;br /&gt;
Is an W3C specification offering the possbility to instruct the client browser from which location and/or which type of resources are allowed to be loaded. To define a loading behavior, the CSP specification use &amp;quot;directive&amp;quot; where a directive define a loading behavior for a target resource type.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This article is based on version [https://dvcs.w3.org/hg/content-security-policy/raw-file/tip/csp-specification.dev.html 1.1] of the W3C specification.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Directives can be specified using HTTP response header (a server may send more than one CSP HTTP header field with a given resource representation and a server may send different CSP header field values with different representations of the same resource or with different resources) or HTML Meta tag, the HTTP headers below are defined by the specs:&lt;br /&gt;
* '''Content-Security-Policy''' : Defined by W3C Specs as standard header, used by Chrome starting with version 25&lt;br /&gt;
* '''X-Content-Security-Policy''' : Used by Firefox and Internet Explorer,&lt;br /&gt;
* '''X-WebKit-CSP''' : Used by Chrome (will transition to Content-Security-Policy)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The supported directives are:&lt;br /&gt;
* '''default-src''' : Define loading policy for all resources type in case of a resource type dedicated directive is not defined (fallback),&lt;br /&gt;
* '''script-src''' :  Define which scripts the protected resource can execute,&lt;br /&gt;
* '''object-src''' :  Define from where the protected resource can load plugins,&lt;br /&gt;
* '''style-src''' : Define which styles (CSS) the user applies to the protected resource,&lt;br /&gt;
* '''img-src''' : Define from where the protected resource can load images,&lt;br /&gt;
* '''media-src''' : Define from where the protected resource can load video and audio,&lt;br /&gt;
* '''frame-src''' : Define from where the protected resource can embed frames,&lt;br /&gt;
* '''font-src''' : Define from where the protected resource can load fonts,&lt;br /&gt;
* '''connect-src''' : Define which URIs the protected resource can load using script interfaces,&lt;br /&gt;
* '''form-action''' : Define which URIs can be used as the action of HTML form elements,&lt;br /&gt;
* '''sandbox''' : Specifies an HTML sandbox policy that the user agent applies to the protected resource,&lt;br /&gt;
* '''script-nonce''' : Define script execution by requiring the presence of the specified nonce on script elements,&lt;br /&gt;
* '''plugin-types''' : Define the set of plugins that can be invoked by the protected resource by limiting the types of resources that can be embedded,&lt;br /&gt;
* '''reflected-xss''' : Instructs a user agent to activate or disactivate any heuristics used to filter or block reflected cross-site scripting attacks, equivalent to the effects of the non-standard X-XSS-Protection header,&lt;br /&gt;
*  '''report-uri''' : Specifies a URI to which the user agent sends reports about policy violation&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An introduction to CSP is available on [http://www.html5rocks.com/en/tutorials/security/content-security-policy/ HTML5Rocks].  The browser support is shown on http://caniuse.com/#feat=contentsecuritypolicy&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Risk ==&lt;br /&gt;
The risk with CSP can have 2 main sources:&lt;br /&gt;
# Policies misconfiguration,&lt;br /&gt;
# Too permissive policies.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Countermeasure ==&lt;br /&gt;
This article will focus on providing an sample implementation of a JEE Web Filter in order to apply a set of CSP policies on all HTTP response returned by server. &lt;br /&gt;
&lt;br /&gt;
The policies will instructs the browser to have the loading behavior below using all HTTP headers defined in W3C Specs:&lt;br /&gt;
* Explicit loading definition of each resource type,&lt;br /&gt;
* Resources are loaded only from source domain,&lt;br /&gt;
* Inline style is not allowed,&lt;br /&gt;
* For JavaScript:&lt;br /&gt;
** ''Inline script'' will be allowed because inline scripting it's commonly used (can be disabled if target site do not use this type of scripting),&lt;br /&gt;
** ''eval()'' function will be allowed in order to not break use of popular JavaScript libraries (ex: JQuery, JQueryUI, Sencha, ...) because they use eval() function (it was the case last time I have checked the source code from CDN ;) ),&lt;br /&gt;
* Generation of a random not guessable script nonce to use into all script tag,&lt;br /&gt;
* Plugin types only allow PDF and Flash,&lt;br /&gt;
* No font loading (configurable),&lt;br /&gt;
* No Audio / Video loading (configurable),&lt;br /&gt;
* Enable browser XSS filtering feature.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:navy&amp;quot;&amp;gt;&lt;br /&gt;
The support for CSP directives is not the same level in major browsers (Firefox/Chrome/IE). It's recommanded to check the support &lt;br /&gt;
provided by target browsers  (using site provided in link section of this article) in order to configure CSP policies. The sample &lt;br /&gt;
below try to provide a set of policies from which your can add policies specific to your application context.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''This implementation provide an option to add CSP directives used by Firefox (Mozilla CSP directives).''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.security.MessageDigest;&lt;br /&gt;
import java.security.NoSuchAlgorithmException;&lt;br /&gt;
import java.security.SecureRandom;&lt;br /&gt;
import java.util.ArrayList;&lt;br /&gt;
import java.util.List;&lt;br /&gt;
&lt;br /&gt;
import javax.servlet.Filter;&lt;br /&gt;
import javax.servlet.FilterChain;&lt;br /&gt;
import javax.servlet.FilterConfig;&lt;br /&gt;
import javax.servlet.ServletException;&lt;br /&gt;
import javax.servlet.ServletRequest;&lt;br /&gt;
import javax.servlet.ServletResponse;&lt;br /&gt;
import javax.servlet.annotation.WebFilter;&lt;br /&gt;
import javax.servlet.http.HttpServletRequest;&lt;br /&gt;
import javax.servlet.http.HttpServletResponse;&lt;br /&gt;
&lt;br /&gt;
import org.apache.commons.codec.binary.Hex;&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * Sample filter implementation to define a set of Content Security Policies.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 * This implementation has a dependency on Commons Codec API.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 * This filter set CSP policies using all HTTP headers defined into W3C specification.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &amp;lt;br/&amp;gt;&lt;br /&gt;
 * This implementation is oriented to be easily understandable and easily adapted.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
@WebFilter(&amp;quot;/*&amp;quot;)&lt;br /&gt;
public class CSPPoliciesApplier implements Filter {&lt;br /&gt;
&lt;br /&gt;
	/** Configuration member to specify if web app use web fonts */&lt;br /&gt;
	public static final boolean APP_USE_WEBFONTS = false;&lt;br /&gt;
&lt;br /&gt;
	/** Configuration member to specify if web app use videos or audios */&lt;br /&gt;
	public static final boolean APP_USE_AUDIOS_OR_VIDEOS = false;&lt;br /&gt;
&lt;br /&gt;
	/** Configuration member to specify if filter must add CSP directive used by Mozilla (Firefox) */&lt;br /&gt;
	public static final boolean INCLUDE_MOZILLA_CSP_DIRECTIVES = true;&lt;br /&gt;
&lt;br /&gt;
	/** Filter configuration */&lt;br /&gt;
	@SuppressWarnings(&amp;quot;unused&amp;quot;)&lt;br /&gt;
	private FilterConfig filterConfig = null;&lt;br /&gt;
&lt;br /&gt;
	/** List CSP HTTP Headers */&lt;br /&gt;
	private List&amp;lt;String&amp;gt; cspHeaders = new ArrayList&amp;lt;String&amp;gt;();&lt;br /&gt;
&lt;br /&gt;
	/** Collection of CSP polcies that will be applied */&lt;br /&gt;
	private String policies = null;&lt;br /&gt;
&lt;br /&gt;
	/** Used for Script Nonce */&lt;br /&gt;
	private SecureRandom prng = null;&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Used to prepare (one time for all) set of CSP policies that will be applied on each HTTP response.&lt;br /&gt;
	 * &lt;br /&gt;
	 * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)&lt;br /&gt;
	 */&lt;br /&gt;
	@Override&lt;br /&gt;
	public void init(FilterConfig fConfig) throws ServletException {&lt;br /&gt;
		// Get filter configuration&lt;br /&gt;
		this.filterConfig = fConfig;&lt;br /&gt;
&lt;br /&gt;
		// Init secure random&lt;br /&gt;
		try {&lt;br /&gt;
			this.prng = SecureRandom.getInstance(&amp;quot;SHA1PRNG&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		catch (NoSuchAlgorithmException e) {&lt;br /&gt;
			throw new ServletException(e);&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		// Define list of CSP HTTP Headers&lt;br /&gt;
		this.cspHeaders.add(&amp;quot;Content-Security-Policy&amp;quot;);&lt;br /&gt;
		this.cspHeaders.add(&amp;quot;X-Content-Security-Policy&amp;quot;);&lt;br /&gt;
		this.cspHeaders.add(&amp;quot;X-WebKit-CSP&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
		// Define CSP policies&lt;br /&gt;
		// Loading policies for Frame and Sandboxing will be dynamically defined : We need to know if context use Frame&lt;br /&gt;
		List&amp;lt;String&amp;gt; cspPolicies = new ArrayList&amp;lt;String&amp;gt;();&lt;br /&gt;
		String originLocationRef = &amp;quot;'self'&amp;quot;;&lt;br /&gt;
		// --Disable default source in order to avoid browser fallback loading using 'default-src' locations&lt;br /&gt;
		cspPolicies.add(&amp;quot;default-src 'none'&amp;quot;);&lt;br /&gt;
		// --Define loading policies for Scripts&lt;br /&gt;
		cspPolicies.add(&amp;quot;script-src &amp;quot; + originLocationRef + &amp;quot; 'unsafe-inline' 'unsafe-eval'&amp;quot;);&lt;br /&gt;
		if (INCLUDE_MOZILLA_CSP_DIRECTIVES) {&lt;br /&gt;
			cspPolicies.add(&amp;quot;options inline-script eval-script&amp;quot;);&lt;br /&gt;
			cspPolicies.add(&amp;quot;xhr-src 'self'&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		// --Define loading policies for Plugins&lt;br /&gt;
		cspPolicies.add(&amp;quot;object-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Styles (CSS)&lt;br /&gt;
		cspPolicies.add(&amp;quot;style-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Images&lt;br /&gt;
		cspPolicies.add(&amp;quot;img-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Form&lt;br /&gt;
		cspPolicies.add(&amp;quot;form-action &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Audios/Videos&lt;br /&gt;
		if (APP_USE_AUDIOS_OR_VIDEOS) {&lt;br /&gt;
			cspPolicies.add(&amp;quot;media-src &amp;quot; + originLocationRef);&lt;br /&gt;
		}&lt;br /&gt;
		// --Define loading policies for Fonts&lt;br /&gt;
		if (APP_USE_WEBFONTS) {&lt;br /&gt;
			cspPolicies.add(&amp;quot;font-src &amp;quot; + originLocationRef);&lt;br /&gt;
		}&lt;br /&gt;
		// --Define loading policies for Connection&lt;br /&gt;
		cspPolicies.add(&amp;quot;connect-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Plugins Types&lt;br /&gt;
		cspPolicies.add(&amp;quot;plugin-types application/pdf application/x-shockwave-flash&amp;quot;);&lt;br /&gt;
		// --Define browser XSS filtering feature running mode&lt;br /&gt;
		cspPolicies.add(&amp;quot;reflected-xss block&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
		// Target formating&lt;br /&gt;
		this.policies = cspPolicies.toString().replaceAll(&amp;quot;(\\[|\\])&amp;quot;, &amp;quot;&amp;quot;).replaceAll(&amp;quot;,&amp;quot;, &amp;quot;;&amp;quot;).trim();&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Add CSP policies on each HTTP response.&lt;br /&gt;
	 * &lt;br /&gt;
	 * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)&lt;br /&gt;
	 */&lt;br /&gt;
	@Override&lt;br /&gt;
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain fchain) throws IOException, ServletException {&lt;br /&gt;
		HttpServletRequest httpRequest = ((HttpServletRequest) request);&lt;br /&gt;
		HttpServletResponse httpResponse = ((HttpServletResponse) response);&lt;br /&gt;
&lt;br /&gt;
		/* Step 1 : Detect if target resource is a Frame */&lt;br /&gt;
		// Customize here according to your context...&lt;br /&gt;
		boolean isFrame = true;&lt;br /&gt;
&lt;br /&gt;
		/* Step 2 : Add CSP policies to HTTP response */&lt;br /&gt;
		StringBuilder policiesBuffer = new StringBuilder(this.policies);&lt;br /&gt;
&lt;br /&gt;
		// If resource is a frame add Frame/Sandbox CSP policy&lt;br /&gt;
		if (isFrame) {&lt;br /&gt;
			// Frame + Sandbox : Here sandbox allow nothing, customize sandbox options depending on your app....&lt;br /&gt;
			policiesBuffer.append(&amp;quot;;&amp;quot;).append(&amp;quot;frame-src 'self';sandbox&amp;quot;);&lt;br /&gt;
			if (INCLUDE_MOZILLA_CSP_DIRECTIVES) {&lt;br /&gt;
				policiesBuffer.append(&amp;quot;;&amp;quot;).append(&amp;quot;frame-ancestors 'self'&amp;quot;);&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		// Add Script Nonce CSP Policy&lt;br /&gt;
		// --Generate a random number&lt;br /&gt;
		String randomNum = new Integer(this.prng.nextInt()).toString();&lt;br /&gt;
		// --Get its digest&lt;br /&gt;
		MessageDigest sha;&lt;br /&gt;
		try {&lt;br /&gt;
			sha = MessageDigest.getInstance(&amp;quot;SHA-1&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		catch (NoSuchAlgorithmException e) {&lt;br /&gt;
			throw new ServletException(e);&lt;br /&gt;
		}&lt;br /&gt;
		byte[] digest = sha.digest(randomNum.getBytes());&lt;br /&gt;
		// --Encode it into HEXA&lt;br /&gt;
		String scriptNonce = Hex.encodeHexString(digest);&lt;br /&gt;
		policiesBuffer.append(&amp;quot;;&amp;quot;).append(&amp;quot;script-nonce &amp;quot;).append(scriptNonce);&lt;br /&gt;
		// --Made available script nonce in view app layer&lt;br /&gt;
		httpRequest.setAttribute(&amp;quot;CSP_SCRIPT_NONCE&amp;quot;, scriptNonce);&lt;br /&gt;
&lt;br /&gt;
		// Add policies to all HTTP headers&lt;br /&gt;
		for (String header : this.cspHeaders) {&lt;br /&gt;
			httpResponse.setHeader(header, policiesBuffer.toString());&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		/* Step 3 : Let request continue chain filter */&lt;br /&gt;
		fchain.doFilter(request, response);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * {@inheritDoc}&lt;br /&gt;
	 * &lt;br /&gt;
	 * @see javax.servlet.Filter#destroy()&lt;br /&gt;
	 */&lt;br /&gt;
	@Override&lt;br /&gt;
	public void destroy() {&lt;br /&gt;
		// Not used&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:'''&lt;br /&gt;
[[Automated Audit using W3AF|W3AF]] audit tools (http://w3af.org) contain plugins to automatically audit web application to check if they correctly implement CSP policies. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:#088A08&amp;quot;&amp;gt;&lt;br /&gt;
It's very useful to include this type of tools into a web application development process in order to &lt;br /&gt;
perform a regular automatic first level check (do not replace an manual audit and manual audit must be also conducted regularly).&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Information links ==&lt;br /&gt;
* W3C Specification (last specs release) : http://www.w3.org/TR/CSP&lt;br /&gt;
* Introduction to CSP: http://www.html5rocks.com/en/tutorials/security/content-security-policy&lt;br /&gt;
* CSP browser support: http://caniuse.com/#feat=contentsecuritypolicy&lt;br /&gt;
* CSP readiness browser testing: http://erlend.oftedal.no/blog/csp/readiness/&lt;br /&gt;
* CSP proposal by Mozilla Security ('''deprecated''', use W3C specs): https://wiki.mozilla.org/Security/CSP/Specification&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP Java Project]]&lt;br /&gt;
[[Category: Injection]]&lt;br /&gt;
[[Category:Attack]]&lt;br /&gt;
[[Category:Injection Attack]]&lt;/div&gt;</summary>
		<author><name>Dimisec</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Content_Security_Policy&amp;diff=150699</id>
		<title>Content Security Policy</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Content_Security_Policy&amp;diff=150699"/>
				<updated>2013-04-30T09:13:28Z</updated>
		
		<summary type="html">&lt;p&gt;Dimisec: minor grammar pick&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Last revision (mm/dd/yy): '''02/03/2013'''&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
'''CSP''' stands for '''C'''ontent '''S'''ecurity '''P'''olicy. &lt;br /&gt;
&lt;br /&gt;
Is an W3C specification offering the possbility to instruct the client browser from which location and/or which type of resources are allowed to be loaded. To define a loading behavior, the CSP specification use &amp;quot;directive&amp;quot; where a directive define a loading behavior for a target resource type.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This article is based on version [https://dvcs.w3.org/hg/content-security-policy/raw-file/tip/csp-specification.dev.html 1.1] of the W3C specification.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Directives can be specified using HTTP response header (a server may send more than one CSP HTTP header field with a given resource representation and a server may send different CSP header field values with different representations of the same resource or with different resources) or HTML Meta tag, the HTTP headers below are defined by the specs:&lt;br /&gt;
* '''Content-Security-Policy''' : Defined by W3C Specs as standard header, used by Chrome starting with version 25&lt;br /&gt;
* '''X-Content-Security-Policy''' : Used by Firefox and Internet Explorer,&lt;br /&gt;
* '''X-WebKit-CSP''' : Used by Chrome (will transition to Content-Security-Policy)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The supported directives are:&lt;br /&gt;
* '''default-src''' : Define loading policy for all resources type in case of a resource type dedicated directive is not defined (fallback),&lt;br /&gt;
* '''script-src''' :  Define which scripts the protected resource can execute,&lt;br /&gt;
* '''object-src''' :  Define from where the protected resource can load plugins,&lt;br /&gt;
* '''style-src''' : Define which styles (CSS) the user applies to the protected resource,&lt;br /&gt;
* '''img-src''' : Define from where the protected resource can load images,&lt;br /&gt;
* '''media-src''' : Define from where the protected resource can load video and audio,&lt;br /&gt;
* '''frame-src''' : Define from where the protected resource can embed frames,&lt;br /&gt;
* '''font-src''' : Define from where the protected resource can load fonts,&lt;br /&gt;
* '''connect-src''' : Define which URIs the protected resource can load using script interfaces,&lt;br /&gt;
* '''form-action''' : Define which URIs can be used as the action of HTML form elements,&lt;br /&gt;
* '''sandbox''' : Specifies an HTML sandbox policy that the user agent applies to the protected resource,&lt;br /&gt;
* '''script-nonce''' : Define script execution by requiring the presence of the specified nonce on script elements,&lt;br /&gt;
* '''plugin-types''' : Define the set of plugins that can be invoked by the protected resource by limiting the types of resources that can be embedded,&lt;br /&gt;
* '''reflected-xss''' : Instructs a user agent to activate or disactivate any heuristics used to filter or block reflected cross-site scripting attacks.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An introduction to CSP is available on [http://www.html5rocks.com/en/tutorials/security/content-security-policy/ HTML5Rocks].  The browser support is shown on http://caniuse.com/#feat=contentsecuritypolicy&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Risk ==&lt;br /&gt;
The risk with CSP can have 2 main sources:&lt;br /&gt;
# Policies misconfiguration,&lt;br /&gt;
# Too permissive policies.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Countermeasure ==&lt;br /&gt;
This article will focus on providing an sample implementation of a JEE Web Filter in order to apply a set of CSP policies on all HTTP response returned by server. &lt;br /&gt;
&lt;br /&gt;
The policies will instructs the browser to have the loading behavior below using all HTTP headers defined in W3C Specs:&lt;br /&gt;
* Explicit loading definition of each resource type,&lt;br /&gt;
* Resources are loaded only from source domain,&lt;br /&gt;
* Inline style is not allowed,&lt;br /&gt;
* For JavaScript:&lt;br /&gt;
** ''Inline script'' will be allowed because inline scripting it's commonly used (can be disabled if target site do not use this type of scripting),&lt;br /&gt;
** ''eval()'' function will be allowed in order to not break use of popular JavaScript libraries (ex: JQuery, JQueryUI, Sencha, ...) because they use eval() function (it was the case last time I have checked the source code from CDN ;) ),&lt;br /&gt;
* Generation of a random not guessable script nonce to use into all script tag,&lt;br /&gt;
* Plugin types only allow PDF and Flash,&lt;br /&gt;
* No font loading (configurable),&lt;br /&gt;
* No Audio / Video loading (configurable),&lt;br /&gt;
* Enable browser XSS filtering feature.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:navy&amp;quot;&amp;gt;&lt;br /&gt;
The support for CSP directives is not the same level in major browsers (Firefox/Chrome/IE). It's recommanded to check the support &lt;br /&gt;
provided by target browsers  (using site provided in link section of this article) in order to configure CSP policies. The sample &lt;br /&gt;
below try to provide a set of policies from which your can add policies specific to your application context.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''This implementation provide an option to add CSP directives used by Firefox (Mozilla CSP directives).''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.security.MessageDigest;&lt;br /&gt;
import java.security.NoSuchAlgorithmException;&lt;br /&gt;
import java.security.SecureRandom;&lt;br /&gt;
import java.util.ArrayList;&lt;br /&gt;
import java.util.List;&lt;br /&gt;
&lt;br /&gt;
import javax.servlet.Filter;&lt;br /&gt;
import javax.servlet.FilterChain;&lt;br /&gt;
import javax.servlet.FilterConfig;&lt;br /&gt;
import javax.servlet.ServletException;&lt;br /&gt;
import javax.servlet.ServletRequest;&lt;br /&gt;
import javax.servlet.ServletResponse;&lt;br /&gt;
import javax.servlet.annotation.WebFilter;&lt;br /&gt;
import javax.servlet.http.HttpServletRequest;&lt;br /&gt;
import javax.servlet.http.HttpServletResponse;&lt;br /&gt;
&lt;br /&gt;
import org.apache.commons.codec.binary.Hex;&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * Sample filter implementation to define a set of Content Security Policies.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 * This implementation has a dependency on Commons Codec API.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 * This filter set CSP policies using all HTTP headers defined into W3C specification.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &amp;lt;br/&amp;gt;&lt;br /&gt;
 * This implementation is oriented to be easily understandable and easily adapted.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
@WebFilter(&amp;quot;/*&amp;quot;)&lt;br /&gt;
public class CSPPoliciesApplier implements Filter {&lt;br /&gt;
&lt;br /&gt;
	/** Configuration member to specify if web app use web fonts */&lt;br /&gt;
	public static final boolean APP_USE_WEBFONTS = false;&lt;br /&gt;
&lt;br /&gt;
	/** Configuration member to specify if web app use videos or audios */&lt;br /&gt;
	public static final boolean APP_USE_AUDIOS_OR_VIDEOS = false;&lt;br /&gt;
&lt;br /&gt;
	/** Configuration member to specify if filter must add CSP directive used by Mozilla (Firefox) */&lt;br /&gt;
	public static final boolean INCLUDE_MOZILLA_CSP_DIRECTIVES = true;&lt;br /&gt;
&lt;br /&gt;
	/** Filter configuration */&lt;br /&gt;
	@SuppressWarnings(&amp;quot;unused&amp;quot;)&lt;br /&gt;
	private FilterConfig filterConfig = null;&lt;br /&gt;
&lt;br /&gt;
	/** List CSP HTTP Headers */&lt;br /&gt;
	private List&amp;lt;String&amp;gt; cspHeaders = new ArrayList&amp;lt;String&amp;gt;();&lt;br /&gt;
&lt;br /&gt;
	/** Collection of CSP polcies that will be applied */&lt;br /&gt;
	private String policies = null;&lt;br /&gt;
&lt;br /&gt;
	/** Used for Script Nonce */&lt;br /&gt;
	private SecureRandom prng = null;&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Used to prepare (one time for all) set of CSP policies that will be applied on each HTTP response.&lt;br /&gt;
	 * &lt;br /&gt;
	 * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)&lt;br /&gt;
	 */&lt;br /&gt;
	@Override&lt;br /&gt;
	public void init(FilterConfig fConfig) throws ServletException {&lt;br /&gt;
		// Get filter configuration&lt;br /&gt;
		this.filterConfig = fConfig;&lt;br /&gt;
&lt;br /&gt;
		// Init secure random&lt;br /&gt;
		try {&lt;br /&gt;
			this.prng = SecureRandom.getInstance(&amp;quot;SHA1PRNG&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		catch (NoSuchAlgorithmException e) {&lt;br /&gt;
			throw new ServletException(e);&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		// Define list of CSP HTTP Headers&lt;br /&gt;
		this.cspHeaders.add(&amp;quot;Content-Security-Policy&amp;quot;);&lt;br /&gt;
		this.cspHeaders.add(&amp;quot;X-Content-Security-Policy&amp;quot;);&lt;br /&gt;
		this.cspHeaders.add(&amp;quot;X-WebKit-CSP&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
		// Define CSP policies&lt;br /&gt;
		// Loading policies for Frame and Sandboxing will be dynamically defined : We need to know if context use Frame&lt;br /&gt;
		List&amp;lt;String&amp;gt; cspPolicies = new ArrayList&amp;lt;String&amp;gt;();&lt;br /&gt;
		String originLocationRef = &amp;quot;'self'&amp;quot;;&lt;br /&gt;
		// --Disable default source in order to avoid browser fallback loading using 'default-src' locations&lt;br /&gt;
		cspPolicies.add(&amp;quot;default-src 'none'&amp;quot;);&lt;br /&gt;
		// --Define loading policies for Scripts&lt;br /&gt;
		cspPolicies.add(&amp;quot;script-src &amp;quot; + originLocationRef + &amp;quot; 'unsafe-inline' 'unsafe-eval'&amp;quot;);&lt;br /&gt;
		if (INCLUDE_MOZILLA_CSP_DIRECTIVES) {&lt;br /&gt;
			cspPolicies.add(&amp;quot;options inline-script eval-script&amp;quot;);&lt;br /&gt;
			cspPolicies.add(&amp;quot;xhr-src 'self'&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		// --Define loading policies for Plugins&lt;br /&gt;
		cspPolicies.add(&amp;quot;object-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Styles (CSS)&lt;br /&gt;
		cspPolicies.add(&amp;quot;style-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Images&lt;br /&gt;
		cspPolicies.add(&amp;quot;img-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Form&lt;br /&gt;
		cspPolicies.add(&amp;quot;form-action &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Audios/Videos&lt;br /&gt;
		if (APP_USE_AUDIOS_OR_VIDEOS) {&lt;br /&gt;
			cspPolicies.add(&amp;quot;media-src &amp;quot; + originLocationRef);&lt;br /&gt;
		}&lt;br /&gt;
		// --Define loading policies for Fonts&lt;br /&gt;
		if (APP_USE_WEBFONTS) {&lt;br /&gt;
			cspPolicies.add(&amp;quot;font-src &amp;quot; + originLocationRef);&lt;br /&gt;
		}&lt;br /&gt;
		// --Define loading policies for Connection&lt;br /&gt;
		cspPolicies.add(&amp;quot;connect-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Plugins Types&lt;br /&gt;
		cspPolicies.add(&amp;quot;plugin-types application/pdf application/x-shockwave-flash&amp;quot;);&lt;br /&gt;
		// --Define browser XSS filtering feature running mode&lt;br /&gt;
		cspPolicies.add(&amp;quot;reflected-xss block&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
		// Target formating&lt;br /&gt;
		this.policies = cspPolicies.toString().replaceAll(&amp;quot;(\\[|\\])&amp;quot;, &amp;quot;&amp;quot;).replaceAll(&amp;quot;,&amp;quot;, &amp;quot;;&amp;quot;).trim();&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Add CSP policies on each HTTP response.&lt;br /&gt;
	 * &lt;br /&gt;
	 * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)&lt;br /&gt;
	 */&lt;br /&gt;
	@Override&lt;br /&gt;
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain fchain) throws IOException, ServletException {&lt;br /&gt;
		HttpServletRequest httpRequest = ((HttpServletRequest) request);&lt;br /&gt;
		HttpServletResponse httpResponse = ((HttpServletResponse) response);&lt;br /&gt;
&lt;br /&gt;
		/* Step 1 : Detect if target resource is a Frame */&lt;br /&gt;
		// Customize here according to your context...&lt;br /&gt;
		boolean isFrame = true;&lt;br /&gt;
&lt;br /&gt;
		/* Step 2 : Add CSP policies to HTTP response */&lt;br /&gt;
		StringBuilder policiesBuffer = new StringBuilder(this.policies);&lt;br /&gt;
&lt;br /&gt;
		// If resource is a frame add Frame/Sandbox CSP policy&lt;br /&gt;
		if (isFrame) {&lt;br /&gt;
			// Frame + Sandbox : Here sandbox allow nothing, customize sandbox options depending on your app....&lt;br /&gt;
			policiesBuffer.append(&amp;quot;;&amp;quot;).append(&amp;quot;frame-src 'self';sandbox&amp;quot;);&lt;br /&gt;
			if (INCLUDE_MOZILLA_CSP_DIRECTIVES) {&lt;br /&gt;
				policiesBuffer.append(&amp;quot;;&amp;quot;).append(&amp;quot;frame-ancestors 'self'&amp;quot;);&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		// Add Script Nonce CSP Policy&lt;br /&gt;
		// --Generate a random number&lt;br /&gt;
		String randomNum = new Integer(this.prng.nextInt()).toString();&lt;br /&gt;
		// --Get its digest&lt;br /&gt;
		MessageDigest sha;&lt;br /&gt;
		try {&lt;br /&gt;
			sha = MessageDigest.getInstance(&amp;quot;SHA-1&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		catch (NoSuchAlgorithmException e) {&lt;br /&gt;
			throw new ServletException(e);&lt;br /&gt;
		}&lt;br /&gt;
		byte[] digest = sha.digest(randomNum.getBytes());&lt;br /&gt;
		// --Encode it into HEXA&lt;br /&gt;
		String scriptNonce = Hex.encodeHexString(digest);&lt;br /&gt;
		policiesBuffer.append(&amp;quot;;&amp;quot;).append(&amp;quot;script-nonce &amp;quot;).append(scriptNonce);&lt;br /&gt;
		// --Made available script nonce in view app layer&lt;br /&gt;
		httpRequest.setAttribute(&amp;quot;CSP_SCRIPT_NONCE&amp;quot;, scriptNonce);&lt;br /&gt;
&lt;br /&gt;
		// Add policies to all HTTP headers&lt;br /&gt;
		for (String header : this.cspHeaders) {&lt;br /&gt;
			httpResponse.setHeader(header, policiesBuffer.toString());&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		/* Step 3 : Let request continue chain filter */&lt;br /&gt;
		fchain.doFilter(request, response);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * {@inheritDoc}&lt;br /&gt;
	 * &lt;br /&gt;
	 * @see javax.servlet.Filter#destroy()&lt;br /&gt;
	 */&lt;br /&gt;
	@Override&lt;br /&gt;
	public void destroy() {&lt;br /&gt;
		// Not used&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:'''&lt;br /&gt;
[[Automated Audit using W3AF|W3AF]] audit tools (http://w3af.org) contain plugins to automatically audit web application to check if they correctly implement CSP policies. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:#088A08&amp;quot;&amp;gt;&lt;br /&gt;
It's very useful to include this type of tools into a web application development process in order to &lt;br /&gt;
perform a regular automatic first level check (do not replace an manual audit and manual audit must be also conducted regularly).&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Information links ==&lt;br /&gt;
* W3C Specification (last specs release) : http://www.w3.org/TR/CSP&lt;br /&gt;
* Introduction to CSP: http://www.html5rocks.com/en/tutorials/security/content-security-policy&lt;br /&gt;
* CSP browser support: http://caniuse.com/#feat=contentsecuritypolicy&lt;br /&gt;
* CSP readiness browser testing: http://erlend.oftedal.no/blog/csp/readiness/&lt;br /&gt;
* CSP proposal by Mozilla Security ('''deprecated''', use W3C specs): https://wiki.mozilla.org/Security/CSP/Specification&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP Java Project]]&lt;br /&gt;
[[Category: Injection]]&lt;br /&gt;
[[Category:Attack]]&lt;br /&gt;
[[Category:Injection Attack]]&lt;/div&gt;</summary>
		<author><name>Dimisec</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Content_Security_Policy&amp;diff=150698</id>
		<title>Content Security Policy</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Content_Security_Policy&amp;diff=150698"/>
				<updated>2013-04-30T09:12:38Z</updated>
		
		<summary type="html">&lt;p&gt;Dimisec: added caniuse.com link to the links session; renamed it to &amp;quot;Information Links&amp;quot; (singular &amp;quot;Information&amp;quot;)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Last revision (mm/dd/yy): '''02/03/2013'''&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
'''CSP''' stands for '''C'''ontent '''S'''ecurity '''P'''olicy. &lt;br /&gt;
&lt;br /&gt;
Is an W3C specification offering the possbility to instruct the client browser from which location and/or which type of resources are allowed to be loaded. To define a loading behavior, the CSP specification use &amp;quot;directive&amp;quot; where a directive define a loading behavior for a target resource type.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This article is based on version [https://dvcs.w3.org/hg/content-security-policy/raw-file/tip/csp-specification.dev.html 1.1] of the W3C specification.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Directives can be specified using HTTP response header (a server may send more than one CSP HTTP header field with a given resource representation and a server may send different CSP header field values with different representations of the same resource or with different resources) or HTML Meta tag, the HTTP headers below are defined by the specs:&lt;br /&gt;
* '''Content-Security-Policy''' : Defined by W3C Specs as standard header, used by Chrome starting with version 25&lt;br /&gt;
* '''X-Content-Security-Policy''' : Used by Firefox and Internet Explorer,&lt;br /&gt;
* '''X-WebKit-CSP''' : Used by Chrome (will transition to Content-Security-Policy)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The supported directives are:&lt;br /&gt;
* '''default-src''' : Define loading policy for all resources type in case of a resource type dedicated directive is not defined (fallback),&lt;br /&gt;
* '''script-src''' :  Define which scripts the protected resource can execute,&lt;br /&gt;
* '''object-src''' :  Define from where the protected resource can load plugins,&lt;br /&gt;
* '''style-src''' : Define which styles (CSS) the user applies to the protected resource,&lt;br /&gt;
* '''img-src''' : Define from where the protected resource can load images,&lt;br /&gt;
* '''media-src''' : Define from where the protected resource can load video and audio,&lt;br /&gt;
* '''frame-src''' : Define from where the protected resource can embed frames,&lt;br /&gt;
* '''font-src''' : Define from where the protected resource can load fonts,&lt;br /&gt;
* '''connect-src''' : Define which URIs the protected resource can load using script interfaces,&lt;br /&gt;
* '''form-action''' : Define which URIs can be used as the action of HTML form elements,&lt;br /&gt;
* '''sandbox''' : Specifies an HTML sandbox policy that the user agent applies to the protected resource,&lt;br /&gt;
* '''script-nonce''' : Define script execution by requiring the presence of the specified nonce on script elements,&lt;br /&gt;
* '''plugin-types''' : Define the set of plugins that can be invoked by the protected resource by limiting the types of resources that can be embedded,&lt;br /&gt;
* '''reflected-xss''' : Instructs a user agent to active or disactivate any heuristics used to filter or block reflected cross-site scripting attacks.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An introduction to CSP is available on [http://www.html5rocks.com/en/tutorials/security/content-security-policy/ HTML5Rocks].  The browser support is shown on http://caniuse.com/#feat=contentsecuritypolicy&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Risk ==&lt;br /&gt;
The risk with CSP can have 2 main sources:&lt;br /&gt;
# Policies misconfiguration,&lt;br /&gt;
# Too permissive policies.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Countermeasure ==&lt;br /&gt;
This article will focus on providing an sample implementation of a JEE Web Filter in order to apply a set of CSP policies on all HTTP response returned by server. &lt;br /&gt;
&lt;br /&gt;
The policies will instructs the browser to have the loading behavior below using all HTTP headers defined in W3C Specs:&lt;br /&gt;
* Explicit loading definition of each resource type,&lt;br /&gt;
* Resources are loaded only from source domain,&lt;br /&gt;
* Inline style is not allowed,&lt;br /&gt;
* For JavaScript:&lt;br /&gt;
** ''Inline script'' will be allowed because inline scripting it's commonly used (can be disabled if target site do not use this type of scripting),&lt;br /&gt;
** ''eval()'' function will be allowed in order to not break use of popular JavaScript libraries (ex: JQuery, JQueryUI, Sencha, ...) because they use eval() function (it was the case last time I have checked the source code from CDN ;) ),&lt;br /&gt;
* Generation of a random not guessable script nonce to use into all script tag,&lt;br /&gt;
* Plugin types only allow PDF and Flash,&lt;br /&gt;
* No font loading (configurable),&lt;br /&gt;
* No Audio / Video loading (configurable),&lt;br /&gt;
* Enable browser XSS filtering feature.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:navy&amp;quot;&amp;gt;&lt;br /&gt;
The support for CSP directives is not the same level in major browsers (Firefox/Chrome/IE). It's recommanded to check the support &lt;br /&gt;
provided by target browsers  (using site provided in link section of this article) in order to configure CSP policies. The sample &lt;br /&gt;
below try to provide a set of policies from which your can add policies specific to your application context.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''This implementation provide an option to add CSP directives used by Firefox (Mozilla CSP directives).''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.security.MessageDigest;&lt;br /&gt;
import java.security.NoSuchAlgorithmException;&lt;br /&gt;
import java.security.SecureRandom;&lt;br /&gt;
import java.util.ArrayList;&lt;br /&gt;
import java.util.List;&lt;br /&gt;
&lt;br /&gt;
import javax.servlet.Filter;&lt;br /&gt;
import javax.servlet.FilterChain;&lt;br /&gt;
import javax.servlet.FilterConfig;&lt;br /&gt;
import javax.servlet.ServletException;&lt;br /&gt;
import javax.servlet.ServletRequest;&lt;br /&gt;
import javax.servlet.ServletResponse;&lt;br /&gt;
import javax.servlet.annotation.WebFilter;&lt;br /&gt;
import javax.servlet.http.HttpServletRequest;&lt;br /&gt;
import javax.servlet.http.HttpServletResponse;&lt;br /&gt;
&lt;br /&gt;
import org.apache.commons.codec.binary.Hex;&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * Sample filter implementation to define a set of Content Security Policies.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 * This implementation has a dependency on Commons Codec API.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 * This filter set CSP policies using all HTTP headers defined into W3C specification.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &amp;lt;br/&amp;gt;&lt;br /&gt;
 * This implementation is oriented to be easily understandable and easily adapted.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
@WebFilter(&amp;quot;/*&amp;quot;)&lt;br /&gt;
public class CSPPoliciesApplier implements Filter {&lt;br /&gt;
&lt;br /&gt;
	/** Configuration member to specify if web app use web fonts */&lt;br /&gt;
	public static final boolean APP_USE_WEBFONTS = false;&lt;br /&gt;
&lt;br /&gt;
	/** Configuration member to specify if web app use videos or audios */&lt;br /&gt;
	public static final boolean APP_USE_AUDIOS_OR_VIDEOS = false;&lt;br /&gt;
&lt;br /&gt;
	/** Configuration member to specify if filter must add CSP directive used by Mozilla (Firefox) */&lt;br /&gt;
	public static final boolean INCLUDE_MOZILLA_CSP_DIRECTIVES = true;&lt;br /&gt;
&lt;br /&gt;
	/** Filter configuration */&lt;br /&gt;
	@SuppressWarnings(&amp;quot;unused&amp;quot;)&lt;br /&gt;
	private FilterConfig filterConfig = null;&lt;br /&gt;
&lt;br /&gt;
	/** List CSP HTTP Headers */&lt;br /&gt;
	private List&amp;lt;String&amp;gt; cspHeaders = new ArrayList&amp;lt;String&amp;gt;();&lt;br /&gt;
&lt;br /&gt;
	/** Collection of CSP polcies that will be applied */&lt;br /&gt;
	private String policies = null;&lt;br /&gt;
&lt;br /&gt;
	/** Used for Script Nonce */&lt;br /&gt;
	private SecureRandom prng = null;&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Used to prepare (one time for all) set of CSP policies that will be applied on each HTTP response.&lt;br /&gt;
	 * &lt;br /&gt;
	 * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)&lt;br /&gt;
	 */&lt;br /&gt;
	@Override&lt;br /&gt;
	public void init(FilterConfig fConfig) throws ServletException {&lt;br /&gt;
		// Get filter configuration&lt;br /&gt;
		this.filterConfig = fConfig;&lt;br /&gt;
&lt;br /&gt;
		// Init secure random&lt;br /&gt;
		try {&lt;br /&gt;
			this.prng = SecureRandom.getInstance(&amp;quot;SHA1PRNG&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		catch (NoSuchAlgorithmException e) {&lt;br /&gt;
			throw new ServletException(e);&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		// Define list of CSP HTTP Headers&lt;br /&gt;
		this.cspHeaders.add(&amp;quot;Content-Security-Policy&amp;quot;);&lt;br /&gt;
		this.cspHeaders.add(&amp;quot;X-Content-Security-Policy&amp;quot;);&lt;br /&gt;
		this.cspHeaders.add(&amp;quot;X-WebKit-CSP&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
		// Define CSP policies&lt;br /&gt;
		// Loading policies for Frame and Sandboxing will be dynamically defined : We need to know if context use Frame&lt;br /&gt;
		List&amp;lt;String&amp;gt; cspPolicies = new ArrayList&amp;lt;String&amp;gt;();&lt;br /&gt;
		String originLocationRef = &amp;quot;'self'&amp;quot;;&lt;br /&gt;
		// --Disable default source in order to avoid browser fallback loading using 'default-src' locations&lt;br /&gt;
		cspPolicies.add(&amp;quot;default-src 'none'&amp;quot;);&lt;br /&gt;
		// --Define loading policies for Scripts&lt;br /&gt;
		cspPolicies.add(&amp;quot;script-src &amp;quot; + originLocationRef + &amp;quot; 'unsafe-inline' 'unsafe-eval'&amp;quot;);&lt;br /&gt;
		if (INCLUDE_MOZILLA_CSP_DIRECTIVES) {&lt;br /&gt;
			cspPolicies.add(&amp;quot;options inline-script eval-script&amp;quot;);&lt;br /&gt;
			cspPolicies.add(&amp;quot;xhr-src 'self'&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		// --Define loading policies for Plugins&lt;br /&gt;
		cspPolicies.add(&amp;quot;object-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Styles (CSS)&lt;br /&gt;
		cspPolicies.add(&amp;quot;style-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Images&lt;br /&gt;
		cspPolicies.add(&amp;quot;img-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Form&lt;br /&gt;
		cspPolicies.add(&amp;quot;form-action &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Audios/Videos&lt;br /&gt;
		if (APP_USE_AUDIOS_OR_VIDEOS) {&lt;br /&gt;
			cspPolicies.add(&amp;quot;media-src &amp;quot; + originLocationRef);&lt;br /&gt;
		}&lt;br /&gt;
		// --Define loading policies for Fonts&lt;br /&gt;
		if (APP_USE_WEBFONTS) {&lt;br /&gt;
			cspPolicies.add(&amp;quot;font-src &amp;quot; + originLocationRef);&lt;br /&gt;
		}&lt;br /&gt;
		// --Define loading policies for Connection&lt;br /&gt;
		cspPolicies.add(&amp;quot;connect-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Plugins Types&lt;br /&gt;
		cspPolicies.add(&amp;quot;plugin-types application/pdf application/x-shockwave-flash&amp;quot;);&lt;br /&gt;
		// --Define browser XSS filtering feature running mode&lt;br /&gt;
		cspPolicies.add(&amp;quot;reflected-xss block&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
		// Target formating&lt;br /&gt;
		this.policies = cspPolicies.toString().replaceAll(&amp;quot;(\\[|\\])&amp;quot;, &amp;quot;&amp;quot;).replaceAll(&amp;quot;,&amp;quot;, &amp;quot;;&amp;quot;).trim();&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Add CSP policies on each HTTP response.&lt;br /&gt;
	 * &lt;br /&gt;
	 * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)&lt;br /&gt;
	 */&lt;br /&gt;
	@Override&lt;br /&gt;
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain fchain) throws IOException, ServletException {&lt;br /&gt;
		HttpServletRequest httpRequest = ((HttpServletRequest) request);&lt;br /&gt;
		HttpServletResponse httpResponse = ((HttpServletResponse) response);&lt;br /&gt;
&lt;br /&gt;
		/* Step 1 : Detect if target resource is a Frame */&lt;br /&gt;
		// Customize here according to your context...&lt;br /&gt;
		boolean isFrame = true;&lt;br /&gt;
&lt;br /&gt;
		/* Step 2 : Add CSP policies to HTTP response */&lt;br /&gt;
		StringBuilder policiesBuffer = new StringBuilder(this.policies);&lt;br /&gt;
&lt;br /&gt;
		// If resource is a frame add Frame/Sandbox CSP policy&lt;br /&gt;
		if (isFrame) {&lt;br /&gt;
			// Frame + Sandbox : Here sandbox allow nothing, customize sandbox options depending on your app....&lt;br /&gt;
			policiesBuffer.append(&amp;quot;;&amp;quot;).append(&amp;quot;frame-src 'self';sandbox&amp;quot;);&lt;br /&gt;
			if (INCLUDE_MOZILLA_CSP_DIRECTIVES) {&lt;br /&gt;
				policiesBuffer.append(&amp;quot;;&amp;quot;).append(&amp;quot;frame-ancestors 'self'&amp;quot;);&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		// Add Script Nonce CSP Policy&lt;br /&gt;
		// --Generate a random number&lt;br /&gt;
		String randomNum = new Integer(this.prng.nextInt()).toString();&lt;br /&gt;
		// --Get its digest&lt;br /&gt;
		MessageDigest sha;&lt;br /&gt;
		try {&lt;br /&gt;
			sha = MessageDigest.getInstance(&amp;quot;SHA-1&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		catch (NoSuchAlgorithmException e) {&lt;br /&gt;
			throw new ServletException(e);&lt;br /&gt;
		}&lt;br /&gt;
		byte[] digest = sha.digest(randomNum.getBytes());&lt;br /&gt;
		// --Encode it into HEXA&lt;br /&gt;
		String scriptNonce = Hex.encodeHexString(digest);&lt;br /&gt;
		policiesBuffer.append(&amp;quot;;&amp;quot;).append(&amp;quot;script-nonce &amp;quot;).append(scriptNonce);&lt;br /&gt;
		// --Made available script nonce in view app layer&lt;br /&gt;
		httpRequest.setAttribute(&amp;quot;CSP_SCRIPT_NONCE&amp;quot;, scriptNonce);&lt;br /&gt;
&lt;br /&gt;
		// Add policies to all HTTP headers&lt;br /&gt;
		for (String header : this.cspHeaders) {&lt;br /&gt;
			httpResponse.setHeader(header, policiesBuffer.toString());&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		/* Step 3 : Let request continue chain filter */&lt;br /&gt;
		fchain.doFilter(request, response);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * {@inheritDoc}&lt;br /&gt;
	 * &lt;br /&gt;
	 * @see javax.servlet.Filter#destroy()&lt;br /&gt;
	 */&lt;br /&gt;
	@Override&lt;br /&gt;
	public void destroy() {&lt;br /&gt;
		// Not used&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:'''&lt;br /&gt;
[[Automated Audit using W3AF|W3AF]] audit tools (http://w3af.org) contain plugins to automatically audit web application to check if they correctly implement CSP policies. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:#088A08&amp;quot;&amp;gt;&lt;br /&gt;
It's very useful to include this type of tools into a web application development process in order to &lt;br /&gt;
perform a regular automatic first level check (do not replace an manual audit and manual audit must be also conducted regularly).&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Information links ==&lt;br /&gt;
* W3C Specification (last specs release) : http://www.w3.org/TR/CSP&lt;br /&gt;
* Introduction to CSP: http://www.html5rocks.com/en/tutorials/security/content-security-policy&lt;br /&gt;
* CSP browser support: http://caniuse.com/#feat=contentsecuritypolicy&lt;br /&gt;
* CSP readiness browser testing: http://erlend.oftedal.no/blog/csp/readiness/&lt;br /&gt;
* CSP proposal by Mozilla Security ('''deprecated''', use W3C specs): https://wiki.mozilla.org/Security/CSP/Specification&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP Java Project]]&lt;br /&gt;
[[Category: Injection]]&lt;br /&gt;
[[Category:Attack]]&lt;br /&gt;
[[Category:Injection Attack]]&lt;/div&gt;</summary>
		<author><name>Dimisec</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Content_Security_Policy&amp;diff=150697</id>
		<title>Content Security Policy</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Content_Security_Policy&amp;diff=150697"/>
				<updated>2013-04-30T09:08:18Z</updated>
		
		<summary type="html">&lt;p&gt;Dimisec: grammar (plural case)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Last revision (mm/dd/yy): '''02/03/2013'''&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
'''CSP''' stands for '''C'''ontent '''S'''ecurity '''P'''olicy. &lt;br /&gt;
&lt;br /&gt;
Is an W3C specification offering the possbility to instruct the client browser from which location and/or which type of resources are allowed to be loaded. To define a loading behavior, the CSP specification use &amp;quot;directive&amp;quot; where a directive define a loading behavior for a target resource type.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This article is based on version [https://dvcs.w3.org/hg/content-security-policy/raw-file/tip/csp-specification.dev.html 1.1] of the W3C specification.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Directives can be specified using HTTP response header (a server may send more than one CSP HTTP header field with a given resource representation and a server may send different CSP header field values with different representations of the same resource or with different resources) or HTML Meta tag, the HTTP headers below are defined by the specs:&lt;br /&gt;
* '''Content-Security-Policy''' : Defined by W3C Specs as standard header, used by Chrome starting with version 25&lt;br /&gt;
* '''X-Content-Security-Policy''' : Used by Firefox and Internet Explorer,&lt;br /&gt;
* '''X-WebKit-CSP''' : Used by Chrome (will transition to Content-Security-Policy)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The supported directives are:&lt;br /&gt;
* '''default-src''' : Define loading policy for all resources type in case of a resource type dedicated directive is not defined (fallback),&lt;br /&gt;
* '''script-src''' :  Define which scripts the protected resource can execute,&lt;br /&gt;
* '''object-src''' :  Define from where the protected resource can load plugins,&lt;br /&gt;
* '''style-src''' : Define which styles (CSS) the user applies to the protected resource,&lt;br /&gt;
* '''img-src''' : Define from where the protected resource can load images,&lt;br /&gt;
* '''media-src''' : Define from where the protected resource can load video and audio,&lt;br /&gt;
* '''frame-src''' : Define from where the protected resource can embed frames,&lt;br /&gt;
* '''font-src''' : Define from where the protected resource can load fonts,&lt;br /&gt;
* '''connect-src''' : Define which URIs the protected resource can load using script interfaces,&lt;br /&gt;
* '''form-action''' : Define which URIs can be used as the action of HTML form elements,&lt;br /&gt;
* '''sandbox''' : Specifies an HTML sandbox policy that the user agent applies to the protected resource,&lt;br /&gt;
* '''script-nonce''' : Define script execution by requiring the presence of the specified nonce on script elements,&lt;br /&gt;
* '''plugin-types''' : Define the set of plugins that can be invoked by the protected resource by limiting the types of resources that can be embedded,&lt;br /&gt;
* '''reflected-xss''' : Instructs a user agent to active or disactivate any heuristics used to filter or block reflected cross-site scripting attacks.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An introduction to CSP is available on [http://www.html5rocks.com/en/tutorials/security/content-security-policy/ HTML5Rocks].  The browser support is shown on http://caniuse.com/#feat=contentsecuritypolicy&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Risk ==&lt;br /&gt;
The risk with CSP can have 2 main sources:&lt;br /&gt;
# Policies misconfiguration,&lt;br /&gt;
# Too permissive policies.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Countermeasure ==&lt;br /&gt;
This article will focus on providing an sample implementation of a JEE Web Filter in order to apply a set of CSP policies on all HTTP response returned by server. &lt;br /&gt;
&lt;br /&gt;
The policies will instructs the browser to have the loading behavior below using all HTTP headers defined in W3C Specs:&lt;br /&gt;
* Explicit loading definition of each resource type,&lt;br /&gt;
* Resources are loaded only from source domain,&lt;br /&gt;
* Inline style is not allowed,&lt;br /&gt;
* For JavaScript:&lt;br /&gt;
** ''Inline script'' will be allowed because inline scripting it's commonly used (can be disabled if target site do not use this type of scripting),&lt;br /&gt;
** ''eval()'' function will be allowed in order to not break use of popular JavaScript libraries (ex: JQuery, JQueryUI, Sencha, ...) because they use eval() function (it was the case last time I have checked the source code from CDN ;) ),&lt;br /&gt;
* Generation of a random not guessable script nonce to use into all script tag,&lt;br /&gt;
* Plugin types only allow PDF and Flash,&lt;br /&gt;
* No font loading (configurable),&lt;br /&gt;
* No Audio / Video loading (configurable),&lt;br /&gt;
* Enable browser XSS filtering feature.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:navy&amp;quot;&amp;gt;&lt;br /&gt;
The support for CSP directives is not the same level in major browsers (Firefox/Chrome/IE). It's recommanded to check the support &lt;br /&gt;
provided by target browsers  (using site provided in link section of this article) in order to configure CSP policies. The sample &lt;br /&gt;
below try to provide a set of policies from which your can add policies specific to your application context.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''This implementation provide an option to add CSP directives used by Firefox (Mozilla CSP directives).''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.security.MessageDigest;&lt;br /&gt;
import java.security.NoSuchAlgorithmException;&lt;br /&gt;
import java.security.SecureRandom;&lt;br /&gt;
import java.util.ArrayList;&lt;br /&gt;
import java.util.List;&lt;br /&gt;
&lt;br /&gt;
import javax.servlet.Filter;&lt;br /&gt;
import javax.servlet.FilterChain;&lt;br /&gt;
import javax.servlet.FilterConfig;&lt;br /&gt;
import javax.servlet.ServletException;&lt;br /&gt;
import javax.servlet.ServletRequest;&lt;br /&gt;
import javax.servlet.ServletResponse;&lt;br /&gt;
import javax.servlet.annotation.WebFilter;&lt;br /&gt;
import javax.servlet.http.HttpServletRequest;&lt;br /&gt;
import javax.servlet.http.HttpServletResponse;&lt;br /&gt;
&lt;br /&gt;
import org.apache.commons.codec.binary.Hex;&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * Sample filter implementation to define a set of Content Security Policies.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 * This implementation has a dependency on Commons Codec API.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 * This filter set CSP policies using all HTTP headers defined into W3C specification.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &amp;lt;br/&amp;gt;&lt;br /&gt;
 * This implementation is oriented to be easily understandable and easily adapted.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
@WebFilter(&amp;quot;/*&amp;quot;)&lt;br /&gt;
public class CSPPoliciesApplier implements Filter {&lt;br /&gt;
&lt;br /&gt;
	/** Configuration member to specify if web app use web fonts */&lt;br /&gt;
	public static final boolean APP_USE_WEBFONTS = false;&lt;br /&gt;
&lt;br /&gt;
	/** Configuration member to specify if web app use videos or audios */&lt;br /&gt;
	public static final boolean APP_USE_AUDIOS_OR_VIDEOS = false;&lt;br /&gt;
&lt;br /&gt;
	/** Configuration member to specify if filter must add CSP directive used by Mozilla (Firefox) */&lt;br /&gt;
	public static final boolean INCLUDE_MOZILLA_CSP_DIRECTIVES = true;&lt;br /&gt;
&lt;br /&gt;
	/** Filter configuration */&lt;br /&gt;
	@SuppressWarnings(&amp;quot;unused&amp;quot;)&lt;br /&gt;
	private FilterConfig filterConfig = null;&lt;br /&gt;
&lt;br /&gt;
	/** List CSP HTTP Headers */&lt;br /&gt;
	private List&amp;lt;String&amp;gt; cspHeaders = new ArrayList&amp;lt;String&amp;gt;();&lt;br /&gt;
&lt;br /&gt;
	/** Collection of CSP polcies that will be applied */&lt;br /&gt;
	private String policies = null;&lt;br /&gt;
&lt;br /&gt;
	/** Used for Script Nonce */&lt;br /&gt;
	private SecureRandom prng = null;&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Used to prepare (one time for all) set of CSP policies that will be applied on each HTTP response.&lt;br /&gt;
	 * &lt;br /&gt;
	 * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)&lt;br /&gt;
	 */&lt;br /&gt;
	@Override&lt;br /&gt;
	public void init(FilterConfig fConfig) throws ServletException {&lt;br /&gt;
		// Get filter configuration&lt;br /&gt;
		this.filterConfig = fConfig;&lt;br /&gt;
&lt;br /&gt;
		// Init secure random&lt;br /&gt;
		try {&lt;br /&gt;
			this.prng = SecureRandom.getInstance(&amp;quot;SHA1PRNG&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		catch (NoSuchAlgorithmException e) {&lt;br /&gt;
			throw new ServletException(e);&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		// Define list of CSP HTTP Headers&lt;br /&gt;
		this.cspHeaders.add(&amp;quot;Content-Security-Policy&amp;quot;);&lt;br /&gt;
		this.cspHeaders.add(&amp;quot;X-Content-Security-Policy&amp;quot;);&lt;br /&gt;
		this.cspHeaders.add(&amp;quot;X-WebKit-CSP&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
		// Define CSP policies&lt;br /&gt;
		// Loading policies for Frame and Sandboxing will be dynamically defined : We need to know if context use Frame&lt;br /&gt;
		List&amp;lt;String&amp;gt; cspPolicies = new ArrayList&amp;lt;String&amp;gt;();&lt;br /&gt;
		String originLocationRef = &amp;quot;'self'&amp;quot;;&lt;br /&gt;
		// --Disable default source in order to avoid browser fallback loading using 'default-src' locations&lt;br /&gt;
		cspPolicies.add(&amp;quot;default-src 'none'&amp;quot;);&lt;br /&gt;
		// --Define loading policies for Scripts&lt;br /&gt;
		cspPolicies.add(&amp;quot;script-src &amp;quot; + originLocationRef + &amp;quot; 'unsafe-inline' 'unsafe-eval'&amp;quot;);&lt;br /&gt;
		if (INCLUDE_MOZILLA_CSP_DIRECTIVES) {&lt;br /&gt;
			cspPolicies.add(&amp;quot;options inline-script eval-script&amp;quot;);&lt;br /&gt;
			cspPolicies.add(&amp;quot;xhr-src 'self'&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		// --Define loading policies for Plugins&lt;br /&gt;
		cspPolicies.add(&amp;quot;object-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Styles (CSS)&lt;br /&gt;
		cspPolicies.add(&amp;quot;style-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Images&lt;br /&gt;
		cspPolicies.add(&amp;quot;img-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Form&lt;br /&gt;
		cspPolicies.add(&amp;quot;form-action &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Audios/Videos&lt;br /&gt;
		if (APP_USE_AUDIOS_OR_VIDEOS) {&lt;br /&gt;
			cspPolicies.add(&amp;quot;media-src &amp;quot; + originLocationRef);&lt;br /&gt;
		}&lt;br /&gt;
		// --Define loading policies for Fonts&lt;br /&gt;
		if (APP_USE_WEBFONTS) {&lt;br /&gt;
			cspPolicies.add(&amp;quot;font-src &amp;quot; + originLocationRef);&lt;br /&gt;
		}&lt;br /&gt;
		// --Define loading policies for Connection&lt;br /&gt;
		cspPolicies.add(&amp;quot;connect-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Plugins Types&lt;br /&gt;
		cspPolicies.add(&amp;quot;plugin-types application/pdf application/x-shockwave-flash&amp;quot;);&lt;br /&gt;
		// --Define browser XSS filtering feature running mode&lt;br /&gt;
		cspPolicies.add(&amp;quot;reflected-xss block&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
		// Target formating&lt;br /&gt;
		this.policies = cspPolicies.toString().replaceAll(&amp;quot;(\\[|\\])&amp;quot;, &amp;quot;&amp;quot;).replaceAll(&amp;quot;,&amp;quot;, &amp;quot;;&amp;quot;).trim();&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Add CSP policies on each HTTP response.&lt;br /&gt;
	 * &lt;br /&gt;
	 * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)&lt;br /&gt;
	 */&lt;br /&gt;
	@Override&lt;br /&gt;
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain fchain) throws IOException, ServletException {&lt;br /&gt;
		HttpServletRequest httpRequest = ((HttpServletRequest) request);&lt;br /&gt;
		HttpServletResponse httpResponse = ((HttpServletResponse) response);&lt;br /&gt;
&lt;br /&gt;
		/* Step 1 : Detect if target resource is a Frame */&lt;br /&gt;
		// Customize here according to your context...&lt;br /&gt;
		boolean isFrame = true;&lt;br /&gt;
&lt;br /&gt;
		/* Step 2 : Add CSP policies to HTTP response */&lt;br /&gt;
		StringBuilder policiesBuffer = new StringBuilder(this.policies);&lt;br /&gt;
&lt;br /&gt;
		// If resource is a frame add Frame/Sandbox CSP policy&lt;br /&gt;
		if (isFrame) {&lt;br /&gt;
			// Frame + Sandbox : Here sandbox allow nothing, customize sandbox options depending on your app....&lt;br /&gt;
			policiesBuffer.append(&amp;quot;;&amp;quot;).append(&amp;quot;frame-src 'self';sandbox&amp;quot;);&lt;br /&gt;
			if (INCLUDE_MOZILLA_CSP_DIRECTIVES) {&lt;br /&gt;
				policiesBuffer.append(&amp;quot;;&amp;quot;).append(&amp;quot;frame-ancestors 'self'&amp;quot;);&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		// Add Script Nonce CSP Policy&lt;br /&gt;
		// --Generate a random number&lt;br /&gt;
		String randomNum = new Integer(this.prng.nextInt()).toString();&lt;br /&gt;
		// --Get its digest&lt;br /&gt;
		MessageDigest sha;&lt;br /&gt;
		try {&lt;br /&gt;
			sha = MessageDigest.getInstance(&amp;quot;SHA-1&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		catch (NoSuchAlgorithmException e) {&lt;br /&gt;
			throw new ServletException(e);&lt;br /&gt;
		}&lt;br /&gt;
		byte[] digest = sha.digest(randomNum.getBytes());&lt;br /&gt;
		// --Encode it into HEXA&lt;br /&gt;
		String scriptNonce = Hex.encodeHexString(digest);&lt;br /&gt;
		policiesBuffer.append(&amp;quot;;&amp;quot;).append(&amp;quot;script-nonce &amp;quot;).append(scriptNonce);&lt;br /&gt;
		// --Made available script nonce in view app layer&lt;br /&gt;
		httpRequest.setAttribute(&amp;quot;CSP_SCRIPT_NONCE&amp;quot;, scriptNonce);&lt;br /&gt;
&lt;br /&gt;
		// Add policies to all HTTP headers&lt;br /&gt;
		for (String header : this.cspHeaders) {&lt;br /&gt;
			httpResponse.setHeader(header, policiesBuffer.toString());&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		/* Step 3 : Let request continue chain filter */&lt;br /&gt;
		fchain.doFilter(request, response);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * {@inheritDoc}&lt;br /&gt;
	 * &lt;br /&gt;
	 * @see javax.servlet.Filter#destroy()&lt;br /&gt;
	 */&lt;br /&gt;
	@Override&lt;br /&gt;
	public void destroy() {&lt;br /&gt;
		// Not used&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:'''&lt;br /&gt;
[[Automated Audit using W3AF|W3AF]] audit tools (http://w3af.org) contain plugins to automatically audit web application to check if they correctly implement CSP policies. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:#088A08&amp;quot;&amp;gt;&lt;br /&gt;
It's very useful to include this type of tools into a web application development process in order to &lt;br /&gt;
perform a regular automatic first level check (do not replace an manual audit and manual audit must be also conducted regularly).&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Informations links ==&lt;br /&gt;
* W3C Specification (last specs release) : http://www.w3.org/TR/CSP&lt;br /&gt;
* Introduction to CSP: http://www.html5rocks.com/en/tutorials/security/content-security-policy&lt;br /&gt;
* CSP readiness browser testing: http://erlend.oftedal.no/blog/csp/readiness/&lt;br /&gt;
* CSP proposal by Mozilla Security ('''deprecated''', use W3C specs): https://wiki.mozilla.org/Security/CSP/Specification&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP Java Project]]&lt;br /&gt;
[[Category: Injection]]&lt;br /&gt;
[[Category:Attack]]&lt;br /&gt;
[[Category:Injection Attack]]&lt;/div&gt;</summary>
		<author><name>Dimisec</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Content_Security_Policy&amp;diff=150696</id>
		<title>Content Security Policy</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Content_Security_Policy&amp;diff=150696"/>
				<updated>2013-04-30T09:07:14Z</updated>
		
		<summary type="html">&lt;p&gt;Dimisec: grammar&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Last revision (mm/dd/yy): '''02/03/2013'''&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
'''CSP''' stands for '''C'''ontent '''S'''ecurity '''P'''olicy. &lt;br /&gt;
&lt;br /&gt;
Is an W3C specification offering the possbility to instruct the client browser from which location and/or which type of resources are allowed to be loaded. To define a loading behavior, the CSP specification use &amp;quot;directive&amp;quot; where a directive define a loading behavior for a target resource type.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This article is based on version [https://dvcs.w3.org/hg/content-security-policy/raw-file/tip/csp-specification.dev.html 1.1] of the W3C specification.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Directives can be specified using HTTP response header (a server may send more than one CSP HTTP header field with a given resource representation and a server may send different CSP header field values with different representations of the same resource or with different resources) or HTML Meta tag, the HTTP headers below are defined by the specs:&lt;br /&gt;
* '''Content-Security-Policy''' : Defined by W3C Specs as standard header, used by Chrome starting with version 25&lt;br /&gt;
* '''X-Content-Security-Policy''' : Used by Firefox and Internet Explorer,&lt;br /&gt;
* '''X-WebKit-CSP''' : Used by Chrome (will transition to Content-Security-Policy)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The supported directives are:&lt;br /&gt;
* '''default-src''' : Define loading policy for all resources type in case of a resource type dedicated directive is not defined (fallback),&lt;br /&gt;
* '''script-src''' :  Define which scripts the protected resource can execute,&lt;br /&gt;
* '''object-src''' :  Define from where the protected resource can load plugins,&lt;br /&gt;
* '''style-src''' : Define which styles (CSS) the user applies to the protected resource,&lt;br /&gt;
* '''img-src''' : Define from where the protected resource can load images,&lt;br /&gt;
* '''media-src''' : Define from where the protected resource can load video and audio,&lt;br /&gt;
* '''frame-src''' : Define from where the protected resource can embed frames,&lt;br /&gt;
* '''font-src''' : Define from where the protected resource can load fonts,&lt;br /&gt;
* '''connect-src''' : Define which URIs the protected resource can load using script interfaces,&lt;br /&gt;
* '''form-action''' : Define which URIs can be used as the action of HTML form elements,&lt;br /&gt;
* '''sandbox''' : Specifies an HTML sandbox policy that the user agent applies to the protected resource,&lt;br /&gt;
* '''script-nonce''' : Define script execution by requiring the presence of the specified nonce on script elements,&lt;br /&gt;
* '''plugin-types''' : Define the set of plugins that can be invoked by the protected resource by limiting the types of resources that can be embedded,&lt;br /&gt;
* '''reflected-xss''' : Instructs a user agent to active or disactivate any heuristics used to filter or block reflected cross-site scripting attacks.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An introduction to CSP is available on [http://www.html5rocks.com/en/tutorials/security/content-security-policy/ HTML5Rocks].  The browser support is shown on http://caniuse.com/#feat=contentsecuritypolicy&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Risk ==&lt;br /&gt;
The risk with CSP can have 2 main sources:&lt;br /&gt;
# Policies misconfiguration,&lt;br /&gt;
# Too permissive policies.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Countermeasure ==&lt;br /&gt;
This article will focus on providing an sample implementation of a JEE Web Filter in order to apply a set of CSP policies on all HTTP response returned by server. &lt;br /&gt;
&lt;br /&gt;
The policies will instructs the browser to have the loading behavior below using all HTTP headers defined in W3C Specs:&lt;br /&gt;
* Explicit loading definition of each resource type,&lt;br /&gt;
* Resources are loaded only from source domain,&lt;br /&gt;
* Inline style is not allowed,&lt;br /&gt;
* For JavaScript:&lt;br /&gt;
** ''Inline script'' will be allowed because inline scripting it's commonly used (can be disabled if target site do not use this type of scripting),&lt;br /&gt;
** ''eval()'' function will be allowed in order to not break use of popular JavaScript libraries (ex: JQuery, JQueryUI, Sencha, ...) because they use eval() function (it was the case last time I have checked the source code from CDN ;) ),&lt;br /&gt;
* Generation of a random not guessable script nonce to use into all script tag,&lt;br /&gt;
* Plugin types only allow PDF and Flash,&lt;br /&gt;
* No font loading (configurable),&lt;br /&gt;
* No Audio / Video loading (configurable),&lt;br /&gt;
* Enable browser XSS filtering feature.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:navy&amp;quot;&amp;gt;&lt;br /&gt;
The support for CSP directives is not the same level in major browsers (Firefox/Chrome/IE). It's recommanded to check the support &lt;br /&gt;
provided by target browsers  (using site provided in link section of this article) in order to configure CSP policies. The sample &lt;br /&gt;
below try to provide a set of policies from which your can add policies specific to your application context.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''This implementation provide an option to add CSP directives used by Firefox (Mozilla CSP directives).''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.security.MessageDigest;&lt;br /&gt;
import java.security.NoSuchAlgorithmException;&lt;br /&gt;
import java.security.SecureRandom;&lt;br /&gt;
import java.util.ArrayList;&lt;br /&gt;
import java.util.List;&lt;br /&gt;
&lt;br /&gt;
import javax.servlet.Filter;&lt;br /&gt;
import javax.servlet.FilterChain;&lt;br /&gt;
import javax.servlet.FilterConfig;&lt;br /&gt;
import javax.servlet.ServletException;&lt;br /&gt;
import javax.servlet.ServletRequest;&lt;br /&gt;
import javax.servlet.ServletResponse;&lt;br /&gt;
import javax.servlet.annotation.WebFilter;&lt;br /&gt;
import javax.servlet.http.HttpServletRequest;&lt;br /&gt;
import javax.servlet.http.HttpServletResponse;&lt;br /&gt;
&lt;br /&gt;
import org.apache.commons.codec.binary.Hex;&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * Sample filter implementation to define a set of Content Security Policies.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 * This implementation has a dependency on Commons Codec API.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 * This filter set CSP policies using all HTTP headers defined into W3C specification.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &amp;lt;br/&amp;gt;&lt;br /&gt;
 * This implementation is oriented to be easily understandable and easily adapted.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
@WebFilter(&amp;quot;/*&amp;quot;)&lt;br /&gt;
public class CSPPoliciesApplier implements Filter {&lt;br /&gt;
&lt;br /&gt;
	/** Configuration member to specify if web app use web fonts */&lt;br /&gt;
	public static final boolean APP_USE_WEBFONTS = false;&lt;br /&gt;
&lt;br /&gt;
	/** Configuration member to specify if web app use videos or audios */&lt;br /&gt;
	public static final boolean APP_USE_AUDIOS_OR_VIDEOS = false;&lt;br /&gt;
&lt;br /&gt;
	/** Configuration member to specify if filter must add CSP directive used by Mozilla (Firefox) */&lt;br /&gt;
	public static final boolean INCLUDE_MOZILLA_CSP_DIRECTIVES = true;&lt;br /&gt;
&lt;br /&gt;
	/** Filter configuration */&lt;br /&gt;
	@SuppressWarnings(&amp;quot;unused&amp;quot;)&lt;br /&gt;
	private FilterConfig filterConfig = null;&lt;br /&gt;
&lt;br /&gt;
	/** List CSP HTTP Headers */&lt;br /&gt;
	private List&amp;lt;String&amp;gt; cspHeaders = new ArrayList&amp;lt;String&amp;gt;();&lt;br /&gt;
&lt;br /&gt;
	/** Collection of CSP polcies that will be applied */&lt;br /&gt;
	private String policies = null;&lt;br /&gt;
&lt;br /&gt;
	/** Used for Script Nonce */&lt;br /&gt;
	private SecureRandom prng = null;&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Used to prepare (one time for all) set of CSP policies that will be applied on each HTTP response.&lt;br /&gt;
	 * &lt;br /&gt;
	 * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)&lt;br /&gt;
	 */&lt;br /&gt;
	@Override&lt;br /&gt;
	public void init(FilterConfig fConfig) throws ServletException {&lt;br /&gt;
		// Get filter configuration&lt;br /&gt;
		this.filterConfig = fConfig;&lt;br /&gt;
&lt;br /&gt;
		// Init secure random&lt;br /&gt;
		try {&lt;br /&gt;
			this.prng = SecureRandom.getInstance(&amp;quot;SHA1PRNG&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		catch (NoSuchAlgorithmException e) {&lt;br /&gt;
			throw new ServletException(e);&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		// Define list of CSP HTTP Headers&lt;br /&gt;
		this.cspHeaders.add(&amp;quot;Content-Security-Policy&amp;quot;);&lt;br /&gt;
		this.cspHeaders.add(&amp;quot;X-Content-Security-Policy&amp;quot;);&lt;br /&gt;
		this.cspHeaders.add(&amp;quot;X-WebKit-CSP&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
		// Define CSP policies&lt;br /&gt;
		// Loading policies for Frame and Sandboxing will be dynamically defined : We need to know if context use Frame&lt;br /&gt;
		List&amp;lt;String&amp;gt; cspPolicies = new ArrayList&amp;lt;String&amp;gt;();&lt;br /&gt;
		String originLocationRef = &amp;quot;'self'&amp;quot;;&lt;br /&gt;
		// --Disable default source in order to avoid browser fallback loading using 'default-src' locations&lt;br /&gt;
		cspPolicies.add(&amp;quot;default-src 'none'&amp;quot;);&lt;br /&gt;
		// --Define loading policies for Scripts&lt;br /&gt;
		cspPolicies.add(&amp;quot;script-src &amp;quot; + originLocationRef + &amp;quot; 'unsafe-inline' 'unsafe-eval'&amp;quot;);&lt;br /&gt;
		if (INCLUDE_MOZILLA_CSP_DIRECTIVES) {&lt;br /&gt;
			cspPolicies.add(&amp;quot;options inline-script eval-script&amp;quot;);&lt;br /&gt;
			cspPolicies.add(&amp;quot;xhr-src 'self'&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		// --Define loading policies for Plugins&lt;br /&gt;
		cspPolicies.add(&amp;quot;object-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Styles (CSS)&lt;br /&gt;
		cspPolicies.add(&amp;quot;style-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Images&lt;br /&gt;
		cspPolicies.add(&amp;quot;img-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Form&lt;br /&gt;
		cspPolicies.add(&amp;quot;form-action &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Audios/Videos&lt;br /&gt;
		if (APP_USE_AUDIOS_OR_VIDEOS) {&lt;br /&gt;
			cspPolicies.add(&amp;quot;media-src &amp;quot; + originLocationRef);&lt;br /&gt;
		}&lt;br /&gt;
		// --Define loading policies for Fonts&lt;br /&gt;
		if (APP_USE_WEBFONTS) {&lt;br /&gt;
			cspPolicies.add(&amp;quot;font-src &amp;quot; + originLocationRef);&lt;br /&gt;
		}&lt;br /&gt;
		// --Define loading policies for Connection&lt;br /&gt;
		cspPolicies.add(&amp;quot;connect-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Plugins Types&lt;br /&gt;
		cspPolicies.add(&amp;quot;plugin-types application/pdf application/x-shockwave-flash&amp;quot;);&lt;br /&gt;
		// --Define browser XSS filtering feature running mode&lt;br /&gt;
		cspPolicies.add(&amp;quot;reflected-xss block&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
		// Target formating&lt;br /&gt;
		this.policies = cspPolicies.toString().replaceAll(&amp;quot;(\\[|\\])&amp;quot;, &amp;quot;&amp;quot;).replaceAll(&amp;quot;,&amp;quot;, &amp;quot;;&amp;quot;).trim();&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Add CSP policies on each HTTP response.&lt;br /&gt;
	 * &lt;br /&gt;
	 * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)&lt;br /&gt;
	 */&lt;br /&gt;
	@Override&lt;br /&gt;
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain fchain) throws IOException, ServletException {&lt;br /&gt;
		HttpServletRequest httpRequest = ((HttpServletRequest) request);&lt;br /&gt;
		HttpServletResponse httpResponse = ((HttpServletResponse) response);&lt;br /&gt;
&lt;br /&gt;
		/* Step 1 : Detect if target resource is a Frame */&lt;br /&gt;
		// Customize here according to your context...&lt;br /&gt;
		boolean isFrame = true;&lt;br /&gt;
&lt;br /&gt;
		/* Step 2 : Add CSP policies to HTTP response */&lt;br /&gt;
		StringBuilder policiesBuffer = new StringBuilder(this.policies);&lt;br /&gt;
&lt;br /&gt;
		// If resource is a frame add Frame/Sandbox CSP policy&lt;br /&gt;
		if (isFrame) {&lt;br /&gt;
			// Frame + Sandbox : Here sandbox allow nothing, customize sandbox options depending on your app....&lt;br /&gt;
			policiesBuffer.append(&amp;quot;;&amp;quot;).append(&amp;quot;frame-src 'self';sandbox&amp;quot;);&lt;br /&gt;
			if (INCLUDE_MOZILLA_CSP_DIRECTIVES) {&lt;br /&gt;
				policiesBuffer.append(&amp;quot;;&amp;quot;).append(&amp;quot;frame-ancestors 'self'&amp;quot;);&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		// Add Script Nonce CSP Policy&lt;br /&gt;
		// --Generate a random number&lt;br /&gt;
		String randomNum = new Integer(this.prng.nextInt()).toString();&lt;br /&gt;
		// --Get its digest&lt;br /&gt;
		MessageDigest sha;&lt;br /&gt;
		try {&lt;br /&gt;
			sha = MessageDigest.getInstance(&amp;quot;SHA-1&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		catch (NoSuchAlgorithmException e) {&lt;br /&gt;
			throw new ServletException(e);&lt;br /&gt;
		}&lt;br /&gt;
		byte[] digest = sha.digest(randomNum.getBytes());&lt;br /&gt;
		// --Encode it into HEXA&lt;br /&gt;
		String scriptNonce = Hex.encodeHexString(digest);&lt;br /&gt;
		policiesBuffer.append(&amp;quot;;&amp;quot;).append(&amp;quot;script-nonce &amp;quot;).append(scriptNonce);&lt;br /&gt;
		// --Made available script nonce in view app layer&lt;br /&gt;
		httpRequest.setAttribute(&amp;quot;CSP_SCRIPT_NONCE&amp;quot;, scriptNonce);&lt;br /&gt;
&lt;br /&gt;
		// Add policies to all HTTP headers&lt;br /&gt;
		for (String header : this.cspHeaders) {&lt;br /&gt;
			httpResponse.setHeader(header, policiesBuffer.toString());&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		/* Step 3 : Let request continue chain filter */&lt;br /&gt;
		fchain.doFilter(request, response);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * {@inheritDoc}&lt;br /&gt;
	 * &lt;br /&gt;
	 * @see javax.servlet.Filter#destroy()&lt;br /&gt;
	 */&lt;br /&gt;
	@Override&lt;br /&gt;
	public void destroy() {&lt;br /&gt;
		// Not used&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:'''&lt;br /&gt;
[[Automated Audit using W3AF|W3AF]] audit tools (http://w3af.org) contains plugins to automatically audit web application to check if they correctly implement CSP policies. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:#088A08&amp;quot;&amp;gt;&lt;br /&gt;
It's very useful to include this type of tools into a web application development process in order to &lt;br /&gt;
perform a regular automatic first level check (do not replace an manual audit and manual audit must be also conducted regularly).&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Informations links ==&lt;br /&gt;
* W3C Specification (last specs release) : http://www.w3.org/TR/CSP&lt;br /&gt;
* Introduction to CSP: http://www.html5rocks.com/en/tutorials/security/content-security-policy&lt;br /&gt;
* CSP readiness browser testing: http://erlend.oftedal.no/blog/csp/readiness/&lt;br /&gt;
* CSP proposal by Mozilla Security ('''deprecated''', use W3C specs): https://wiki.mozilla.org/Security/CSP/Specification&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP Java Project]]&lt;br /&gt;
[[Category: Injection]]&lt;br /&gt;
[[Category:Attack]]&lt;br /&gt;
[[Category:Injection Attack]]&lt;/div&gt;</summary>
		<author><name>Dimisec</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Content_Security_Policy&amp;diff=150695</id>
		<title>Content Security Policy</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Content_Security_Policy&amp;diff=150695"/>
				<updated>2013-04-30T09:05:13Z</updated>
		
		<summary type="html">&lt;p&gt;Dimisec: updated the snippet on header names and Chrome, added caniuse.com reference&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Last revision (mm/dd/yy): '''02/03/2013'''&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
'''CSP''' stands for '''C'''ontent '''S'''ecurity '''P'''olicy. &lt;br /&gt;
&lt;br /&gt;
Is an W3C specification offering the possbility to instruct the client browser from which location and/or which type of resources are allowed to be loaded. To define a loading behavior, the CSP specification use &amp;quot;directive&amp;quot; where a directive define a loading behavior for a target resource type.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This article is based on version [https://dvcs.w3.org/hg/content-security-policy/raw-file/tip/csp-specification.dev.html 1.1] of the W3C specification.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Directives can be specified using HTTP response header (a server may send more than one CSP HTTP header field with a given resource representation and a server may send different CSP header field values with different representations of the same resource or with different resources) or HTML Meta tag, the HTTP headers below are defined by the specs:&lt;br /&gt;
* '''Content-Security-Policy''' : Defined by W3C Specs as standard header, used by Chrome starting with version 25&lt;br /&gt;
* '''X-Content-Security-Policy''' : Used by Firefox and Internet Explorer,&lt;br /&gt;
* '''X-WebKit-CSP''' : Used by Chrome (will transition to Content-Security-Policy)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The supported directives are:&lt;br /&gt;
* '''default-src''' : Define loading policy for all resources type in case of a resource type dedicated directive is not defined (fallback),&lt;br /&gt;
* '''script-src''' :  Define which scripts the protected resource can execute,&lt;br /&gt;
* '''object-src''' :  Define from where the protected resource can load plugins,&lt;br /&gt;
* '''style-src''' : Define which styles (CSS) the user applies to the protected resource,&lt;br /&gt;
* '''img-src''' : Define from where the protected resource can load images,&lt;br /&gt;
* '''media-src''' : Define from where the protected resource can load video and audio,&lt;br /&gt;
* '''frame-src''' : Define from where the protected resource can embed frames,&lt;br /&gt;
* '''font-src''' : Define from where the protected resource can load fonts,&lt;br /&gt;
* '''connect-src''' : Define which URIs the protected resource can load using script interfaces,&lt;br /&gt;
* '''form-action''' : Define which URIs can be used as the action of HTML form elements,&lt;br /&gt;
* '''sandbox''' : Specifies an HTML sandbox policy that the user agent applies to the protected resource,&lt;br /&gt;
* '''script-nonce''' : Define script execution by requiring the presence of the specified nonce on script elements,&lt;br /&gt;
* '''plugin-types''' : Define the set of plugins that can be invoked by the protected resource by limiting the types of resources that can be embedded,&lt;br /&gt;
* '''reflected-xss''' : Instructs a user agent to active or disactivate any heuristics used to filter or block reflected cross-site scripting attacks.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An introduction to CSP is available on [http://www.html5rocks.com/en/tutorials/security/content-security-policy/ HTML5Rocks].  The browser support is shown on http://caniuse.com/#feat=contentsecuritypolicy&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Risk ==&lt;br /&gt;
The risk with CSP can have 2 main sources:&lt;br /&gt;
# Policies misconfiguration,&lt;br /&gt;
# Too permissive policies.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Countermeasure ==&lt;br /&gt;
This article will focus on providing an sample implementation of a JEE Web Filter in order to apply a set of CSP policies on all HTTP response returned by server. &lt;br /&gt;
&lt;br /&gt;
The policies will instructs the browser to have the loading behavior below using all HTTP headers defined in W3C Specs:&lt;br /&gt;
* Explicit loading definition of each resource type,&lt;br /&gt;
* Resources are loaded only from source domain,&lt;br /&gt;
* Inline style is not allowed,&lt;br /&gt;
* For JavaScript:&lt;br /&gt;
** ''Inline script'' will be allowed because inline scripting it's commonly used (can be disabled if target site do not use this type of scripting),&lt;br /&gt;
** ''eval()'' function will be allowed in order to not break use of popular JavaScript libraries (ex: JQuery, JQueryUI, Sencha, ...) because they use eval() function (it was the case last time I have checked the source code from CDN ;) ),&lt;br /&gt;
* Generation of a random not guessable script nonce to use into all script tag,&lt;br /&gt;
* Plugin types only allow PDF and Flash,&lt;br /&gt;
* No font loading (configurable),&lt;br /&gt;
* No Audio / Video loading (configurable),&lt;br /&gt;
* Enable browser XSS filtering feature.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:navy&amp;quot;&amp;gt;&lt;br /&gt;
The support for CSP directives is not the same level in major browsers (Firefox/Chrome/IE). It's recommanded to check the support &lt;br /&gt;
provided by target browsers  (using site provided in link section of this article) in order to configure CSP policies. The sample &lt;br /&gt;
below try to provide a set of policies from which your can add policies specific to your application context.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''This implementation provide an option to add CSP directives used by Firefox (Mozilla CSP directives).''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.security.MessageDigest;&lt;br /&gt;
import java.security.NoSuchAlgorithmException;&lt;br /&gt;
import java.security.SecureRandom;&lt;br /&gt;
import java.util.ArrayList;&lt;br /&gt;
import java.util.List;&lt;br /&gt;
&lt;br /&gt;
import javax.servlet.Filter;&lt;br /&gt;
import javax.servlet.FilterChain;&lt;br /&gt;
import javax.servlet.FilterConfig;&lt;br /&gt;
import javax.servlet.ServletException;&lt;br /&gt;
import javax.servlet.ServletRequest;&lt;br /&gt;
import javax.servlet.ServletResponse;&lt;br /&gt;
import javax.servlet.annotation.WebFilter;&lt;br /&gt;
import javax.servlet.http.HttpServletRequest;&lt;br /&gt;
import javax.servlet.http.HttpServletResponse;&lt;br /&gt;
&lt;br /&gt;
import org.apache.commons.codec.binary.Hex;&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * Sample filter implementation to define a set of Content Security Policies.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 * This implementation has a dependency on Commons Codec API.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 * This filter set CSP policies using all HTTP headers defined into W3C specification.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &amp;lt;br/&amp;gt;&lt;br /&gt;
 * This implementation is oriented to be easily understandable and easily adapted.&amp;lt;br/&amp;gt;&lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
@WebFilter(&amp;quot;/*&amp;quot;)&lt;br /&gt;
public class CSPPoliciesApplier implements Filter {&lt;br /&gt;
&lt;br /&gt;
	/** Configuration member to specify if web app use web fonts */&lt;br /&gt;
	public static final boolean APP_USE_WEBFONTS = false;&lt;br /&gt;
&lt;br /&gt;
	/** Configuration member to specify if web app use videos or audios */&lt;br /&gt;
	public static final boolean APP_USE_AUDIOS_OR_VIDEOS = false;&lt;br /&gt;
&lt;br /&gt;
	/** Configuration member to specify if filter must add CSP directive used by Mozilla (Firefox) */&lt;br /&gt;
	public static final boolean INCLUDE_MOZILLA_CSP_DIRECTIVES = true;&lt;br /&gt;
&lt;br /&gt;
	/** Filter configuration */&lt;br /&gt;
	@SuppressWarnings(&amp;quot;unused&amp;quot;)&lt;br /&gt;
	private FilterConfig filterConfig = null;&lt;br /&gt;
&lt;br /&gt;
	/** List CSP HTTP Headers */&lt;br /&gt;
	private List&amp;lt;String&amp;gt; cspHeaders = new ArrayList&amp;lt;String&amp;gt;();&lt;br /&gt;
&lt;br /&gt;
	/** Collection of CSP polcies that will be applied */&lt;br /&gt;
	private String policies = null;&lt;br /&gt;
&lt;br /&gt;
	/** Used for Script Nonce */&lt;br /&gt;
	private SecureRandom prng = null;&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Used to prepare (one time for all) set of CSP policies that will be applied on each HTTP response.&lt;br /&gt;
	 * &lt;br /&gt;
	 * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)&lt;br /&gt;
	 */&lt;br /&gt;
	@Override&lt;br /&gt;
	public void init(FilterConfig fConfig) throws ServletException {&lt;br /&gt;
		// Get filter configuration&lt;br /&gt;
		this.filterConfig = fConfig;&lt;br /&gt;
&lt;br /&gt;
		// Init secure random&lt;br /&gt;
		try {&lt;br /&gt;
			this.prng = SecureRandom.getInstance(&amp;quot;SHA1PRNG&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		catch (NoSuchAlgorithmException e) {&lt;br /&gt;
			throw new ServletException(e);&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		// Define list of CSP HTTP Headers&lt;br /&gt;
		this.cspHeaders.add(&amp;quot;Content-Security-Policy&amp;quot;);&lt;br /&gt;
		this.cspHeaders.add(&amp;quot;X-Content-Security-Policy&amp;quot;);&lt;br /&gt;
		this.cspHeaders.add(&amp;quot;X-WebKit-CSP&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
		// Define CSP policies&lt;br /&gt;
		// Loading policies for Frame and Sandboxing will be dynamically defined : We need to know if context use Frame&lt;br /&gt;
		List&amp;lt;String&amp;gt; cspPolicies = new ArrayList&amp;lt;String&amp;gt;();&lt;br /&gt;
		String originLocationRef = &amp;quot;'self'&amp;quot;;&lt;br /&gt;
		// --Disable default source in order to avoid browser fallback loading using 'default-src' locations&lt;br /&gt;
		cspPolicies.add(&amp;quot;default-src 'none'&amp;quot;);&lt;br /&gt;
		// --Define loading policies for Scripts&lt;br /&gt;
		cspPolicies.add(&amp;quot;script-src &amp;quot; + originLocationRef + &amp;quot; 'unsafe-inline' 'unsafe-eval'&amp;quot;);&lt;br /&gt;
		if (INCLUDE_MOZILLA_CSP_DIRECTIVES) {&lt;br /&gt;
			cspPolicies.add(&amp;quot;options inline-script eval-script&amp;quot;);&lt;br /&gt;
			cspPolicies.add(&amp;quot;xhr-src 'self'&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		// --Define loading policies for Plugins&lt;br /&gt;
		cspPolicies.add(&amp;quot;object-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Styles (CSS)&lt;br /&gt;
		cspPolicies.add(&amp;quot;style-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Images&lt;br /&gt;
		cspPolicies.add(&amp;quot;img-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Form&lt;br /&gt;
		cspPolicies.add(&amp;quot;form-action &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Audios/Videos&lt;br /&gt;
		if (APP_USE_AUDIOS_OR_VIDEOS) {&lt;br /&gt;
			cspPolicies.add(&amp;quot;media-src &amp;quot; + originLocationRef);&lt;br /&gt;
		}&lt;br /&gt;
		// --Define loading policies for Fonts&lt;br /&gt;
		if (APP_USE_WEBFONTS) {&lt;br /&gt;
			cspPolicies.add(&amp;quot;font-src &amp;quot; + originLocationRef);&lt;br /&gt;
		}&lt;br /&gt;
		// --Define loading policies for Connection&lt;br /&gt;
		cspPolicies.add(&amp;quot;connect-src &amp;quot; + originLocationRef);&lt;br /&gt;
		// --Define loading policies for Plugins Types&lt;br /&gt;
		cspPolicies.add(&amp;quot;plugin-types application/pdf application/x-shockwave-flash&amp;quot;);&lt;br /&gt;
		// --Define browser XSS filtering feature running mode&lt;br /&gt;
		cspPolicies.add(&amp;quot;reflected-xss block&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
		// Target formating&lt;br /&gt;
		this.policies = cspPolicies.toString().replaceAll(&amp;quot;(\\[|\\])&amp;quot;, &amp;quot;&amp;quot;).replaceAll(&amp;quot;,&amp;quot;, &amp;quot;;&amp;quot;).trim();&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Add CSP policies on each HTTP response.&lt;br /&gt;
	 * &lt;br /&gt;
	 * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)&lt;br /&gt;
	 */&lt;br /&gt;
	@Override&lt;br /&gt;
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain fchain) throws IOException, ServletException {&lt;br /&gt;
		HttpServletRequest httpRequest = ((HttpServletRequest) request);&lt;br /&gt;
		HttpServletResponse httpResponse = ((HttpServletResponse) response);&lt;br /&gt;
&lt;br /&gt;
		/* Step 1 : Detect if target resource is a Frame */&lt;br /&gt;
		// Customize here according to your context...&lt;br /&gt;
		boolean isFrame = true;&lt;br /&gt;
&lt;br /&gt;
		/* Step 2 : Add CSP policies to HTTP response */&lt;br /&gt;
		StringBuilder policiesBuffer = new StringBuilder(this.policies);&lt;br /&gt;
&lt;br /&gt;
		// If resource is a frame add Frame/Sandbox CSP policy&lt;br /&gt;
		if (isFrame) {&lt;br /&gt;
			// Frame + Sandbox : Here sandbox allow nothing, customize sandbox options depending on your app....&lt;br /&gt;
			policiesBuffer.append(&amp;quot;;&amp;quot;).append(&amp;quot;frame-src 'self';sandbox&amp;quot;);&lt;br /&gt;
			if (INCLUDE_MOZILLA_CSP_DIRECTIVES) {&lt;br /&gt;
				policiesBuffer.append(&amp;quot;;&amp;quot;).append(&amp;quot;frame-ancestors 'self'&amp;quot;);&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		// Add Script Nonce CSP Policy&lt;br /&gt;
		// --Generate a random number&lt;br /&gt;
		String randomNum = new Integer(this.prng.nextInt()).toString();&lt;br /&gt;
		// --Get its digest&lt;br /&gt;
		MessageDigest sha;&lt;br /&gt;
		try {&lt;br /&gt;
			sha = MessageDigest.getInstance(&amp;quot;SHA-1&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		catch (NoSuchAlgorithmException e) {&lt;br /&gt;
			throw new ServletException(e);&lt;br /&gt;
		}&lt;br /&gt;
		byte[] digest = sha.digest(randomNum.getBytes());&lt;br /&gt;
		// --Encode it into HEXA&lt;br /&gt;
		String scriptNonce = Hex.encodeHexString(digest);&lt;br /&gt;
		policiesBuffer.append(&amp;quot;;&amp;quot;).append(&amp;quot;script-nonce &amp;quot;).append(scriptNonce);&lt;br /&gt;
		// --Made available script nonce in view app layer&lt;br /&gt;
		httpRequest.setAttribute(&amp;quot;CSP_SCRIPT_NONCE&amp;quot;, scriptNonce);&lt;br /&gt;
&lt;br /&gt;
		// Add policies to all HTTP headers&lt;br /&gt;
		for (String header : this.cspHeaders) {&lt;br /&gt;
			httpResponse.setHeader(header, policiesBuffer.toString());&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		/* Step 3 : Let request continue chain filter */&lt;br /&gt;
		fchain.doFilter(request, response);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * {@inheritDoc}&lt;br /&gt;
	 * &lt;br /&gt;
	 * @see javax.servlet.Filter#destroy()&lt;br /&gt;
	 */&lt;br /&gt;
	@Override&lt;br /&gt;
	public void destroy() {&lt;br /&gt;
		// Not used&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:'''&lt;br /&gt;
[[Automated Audit using W3AF|W3AF]] audit tools (http://w3af.org) contains plugins to automatically audit web application to check if they implements correctly CSP policies. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre style=&amp;quot;color:#088A08&amp;quot;&amp;gt;&lt;br /&gt;
It's very useful to include this type of tools into a web application development process in order to &lt;br /&gt;
perform a regular automatic first level check (do not replace an manual audit and manual audit must be also conducted regularly).&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Informations links ==&lt;br /&gt;
* W3C Specification (last specs release) : http://www.w3.org/TR/CSP&lt;br /&gt;
* Introduction to CSP: http://www.html5rocks.com/en/tutorials/security/content-security-policy&lt;br /&gt;
* CSP readiness browser testing: http://erlend.oftedal.no/blog/csp/readiness/&lt;br /&gt;
* CSP proposal by Mozilla Security ('''deprecated''', use W3C specs): https://wiki.mozilla.org/Security/CSP/Specification&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP Java Project]]&lt;br /&gt;
[[Category: Injection]]&lt;br /&gt;
[[Category:Attack]]&lt;br /&gt;
[[Category:Injection Attack]]&lt;/div&gt;</summary>
		<author><name>Dimisec</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet&amp;diff=147899</id>
		<title>XSS (Cross Site Scripting) Prevention Cheat Sheet</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet&amp;diff=147899"/>
				<updated>2013-03-15T09:33:08Z</updated>
		
		<summary type="html">&lt;p&gt;Dimisec: added an example on DOM XSS sample exploit&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
This article provides a simple positive model for preventing [[XSS]] using output escaping/encoding properly. While there are a huge number of XSS attack vectors, following a few simple rules can completely defend against this serious attack. This article does not explore the technical or business impact of XSS. Suffice it to say that it can lead to an attacker gaining the ability to do anything a victim can do through their browser.&lt;br /&gt;
&lt;br /&gt;
Both [[XSS#Stored_and_Reflected_XSS_Attacks | reflected and stored XSS]] can be addressed by performing the appropriate validation and escaping on the server-side. [[DOM Based XSS]] can be addressed with a special subset of rules described in the [[DOM based XSS Prevention Cheat Sheet]].&lt;br /&gt;
&lt;br /&gt;
For a cheatsheet on the attack vectors related to XSS, please refer to the [[XSS Filter Evasion Cheat Sheet]]. More background on browser security and the various browsers can be found in the [http://code.google.com/p/browsersec/ Browser Security Handbook].&lt;br /&gt;
&lt;br /&gt;
Before reading this cheatsheet, it is important to have a fundamental understanding of [[Injection Theory]].&lt;br /&gt;
&lt;br /&gt;
== A Positive XSS Prevention Model ==&lt;br /&gt;
&lt;br /&gt;
This article treats an HTML page like a template, with slots where a developer is allowed to put untrusted data. These slots cover the vast majority of the common places where a developer might want to put untrusted data. Putting untrusted data in other places in the HTML is not allowed. This is a &amp;quot;whitelist&amp;quot; model, that denies everything that is not specifically allowed.&lt;br /&gt;
&lt;br /&gt;
Given the way browsers parse HTML, each of the different types of slots has slightly different security rules. When you put untrusted data into these slots, you need to take certain steps to make sure that the data does not break out of that slot into a context that allows code execution. In a way, this approach treats an HTML document like a parameterized database query - the data is kept in specific places and is isolated from code contexts with escaping.&lt;br /&gt;
&lt;br /&gt;
This document sets out the most common types of slots and the rules for putting untrusted data into them safely. Based on the various specifications, known XSS vectors, and a great deal of manual testing with all the popular browsers, we have determined that the rule proposed here are safe.&lt;br /&gt;
&lt;br /&gt;
The slots are defined and a few examples of each are provided. Developers SHOULD NOT put data into any other slots without a very careful analysis to ensure that what they are doing is safe. Browser parsing is extremely tricky and many innocuous looking characters can be significant in the right context.&lt;br /&gt;
&lt;br /&gt;
== Why Can't I Just HTML Entity Encode Untrusted Data? ==&lt;br /&gt;
&lt;br /&gt;
HTML entity encoding is okay for untrusted data that you put in the body of the HTML document, such as inside a &amp;amp;lt;div&amp;gt; tag.  It even sort of works for untrusted data that goes into attributes, particularly if you're religious about using quotes around your attributes.  But HTML entity encoding doesn't work if you're putting untrusted data inside a &amp;amp;lt;script&amp;gt; tag anywhere, or an event handler attribute like onmouseover, or inside CSS, or in a URL.  So even if you use an HTML entity encoding method everywhere, you are still most likely vulnerable to XSS.  '''You MUST use the escape syntax for the part of the HTML document you're putting untrusted data into.'''  That's what the rules below are all about.&lt;br /&gt;
&lt;br /&gt;
== You Need a Security Encoding Library ==&lt;br /&gt;
&lt;br /&gt;
Writing these encoders is not tremendously difficult, but there are quite a few hidden pitfalls. For example, you might be tempted to use some of the escaping shortcuts like \&amp;quot; in JavaScript. However, these values are dangerous and may be misinterpreted by the nested parsers in the browser. You might also forget to escape the escape character, which attackers can use to neutralize your attempts to be safe. OWASP recommends using a security-focused encoding library to make sure these rules are properly implemented.&lt;br /&gt;
&lt;br /&gt;
Microsoft provides an encoding library named the [http://wpl.codeplex.com Microsoft Anti-Cross Site Scripting Library] for the .NET platform and ASP.NET Framework has built-in [http://msdn.microsoft.com/en-us/library/ms972969.aspx#securitybarriers_topic6 ValidateRequest] function that provides '''limited''' sanitization.&lt;br /&gt;
&lt;br /&gt;
The OWASP [[ESAPI]] project has created an escaping library for Java. OWASP also provides the [[OWASP Java Encoder Project]] for high-performance encoding.&lt;br /&gt;
&lt;br /&gt;
= XSS Prevention Rules = &lt;br /&gt;
&lt;br /&gt;
The following rules are intended to prevent all XSS in your application. While these rules do not allow absolute freedom in putting untrusted data into an HTML document, they should cover the vast majority of common use cases. You do not have to allow '''all''' the rules in your organization. Many organizations may find that '''allowing only Rule #1 and Rule #2 are sufficient for their needs'''. Please add a note to the discussion page if there is an additional context that is often required and can be secured with escaping.&lt;br /&gt;
&lt;br /&gt;
Do NOT simply escape the list of example characters provided in the various rules. It is NOT sufficient to escape only that list. Blacklist approaches are quite fragile.  The whitelist rules here have been carefully designed to provide protection even against future vulnerabilities introduced by browser changes.&lt;br /&gt;
&lt;br /&gt;
== RULE #0 - Never Insert Untrusted Data Except in Allowed Locations ==&lt;br /&gt;
&lt;br /&gt;
The first rule is to '''deny all''' - don't put untrusted data into your HTML document unless it is within one of the slots defined in Rule #1 through Rule #5. The reason for Rule #0 is that there are so many strange contexts within HTML that the list of escaping rules gets very complicated. We can't think of any good reason to put untrusted data in these contexts. This includes &amp;quot;nested contexts&amp;quot; like a URL inside a javascript -- the encoding rules for those locations are tricky and dangerous.  If you insist on putting untrusted data into nested contexts, please do a lot of cross-browser testing and let us know what you find out.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;script&amp;gt;'''...NEVER PUT UNTRUSTED DATA HERE...'''&amp;lt;/script&amp;gt;   directly in a script&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;!--'''...NEVER PUT UNTRUSTED DATA HERE...'''--&amp;gt;             inside an HTML comment&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div '''...NEVER PUT UNTRUSTED DATA HERE...'''=test /&amp;gt;       in an attribute name&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;'''NEVER PUT UNTRUSTED DATA HERE...''' href=&amp;quot;/test&amp;quot; /&amp;gt;   in a tag name&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;style&amp;gt;'''...NEVER PUT UNTRUSTED DATA HERE...'''&amp;lt;/style&amp;gt;   directly in CSS&lt;br /&gt;
&lt;br /&gt;
Most importantly, never accept actual JavaScript code from an untrusted source and then run it. For example, a parameter named &amp;quot;callback&amp;quot; that contains a JavaScript code snippet.  No amount of escaping can fix that.&lt;br /&gt;
&lt;br /&gt;
== RULE #1 - HTML Escape Before Inserting Untrusted Data into HTML Element Content ==&lt;br /&gt;
&lt;br /&gt;
Rule #1 is for when you want to put untrusted data directly into the HTML body somewhere. This includes inside normal tags like div, p, b, td, etc. Most web frameworks have a method for HTML escaping for the characters detailed below. However, this is '''absolutely not sufficient for other HTML contexts.'''  You need to implement the other rules detailed here as well.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;body&amp;gt;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;lt;/body&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div&amp;gt;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;lt;/div&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
  any other normal HTML elements&lt;br /&gt;
&lt;br /&gt;
Escape the following characters with HTML entity encoding to prevent switching into any execution context, such as script, style, or event handlers. Using hex entities is recommended in the spec. In addition to the 5 characters significant in XML (&amp;amp;, &amp;lt;, &amp;gt;, &amp;quot;, '), the forward slash is included as it helps to end an HTML entity.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp; --&amp;gt; &amp;amp;amp;amp;&lt;br /&gt;
  &amp;lt; --&amp;gt; &amp;amp;amp;lt;&lt;br /&gt;
  &amp;gt; --&amp;gt; &amp;amp;amp;gt;&lt;br /&gt;
  &amp;quot; --&amp;gt; &amp;amp;amp;quot;&lt;br /&gt;
  ' --&amp;gt; &amp;amp;amp;#x27;     &amp;amp;amp;apos; not recommended because its not in the HTML spec (See: [http://www.w3.org/TR/html4/sgml/entities.html section 24.4.1]) &amp;amp;amp;apos; is in the XML and XHTML specs.&lt;br /&gt;
  / --&amp;gt; &amp;amp;amp;#x2F;     forward slash is included as it helps end an HTML entity&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/HTMLEntityCodec.java ESAPI reference implementation] of HTML entity escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForHTML( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
== RULE #2 - Attribute Escape Before Inserting Untrusted Data into HTML Common Attributes ==&lt;br /&gt;
&lt;br /&gt;
Rule #2 is for putting untrusted data into typical attribute values like width, name, value, etc. This should not be used for complex attributes like href, src, style, or any of the event handlers like onmouseover.  It is extremely important that event handler attributes should follow Rule #3 for HTML JavaScript Data Values.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;div attr='''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;gt;content&amp;lt;/div&amp;gt;     inside UNquoted attribute&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div attr=''''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...''''&amp;gt;content&amp;lt;/div&amp;gt;   inside single quoted attribute&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div attr=&amp;quot;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;quot;&amp;gt;content&amp;lt;/div&amp;gt;   inside double quoted attribute&lt;br /&gt;
&lt;br /&gt;
Except for alphanumeric characters, escape all characters with ASCII values less than 256 with the &amp;amp;amp;#xHH; format (or a named entity if available) to prevent switching out of the attribute. The reason this rule is so broad is that developers frequently leave attributes unquoted.  Properly quoted attributes can only be escaped with the corresponding quote. Unquoted attributes can be broken out of with many characters, including [space] % * + , - / ; &amp;lt; = &amp;gt; ^ and |.&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/HTMLEntityCodec.java ESAPI reference implementation] of HTML entity escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForHTMLAttribute( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
== RULE #3 - JavaScript Escape Before Inserting Untrusted Data into JavaScript Data Values ==&lt;br /&gt;
&lt;br /&gt;
Rule #3 concerns dynamically generated JavaScript code - both script blocks and event-handler attributes. The only safe place to put untrusted data into this code is inside a quoted &amp;quot;data value.&amp;quot;  Including untrusted data inside any other JavaScript context is quite dangerous, as it is extremely easy to switch into an execution context with characters including (but not limited to) semi-colon, equals, space, plus, and many more, so use with caution.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;script&amp;gt;alert(''''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''')&amp;amp;lt;/script&amp;gt;     inside a quoted string&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;script&amp;gt;x=''''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...''''&amp;amp;lt;/script&amp;gt;          one side of a quoted expression&lt;br /&gt;
  &lt;br /&gt;
  &amp;amp;lt;div onmouseover=&amp;quot;x=''''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...''''&amp;quot;&amp;amp;lt;/div&amp;gt;  inside quoted event handler&lt;br /&gt;
&lt;br /&gt;
Please note there are some JavaScript functions that can never safely use untrusted data as input - &amp;lt;b&amp;gt;EVEN IF JAVASCRIPT ESCAPED&amp;lt;/b&amp;gt;! &lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
  &amp;amp;lt;script&amp;gt;&lt;br /&gt;
  window.setInterval(''''...EVEN IF YOU ESCAPE UNTRUSTED DATA YOU ARE XSSED HERE...'''');&lt;br /&gt;
  &amp;amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Except for alphanumeric characters, escape all characters less than 256 with the \xHH format to prevent switching out of the data value into the script context or into another attribute. DO NOT use any escaping shortcuts like \&amp;quot; because the quote character may be matched by the HTML attribute parser which runs first. These escaping shortcuts are also susceptible to &amp;quot;escape-the-escape&amp;quot; attacks where the attacker sends \&amp;quot; and the vulnerable code turns that into \\&amp;quot; which enables the quote.&lt;br /&gt;
&lt;br /&gt;
If an event handler is properly quoted, breaking out requires the corresponding quote. However, we have intentionally made this rule quite broad because event handler attributes are often left unquoted.  Unquoted attributes can be broken out of with many characters including [space] % * + , - / ; &amp;lt; = &amp;gt; ^ and |. Also, a &amp;lt;/script&amp;gt; closing tag will close a script block even though it is inside a quoted string because the HTML parser runs before the JavaScript parser.&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/JavaScriptCodec.java ESAPI reference implementation] of JavaScript escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForJavaScript( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
=== RULE #3.1 - HTML escape JSON values in an HTML context and read the data with JSON.parse ===&lt;br /&gt;
&lt;br /&gt;
In a Web 2.0 world, the need for having data dynamically generated by an application in a javascript context is common.  One strategy is to make an AJAX call to get the values, but this isn't always performant.  Often, an initial block of JSON is loaded into the page to act as a single place to store multiple values.  This data is tricky, though not impossible, to escape correctly without breaking the format and content of the values.&lt;br /&gt;
&lt;br /&gt;
'''Ensure returned ''Content-Type'' header is application/json and not text/html. &lt;br /&gt;
This shall instruct the browser not misunderstand the contect and execute injected script'''&lt;br /&gt;
&lt;br /&gt;
'''Bad HTTP response:'''&lt;br /&gt;
&lt;br /&gt;
    HTTP/1.1 200&lt;br /&gt;
    Date: Wed, 06 Feb 2013 10:28:54 GMT&lt;br /&gt;
    Server: Microsoft-IIS/7.5....&lt;br /&gt;
    '''Content-Type: text/html; charset=utf-8''' &amp;lt;-- bad&lt;br /&gt;
    ....&lt;br /&gt;
    Content-Length: 373&lt;br /&gt;
    Keep-Alive: timeout=5, max=100&lt;br /&gt;
    Connection: Keep-Alive&lt;br /&gt;
    {&amp;quot;Message&amp;quot;:&amp;quot;No HTTP resource was found that matches the request URI 'dev.net.ie/api/pay/.html?HouseNumber=9&amp;amp;AddressLine&lt;br /&gt;
    =The+Gardens'''&amp;amp;lt;script&amp;gt;alert(1)&amp;lt;/script&amp;gt;'''&amp;amp;AddressLine2=foxlodge+woods&amp;amp;TownName=Meath'.&amp;quot;,&amp;quot;MessageDetail&amp;quot;:&amp;quot;No type was found&lt;br /&gt;
    that matches the controller named 'pay'.&amp;quot;}   &amp;lt;-- this script will pop!!&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
'''Good HTTP response'''&lt;br /&gt;
&lt;br /&gt;
    HTTP/1.1 200&lt;br /&gt;
    Date: Wed, 06 Feb 2013 10:28:54 GMT&lt;br /&gt;
    Server: Microsoft-IIS/7.5....&lt;br /&gt;
    '''Content-Type: application/json; charset=utf-8''' &amp;lt;--good&lt;br /&gt;
    .....&lt;br /&gt;
    .....&lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A common '''anti-pattern''' one would see:&lt;br /&gt;
&lt;br /&gt;
    &amp;amp;lt;script&amp;gt;&lt;br /&gt;
      var initData = &amp;lt;%= data.to_json %&amp;gt;; // '''Do NOT do this.'''&lt;br /&gt;
    &amp;amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Instead, consider placing the JSON block on the page as a normal element and then parsing the innerHTML to get the contents.  The javascript that reads the span can live in an external file, thus making the implementation of CSP enforcement easier.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;script id=&amp;quot;init_data&amp;quot; type=&amp;quot;application/json&amp;quot;&amp;gt;&lt;br /&gt;
     &amp;amp;lt;%= data.to_json %&amp;gt;  &amp;amp;lt;-- data is HTML escaped, or at least json entity escaped --&amp;gt;&lt;br /&gt;
  &amp;amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;script&amp;gt;&lt;br /&gt;
    var jsonText = document.getElementById('init_data').innerHTML;  // unescapes the content of the span&lt;br /&gt;
    var initData = JSON.parse(jsonText); &lt;br /&gt;
  &amp;amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The data is added to the page and is HTML entity escaped so it won't pop in the HTML context.  The data is then read by innerHTML, which unescapes the value.  The unescaped text from the page is then parsed with JSON.parse.&lt;br /&gt;
&lt;br /&gt;
== RULE #4 - CSS Escape And Strictly Validate Before Inserting Untrusted Data into HTML Style Property Values ==&lt;br /&gt;
&lt;br /&gt;
Rule #4 is for when you want to put untrusted data into a stylesheet or a style tag. CSS is surprisingly powerful, and can be used for numerous attacks. Therefore, it's important that you only use untrusted data in a property '''value''' and not into other places in style data. You should stay away from putting untrusted data into complex properties like url, behavior, and custom (-moz-binding). You should also not put untrusted data into IE’s expression property value which allows JavaScript.&lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;style&amp;gt;selector { property : '''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''; } &amp;amp;lt;/style&amp;gt;     property value&amp;lt;br/&amp;gt;&lt;br /&gt;
  &amp;amp;lt;style&amp;gt;selector { property : &amp;amp;quot;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;amp;quot;; } &amp;amp;lt;/style&amp;gt;   property value&amp;lt;br/&amp;gt;&lt;br /&gt;
  &amp;amp;lt;span style=&amp;amp;quot;property : '''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...'''&amp;amp;quot;&amp;gt;text&amp;amp;lt;/style&amp;gt;       property value&lt;br /&gt;
&lt;br /&gt;
Please note there are some CSS contexts that can never safely use untrusted data as input - &amp;lt;b&amp;gt;EVEN IF PROPERLY CSS ESCAPED&amp;lt;/b&amp;gt;! You will have to ensure that URLs only start with &amp;quot;http&amp;quot; not &amp;quot;javascript&amp;quot; and that properties never start with &amp;quot;expression&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
  { background-url : &amp;quot;javascript:alert(1)&amp;quot;; }  // and all other URLs&lt;br /&gt;
  { text-size: &amp;quot;expression(alert('XSS'))&amp;quot;; }   // only in IE&lt;br /&gt;
&lt;br /&gt;
Except for alphanumeric characters, escape all characters with ASCII values less than 256 with the \HH escaping format. DO NOT use any escaping shortcuts like \&amp;quot; because the quote character may be matched by the HTML attribute parser which runs first. These escaping shortcuts are also susceptible to &amp;quot;escape-the-escape&amp;quot; attacks where the attacker sends \&amp;quot; and the vulnerable code turns that into \\&amp;quot; which enables the quote.&lt;br /&gt;
&lt;br /&gt;
If attribute is quoted, breaking out requires the corresponding quote.  All attributes should be quoted but your encoding should be strong enough to prevent XSS when untrusted data is placed in unquoted contexts. Unquoted attributes can be broken out of with many characters including [space] % * + , - / ; &amp;lt; = &amp;gt; ^ and |.  Also, the &amp;lt;/style&amp;gt; tag will close the style block even though it is inside a quoted string because the HTML parser runs before the JavaScript parser. Please note that we recommend aggressive CSS encoding and validation to prevent XSS attacks for both quoted and unquoted attributes.&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/CSSCodec.java ESAPI reference implementation] of CSS escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForCSS( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
== RULE #5 - URL Escape Before Inserting Untrusted Data into HTML URL Parameter Values ==&lt;br /&gt;
&lt;br /&gt;
Rule #5 is for when you want to put untrusted data into HTTP GET parameter value. &lt;br /&gt;
&lt;br /&gt;
  &amp;amp;lt;a href=&amp;quot;http&amp;amp;#x3a;&amp;amp;#x2f;&amp;amp;#x2f;www.somesite.com&amp;amp;#x3f;test&amp;amp;#x3d;'''...ESCAPE UNTRUSTED DATA BEFORE PUTTING HERE...&amp;quot;'''&amp;gt;link&amp;amp;lt;/a &amp;gt;       &lt;br /&gt;
&lt;br /&gt;
Except for alphanumeric characters, escape all characters with ASCII values less than 256 with the %HH escaping format.  Including untrusted data in data: URLs should not be allowed as there is no good way to disable attacks with escaping to prevent switching out of the URL. All attributes should be quoted. Unquoted attributes can be broken out of with many characters including [space] % * + , - / ; &amp;lt; = &amp;gt; ^ and |. Note that entity encoding is useless in this context.&lt;br /&gt;
&lt;br /&gt;
See the [http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/PercentCodec.java ESAPI reference implementation] of URL escaping and unescaping.&lt;br /&gt;
&lt;br /&gt;
  String safe = ESAPI.encoder().encodeForURL( request.getParameter( &amp;quot;input&amp;quot; ) );&lt;br /&gt;
&lt;br /&gt;
WARNING: Do not encode complete or relative URL's with URL encoding! If untrusted input is meant to be placed into href, src or other URL-based attributes, it should be validated to make sure it does not point to an unexpected protocol, especially Javascript links. URL's should then be encoded based on the context of display like any other piece of data. For example, user driven URL's in HREF links should be attribute encoded. For example:&lt;br /&gt;
&lt;br /&gt;
  String userURL = request.getParameter( &amp;quot;userURL&amp;quot; )&lt;br /&gt;
  boolean isValidURL = ESAPI.validator().isValidInput(&amp;quot;URLContext&amp;quot;, userURL, &amp;quot;URL&amp;quot;, 255, false); &lt;br /&gt;
  if (isValidURL) {  &lt;br /&gt;
      &amp;lt;a href=&amp;quot;&amp;lt;%=encoder.encodeForHTMLAttribute(userURL)%&amp;gt;&amp;quot;&amp;gt;link&amp;lt;/a&amp;gt;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
== RULE #6 - Use an HTML Policy engine to validate or clean user-driven HTML in an outbound way ==&lt;br /&gt;
&lt;br /&gt;
'''OWASP AntiSamy'''&lt;br /&gt;
&lt;br /&gt;
   import org.owasp.validator.html.*;&lt;br /&gt;
   Policy policy = Policy.getInstance(POLICY_FILE_LOCATION);&lt;br /&gt;
   AntiSamy as = new AntiSamy();&lt;br /&gt;
   CleanResults cr = as.scan(dirtyInput, policy);&lt;br /&gt;
   MyUserDAO.storeUserProfile(cr.getCleanHTML()); // some custom function&lt;br /&gt;
&lt;br /&gt;
'''OWASP Java HTML Sanitizer'''&lt;br /&gt;
&lt;br /&gt;
   import org.owasp.html.Sanitizers;&lt;br /&gt;
   import org.owasp.html.PolicyFactory;&lt;br /&gt;
   PolicyFactory sanitizer = Sanitizers.FORMATTING.and(Sanitizers.BLOCKS);&lt;br /&gt;
   String cleanResults = sanitizer.sanitize(&amp;quot;&amp;amp;lt;p&amp;amp;gt;Hello, &amp;amp;lt;b&amp;amp;gt;World!&amp;amp;lt;/b&amp;amp;gt;&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
For more information on OWASP Java HTML Sanitizer policy construction, see [http://owasp-java-html-sanitizer.googlecode.com/svn/trunk/distrib/javadoc/org/owasp/html/Sanitizers.html http://owasp-java-html-sanitizer.googlecode.com/svn/trunk/distrib/javadoc/org/owasp/html/Sanitizers.html]&lt;br /&gt;
&lt;br /&gt;
== RULE #7 - Prevent DOM-based XSS  ==&lt;br /&gt;
&lt;br /&gt;
For details on what DOM-based XSS is, and defenses against this type of XSS flaw, please see the OWASP article on [[DOM based XSS Prevention Cheat Sheet]].&lt;br /&gt;
&lt;br /&gt;
== Bonus Rule: Use HTTPOnly cookie flag ==&lt;br /&gt;
&lt;br /&gt;
Preventing all XSS flaws in an application is hard, as you can see. To help mitigate the impact of an XSS flaw on your site, OWASP also recommends you set the HTTPOnly flag on your session cookie and any custom cookies you have that are not accessed by any Javascript you wrote. This cookie flag is typically on by default in .NET apps, but in other languages you have to set it manually.  For more details on the HTTPOnly cookie flag, including what it does, and how to use it, see the OWASP article on [[HTTPOnly]].&lt;br /&gt;
&lt;br /&gt;
= XSS Prevention Rules Summary =&lt;br /&gt;
&lt;br /&gt;
The following snippets of HTML demonstrate how to safely render untrusted data in a variety of different contexts. &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable nowraplinks&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Data Type&lt;br /&gt;
! Context&lt;br /&gt;
! Code Sample&lt;br /&gt;
! Defense&lt;br /&gt;
|-&lt;br /&gt;
| String&lt;br /&gt;
| HTML Body&lt;br /&gt;
| &amp;amp;lt;span&amp;gt;&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED DATA&amp;lt;/span&amp;gt;&amp;amp;lt;/span&amp;gt;&lt;br /&gt;
| &amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;[https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet#RULE_.231_-_HTML_Escape_Before_Inserting_Untrusted_Data_into_HTML_Element_Content HTML Entity Encoding]&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| String&lt;br /&gt;
| Safe HTML Attributes&lt;br /&gt;
| &amp;amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;fname&amp;quot; value=&amp;quot;&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED DATA&amp;lt;/span&amp;gt;&amp;quot;&amp;gt;&lt;br /&gt;
| &amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;[https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet#RULE_.232_-_Attribute_Escape_Before_Inserting_Untrusted_Data_into_HTML_Common_Attributes Aggressive HTML Entity Encoding]&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;Only place untrusted data into a whitelist of safe attributes (listed below).&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;Strictly validate unsafe attributes such as background, id and name.&amp;lt;/ul&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| String&lt;br /&gt;
| GET Parameter&lt;br /&gt;
| &amp;amp;lt;a href=&amp;quot;/site/search?value=&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED DATA&amp;lt;/span&amp;gt;&amp;quot;&amp;gt;clickme&amp;amp;lt;/a&amp;gt;&lt;br /&gt;
| &amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;[https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet#RULE_.235_-_URL_Escape_Before_Inserting_Untrusted_Data_into_HTML_URL_Parameter_Values URL Encoding]&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| String&lt;br /&gt;
| Untrusted URL in a SRC or HREF attribute&lt;br /&gt;
| &amp;amp;lt;a href=&amp;quot;&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED URL&amp;lt;/span&amp;gt;&amp;quot;&amp;gt;clickme&amp;amp;lt;/a&amp;gt;&amp;lt;br/&amp;gt;&amp;amp;lt;iframe src=&amp;quot;&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED URL&amp;lt;/span&amp;gt;&amp;quot; /&amp;gt;&lt;br /&gt;
| &amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;Cannonicalize input&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;URL Validation&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;Safe URL verification&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;Whitelist http and https URL's only ([[Avoid the JavaScript Protocol to Open a new Window]])&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;Attribute encoder&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| String&lt;br /&gt;
| CSS Value&lt;br /&gt;
| &amp;amp;lt;div style=&amp;quot;width: &amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED DATA&amp;lt;/span&amp;gt;;&amp;quot;&amp;gt;Selection&amp;amp;lt;/div&amp;gt;&lt;br /&gt;
| &amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;[https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet#RULE_.234_-_CSS_Escape_And_Strictly_Validate_Before_Inserting_Untrusted_Data_into_HTML_Style_Property_Values Strict structural validation]&amp;lt;li&amp;gt;CSS Hex encoding&amp;lt;li&amp;gt;Good design of CSS Features&amp;lt;/ul&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| String&lt;br /&gt;
| JavaScript Variable&lt;br /&gt;
| &amp;amp;lt;script&amp;gt;var currentValue='&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED DATA&amp;lt;/span&amp;gt;';&amp;amp;lt;/script&amp;gt;&amp;lt;br/&amp;gt;&amp;amp;lt;script&amp;gt;someFunction('&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED DATA&amp;lt;/span&amp;gt;');&amp;amp;lt;/script&amp;gt;&lt;br /&gt;
| &amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;Ensure JavaScript variables are quoted&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;JavaScript Hex Encoding&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;JavaScript Unicode Encoding&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;Avoid backslash encoding (\&amp;quot; or \' or \\)&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| HTML&lt;br /&gt;
| HTML Body&lt;br /&gt;
| &amp;amp;lt;div&amp;gt;&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;UNTRUSTED HTML&amp;lt;/span&amp;gt;&amp;amp;lt;/div&amp;gt;&lt;br /&gt;
| &amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;[https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet#RULE_.236_-_Use_an_HTML_Policy_engine_to_validate_or_clean_user-driven_HTML_in_an_outbound_way HTML Validation (JSoup, AntiSamy, HTML Sanitizer)]&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt; &lt;br /&gt;
|-&lt;br /&gt;
| String&lt;br /&gt;
| DOM XSS&lt;br /&gt;
| &amp;amp;lt;script&amp;gt;document.write(&amp;lt;span style=&amp;quot;color:red;&amp;quot;&amp;gt;&amp;quot;UNTRUSTED INPUT: &amp;quot; + document.location.hash&amp;lt;/span&amp;gt;);&amp;amp;lt;script/&amp;amp;gt;&lt;br /&gt;
| &amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;[[DOM based XSS Prevention Cheat Sheet]]&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
'''''Safe HTML Attributes include:''''' align, alink, alt, bgcolor, border, cellpadding, cellspacing, class, color, cols, colspan, coords, dir, face, height, hspace, ismap, lang, marginheight, marginwidth, multiple, nohref, noresize, noshade, nowrap, ref, rel, rev, rows, rowspan, scrolling, shape, span, summary, tabindex, title, usemap, valign, value, vlink, vspace, width&lt;br /&gt;
&lt;br /&gt;
= Output Encoding Rules Summary =&lt;br /&gt;
&lt;br /&gt;
The purpose of output encoding (as it relates to Cross Site Scripting) is to convert untrusted input into a safe form where the input is displayed as '''data''' to the user without executing as '''code''' in the browser. The following charts details a list of critical output encoding methods needed to stop Cross Site Scripting.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Encoding Type&lt;br /&gt;
! Encoding Mechanism&lt;br /&gt;
|-&lt;br /&gt;
| HTML Entity Encoding&lt;br /&gt;
|   Convert &amp;amp; to &amp;amp;amp;amp;&amp;lt;br/&amp;gt;Convert &amp;lt; to &amp;amp;amp;lt;&amp;lt;br/&amp;gt;Convert &amp;gt; to &amp;amp;amp;gt;&amp;lt;br/&amp;gt;Convert &amp;quot; to &amp;amp;amp;quot;&amp;lt;br/&amp;gt;Convert ' to &amp;amp;amp;#x27;&amp;lt;br/&amp;gt;Convert / to &amp;amp;amp;#x2F;&lt;br /&gt;
|-&lt;br /&gt;
| HTML Attribute Encoding&lt;br /&gt;
| Except for alphanumeric characters, escape all characters with the HTML Entity &amp;amp;amp;#xHH; format, including spaces. (HH = Hex Value)&lt;br /&gt;
|-&lt;br /&gt;
| URL Encoding&lt;br /&gt;
| Standard percent encoding, see: [http://www.w3schools.com/tags/ref_urlencode.asp http://www.w3schools.com/tags/ref_urlencode.asp]&lt;br /&gt;
|-&lt;br /&gt;
| JavaScript Encoding&lt;br /&gt;
| Except for alphanumeric characters, escape all characters with the \uXXXX unicode escaping format (X = Integer).&lt;br /&gt;
|-&lt;br /&gt;
| CSS Hex Encoding&lt;br /&gt;
| CSS escaping supports \XX and \XXXXXX. Using a two character escape can cause problems if the next character continues the escape sequence. There are two solutions (a) Add a space after the CSS escape (will be ignored by the CSS parser) (b) use the full amount of CSS escaping possible by zero padding the value.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Related Articles =&lt;br /&gt;
&lt;br /&gt;
'''XSS Attack Cheat Sheet'''&lt;br /&gt;
&lt;br /&gt;
The following article describes how to exploit different kinds of XSS Vulnerabilities that this article was created to help you avoid:&lt;br /&gt;
&lt;br /&gt;
* RSnake: &amp;quot;XSS Cheat Sheet&amp;quot; - http://ha.ckers.org/xss.html&lt;br /&gt;
&lt;br /&gt;
'''A Systematic Analysis of XSS Sanitization in Web Application Frameworks'''&lt;br /&gt;
&lt;br /&gt;
[http://www.cs.berkeley.edu/~prateeks/papers/empirical-webfwks.pdf http://www.cs.berkeley.edu/~prateeks/papers/empirical-webfwks.pdf]&lt;br /&gt;
&lt;br /&gt;
'''Description of XSS Vulnerabilities'''&lt;br /&gt;
&lt;br /&gt;
* OWASP article on [[XSS]] Vulnerabilities&lt;br /&gt;
&lt;br /&gt;
'''How to Review Code for Cross-site scripting Vulnerabilities'''&lt;br /&gt;
&lt;br /&gt;
* [[:Category:OWASP Code Review Project|OWASP Code Review Guide]] article on [[Reviewing Code for Cross-site scripting]] Vulnerabilities&lt;br /&gt;
&lt;br /&gt;
'''How to Test for Cross-site scripting  Vulnerabilities'''&lt;br /&gt;
&lt;br /&gt;
* [[:Category:OWASP Testing Project|OWASP Testing Guide]] article on [[Testing for Cross site scripting]] Vulnerabilities&lt;br /&gt;
&lt;br /&gt;
* [[XSS Experimental Minimal Encoding Rules]]&lt;br /&gt;
&lt;br /&gt;
= Authors and Primary Editors =&lt;br /&gt;
&lt;br /&gt;
Jeff Williams - jeff.williams[at]aspectsecurity.com&amp;lt;br/&amp;gt;&lt;br /&gt;
Jim Manico - jim[at]owasp.org&amp;lt;br/&amp;gt;&lt;br /&gt;
Eoin Keary - eoin.keary[at]owasp.org&lt;br /&gt;
&lt;br /&gt;
= Other Cheatsheets =&lt;br /&gt;
{{Cheatsheet_Navigation}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Cheatsheets]]&lt;/div&gt;</summary>
		<author><name>Dimisec</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=DOM_Based_XSS&amp;diff=144210</id>
		<title>DOM Based XSS</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=DOM_Based_XSS&amp;diff=144210"/>
				<updated>2013-02-13T13:20:15Z</updated>
		
		<summary type="html">&lt;p&gt;Dimisec: updated DOMinator references&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{template: Attack}}&lt;br /&gt;
== DOM Based XSS ==&lt;br /&gt;
&lt;br /&gt;
=== Definition ===&lt;br /&gt;
&lt;br /&gt;
DOM Based [[XSS | XSS]] (or as it is called in some texts, “type-0 XSS”) is an XSS attack wherein the attack payload is executed as a result of modifying the DOM “environment” in the victim’s browser used by the original client side script, so that the client side code runs in an “unexpected” manner. That is, the page itself (the HTTP response that is) does not change, but the client side code contained in the page executes differently due to the malicious modifications that have occurred in the DOM environment.&lt;br /&gt;
&lt;br /&gt;
This is in contrast to other XSS attacks ([[XSS#Stored_and_Reflected_XSS_Attacks |stored or reflected]]), wherein the attack payload is placed in the response page (due to a server side flaw).&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
&lt;br /&gt;
Suppose the following code is used to create a form to let the user choose his/her preferred language. A default language is also provided in the query string, as the parameter “default”.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
…&lt;br /&gt;
&lt;br /&gt;
Select your language:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;select&amp;gt;&amp;lt;script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
document.write(&amp;quot;&amp;lt;OPTION value=1&amp;gt;&amp;quot;+document.location.href.substring(document.location.href.indexOf(&amp;quot;default=&amp;quot;)+8)+&amp;quot;&amp;lt;/OPTION&amp;gt;&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
document.write(&amp;quot;&amp;lt;OPTION value=2&amp;gt;English&amp;lt;/OPTION&amp;gt;&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/script&amp;gt;&amp;lt;/select&amp;gt;&lt;br /&gt;
…&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The page is invoked with a URL such as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
http://www.some.site/page.html?default=French&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A DOM Based XSS attack against this page can be accomplished by sending the following URL to a victim:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
http://www.some.site/page.html?default=&amp;lt;script&amp;gt;alert(document.cookie)&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When the victim clicks on this link, the browser sends a request for: &amp;lt;pre&amp;gt;/page.html?default=&amp;lt;script&amp;gt;alert(document.cookie)&amp;lt;/script&amp;gt;&amp;lt;/pre&amp;gt; to www.some.site. The server responds with the page containing the above Javascript code. The browser creates a DOM object for the page, in which the document.location object contains the string: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
http://www.some.site/page.html?default=&amp;lt;script&amp;gt;alert(document.cookie)&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
The original Javascript code in the page does not expect the default parameter to contain HTML markup, and as such it simply echoes it into the page (DOM) at runtime. The browser then renders the resulting page and executes the attacker’s script: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alert(document.cookie)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that the HTTP response sent from the server does not contain the attacker’s payload. This payload manifests itself at the client-side script at runtime, when a flawed script accesses the DOM variable document.location and assumes it is not malicious.&lt;br /&gt;
&lt;br /&gt;
=== Advanced Techniques and Derivatives ===&lt;br /&gt;
&lt;br /&gt;
In the example above, while the payload was not embedded by the server in the HTTP response, it still arrived at the server as part of an HTTP request, and thus the attack could be detected at the server side.  The [http://www.webappsec.org/projects/articles/071105.shtml “DOM Based XSS” paper] ([1]) details a technique to avoid server side detection. It also describes several other possible locations for the payload, besides document.location.&lt;br /&gt;
&lt;br /&gt;
The technique to avoid sending the payload to the server hinges on the fact that URI fragments (the part in the URI after the “#”) is not sent to the server by the browser. Thus, any client side code that references, say, document.location, may be vulnerable to an attack which uses fragments, and in such case the payload is never sent to the server. For example, the above DOM based XSS can be modified into:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
http://www.some.site/page.html#default=&amp;lt;script&amp;gt;alert(document.cookie)&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
which mounts the same attack without it being seen by the server (which will simply see a request for page.html without any URL parameters).&lt;br /&gt;
&lt;br /&gt;
In December 2006, Stefano Di Paola and Giorgio Fedon described a [http://events.ccc.de/congress/2006/Fahrplan/attachments/1158-Subverting_Ajax.pdf universal XSS attack against the Acrobat PDF plugin] ([4]). This attack applied the fragment variant of DOM based XSS to PDF documents. The researchers discovered that a PDF document served to the browser, when rendered by the Acrobat plugin, may end up executing part of the fragment as Javascript. Since the Javascript is executed in the context (DOM) of the current site, all an attacker needed to exploit this flaw was to simply find a PDF link somewhere on the site for the XSS condition to be met. If the attacker then tricked a user into clicking on (or submitting) a link like:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
http://www.some.site/somefile.pdf#somename=javascript:attackers_script_here&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
then a victim using an un-patched Acrobat reader would succumb to the attack. Adobe patched their reader after they were made aware of this flaw, but if not all users have downloaded the patch then those users are still vulnerable to this type of attack.&lt;br /&gt;
&lt;br /&gt;
Ivan Ristic did some research and proposed some server side defenses against this type of attack in his presentation &amp;quot;Protecting Web Applications from Universal PDF XSS: A discussion of how weird the web application security world has become&amp;quot; at the [[OWASP_AppSec_Europe_2007_-_Italy |2007 OWASP Europe AppSec Conference]] in Milan. His presentation ([5]) can be downloaded [http://www.owasp.org/images/c/c2/OWASPAppSec2007Milan_ProtectingWebAppsfromUniversalPDFXSS.ppt here].&lt;br /&gt;
&lt;br /&gt;
=== Extensions ===&lt;br /&gt;
&lt;br /&gt;
Ory Segal gave an example (section “Javascript flow manipulation” in [2]) of how a target page can be framed and the frame’s parent (in the attacker’s control) can be devised in such manner that it affects the execution of the target page in a way desired by the attacker. The technique shows how DOM manipulation can be useful to modify the execution flow of scripts in the target page.&lt;br /&gt;
&lt;br /&gt;
Kuza55 and Stefano Di Paola discussed more ways in which the concept of DOM manipulation and DOM based XSS can be extended in [3].&lt;br /&gt;
&lt;br /&gt;
=== Testing Tools and Techniques ===&lt;br /&gt;
Minded Security has been doing some significant research into DOM based XSS. They are working on two projects to help with DOM Based XSS:&lt;br /&gt;
&lt;br /&gt;
1. The DOMinator Tool - A commercial tool based on the Firefox browser with modified Spidermonkey Javascript engine that helps testers identify and verify DOM based XSS flaws&lt;br /&gt;
&lt;br /&gt;
See: https://dominator.mindedsecurity.com/ (https://github.com/wisec/DOMinator for the open source part)&lt;br /&gt;
&lt;br /&gt;
2. The DOM XSS Wiki - The start of a Knowledgebase for defining sources of attacker controlled inputs and sinks which could potentially introduce DOM Based XSS issues. Its very immature as of 11/17/2011. Please contribute to this wiki if you know of more dangerous sinks and/or safe alternatives!!&lt;br /&gt;
&lt;br /&gt;
See: http://code.google.com/p/domxsswiki/&lt;br /&gt;
&lt;br /&gt;
3. DOM Snitch - An experimental Chrome extension that enables developers and testers to identify insecure practices commonly found in client-side code. From Google.&lt;br /&gt;
&lt;br /&gt;
See: http://code.google.com/p/domsnitch/&lt;br /&gt;
&lt;br /&gt;
=== Defense Techniques ===&lt;br /&gt;
&lt;br /&gt;
See: https://www.owasp.org/index.php/DOM_based_XSS_Prevention_Cheat_Sheet&lt;br /&gt;
&lt;br /&gt;
=== References ===&lt;br /&gt;
&lt;br /&gt;
[1] “DOM Based Cross Site Scripting or XSS of the Third Kind” (WASC writeup), Amit Klein, July 2005&lt;br /&gt;
&lt;br /&gt;
http://www.webappsec.org/projects/articles/071105.shtml &lt;br /&gt;
&lt;br /&gt;
[2] “JavaScript Code Flow Manipulation, and a real world example advisory - Adobe Flex 3 Dom-Based XSS” (Watchfire blog), Ory Segal, June 17th, 2008&lt;br /&gt;
&lt;br /&gt;
http://blog.watchfire.com/wfblog/2008/06/javascript-code.html&lt;br /&gt;
&lt;br /&gt;
[3] “Attacking Rich Internet Applications” (RUXCON 2008 presentation), Kuza55 and Stefano Di Paola, November 2008&lt;br /&gt;
&lt;br /&gt;
http://www.ruxcon.org.au/files/2008/Attacking_Rich_Internet_Applications.pdf&lt;br /&gt;
&lt;br /&gt;
[4] “Subverting Ajax” (23C3 presentation), Stefano Di Paola and Giorgio Fedon, December 2006&lt;br /&gt;
&lt;br /&gt;
http://events.ccc.de/congress/2006/Fahrplan/attachments/1158-Subverting_Ajax.pdf&lt;br /&gt;
&lt;br /&gt;
[5] &amp;quot;Protecting Web Applications from Universal PDF XSS&amp;quot; (2007 OWASP Europe AppSec presentation) Ivan Ristic, May 2007&lt;br /&gt;
&lt;br /&gt;
http://www.owasp.org/images/c/c2/OWASPAppSec2007Milan_ProtectingWebAppsfromUniversalPDFXSS.ppt&lt;br /&gt;
&lt;br /&gt;
[6] OWASP Testing Guide&lt;br /&gt;
&lt;br /&gt;
[[Testing_for_DOM-based_Cross_site_scripting_(OWASP-DV-003)]]&lt;/div&gt;</summary>
		<author><name>Dimisec</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=Appendix_A:_Testing_Tools&amp;diff=144208</id>
		<title>Appendix A: Testing Tools</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=Appendix_A:_Testing_Tools&amp;diff=144208"/>
				<updated>2013-02-13T13:14:07Z</updated>
		
		<summary type="html">&lt;p&gt;Dimisec: added references to DOMinator Pro, w3af and skip fish&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Template:OWASP Testing Guide v4}}&lt;br /&gt;
&lt;br /&gt;
==Open Source Black Box Testing tools==&lt;br /&gt;
&lt;br /&gt;
=== General Testing ===&lt;br /&gt;
&lt;br /&gt;
* '''[[OWASP_WebScarab_Project|OWASP WebScarab]]'''&lt;br /&gt;
* '''[[OWASP_CAL9000_Project|OWASP CAL9000]]'''&lt;br /&gt;
** CAL9000 is a collection of browser-based tools that enable more effective and efficient manual testing efforts.&lt;br /&gt;
** Includes an XSS Attack Library, Character Encoder/Decoder, HTTP Request Generator and Response Evaluator, Testing Checklist, Automated Attack Editor and much more.&lt;br /&gt;
*  '''[[:Category:OWASP Pantera Web Assessment Studio Project|OWASP Pantera Web Assessment Studio Project]]'''&lt;br /&gt;
* SPIKE - http://www.immunitysec.com/resources-freesoftware.shtml&lt;br /&gt;
* Paros - http://www.parosproxy.org&lt;br /&gt;
* Burp Proxy - http://www.portswigger.net/Burp/&lt;br /&gt;
* Achilles Proxy - http://www.mavensecurity.com/achilles&lt;br /&gt;
* Odysseus Proxy - http://www.wastelands.gen.nz/odysseus/&lt;br /&gt;
* Webstretch Proxy - http://sourceforge.net/projects/webstretch&lt;br /&gt;
* Firefox LiveHTTPHeaders - https://addons.mozilla.org/en-US/firefox/addon/live-http-headers/&lt;br /&gt;
* Firefox Tamper Data - https://addons.mozilla.org/en-US/firefox/addon/tamper-data/&lt;br /&gt;
* Firefox Web Developer Tools - https://addons.mozilla.org/en-US/firefox/addon/web-developer/&lt;br /&gt;
* Firefox Firebug - http://getfirebug.com/&lt;br /&gt;
* Grendel-Scan - http://securitytube-tools.net/index.php?title=Grendel_Scan&lt;br /&gt;
* OWASP SWFIntruder - http://www.mindedsecurity.com/swfintruder.html&lt;br /&gt;
* Sensepost Wikto (Google cached fault-finding) - http://www.sensepost.com/labs/tools/pentest/wikto&lt;br /&gt;
* w3af - http://w3af.org&lt;br /&gt;
* skipfish - http://code.google.com/p/skipfish/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Testing for specific vulnerabilities ===&lt;br /&gt;
&lt;br /&gt;
==== Testing for DOM XSS ====&lt;br /&gt;
* DOMinator Pro - https://dominator.mindedsecurity.com&lt;br /&gt;
&lt;br /&gt;
==== Testing AJAX ====&lt;br /&gt;
* '''[[:Category:OWASP Sprajax Project|OWASP Sprajax Project]]'''&lt;br /&gt;
==== Testing for SQL Injection ====&lt;br /&gt;
* '''[[:Category:OWASP_SQLiX_Project|OWASP SQLiX]]'''&lt;br /&gt;
* Sqlninja: a SQL Server Injection &amp;amp; Takeover Tool - http://sqlninja.sourceforge.net&lt;br /&gt;
* Bernardo Damele A. G.: sqlmap, automatic SQL injection tool - http://sqlmap.org/&lt;br /&gt;
* Absinthe 1.1 (formerly SQLSqueal) - http://sourceforge.net/projects/absinthe/&lt;br /&gt;
* SQLInjector - http://www.databasesecurity.com/sql-injector.htm&lt;br /&gt;
* Bsqlbf-v2 - http://code.google.com/p/bsqlbf-v2/&lt;br /&gt;
* Pangolin - http://www.darknet.org.uk/2009/05/pangolin-automatic-sql-injection-tool/&lt;br /&gt;
* Antonio Parata: Dump Files by sql inference on Mysql - SqlDumper - http://www.ruizata.com/&lt;br /&gt;
* Multiple DBMS Sql Injection tool - SQL Power Injector - http://www.sqlpowerinjector.com/&lt;br /&gt;
* MySql Blind Injection Bruteforcing, Reversing.org - sqlbftools - http://packetstormsecurity.org/files/43795/sqlbftools-1.2.tar.gz.html&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Testing Oracle ====&lt;br /&gt;
* TNS Listener tool (Perl) - http://www.jammed.com/%7Ejwa/hacks/security/tnscmd/tnscmd-doc.html&lt;br /&gt;
* Toad for Oracle - http://www.quest.com/toad &lt;br /&gt;
==== Testing SSL ====&lt;br /&gt;
* Foundstone SSL Digger - http://www.mcafee.com/us/downloads/free-tools/ssldigger.aspx&lt;br /&gt;
==== Testing for Brute Force Password ====&lt;br /&gt;
* THC Hydra - http://www.thc.org/thc-hydra/&lt;br /&gt;
* John the Ripper - http://www.openwall.com/john/&lt;br /&gt;
* Brutus - http://www.hoobie.net/brutus/ &lt;br /&gt;
* Medusa - http://www.foofus.net/~jmk/medusa/medusa.html&lt;br /&gt;
*Ncat - http://nmap.org/ncat/&lt;br /&gt;
&lt;br /&gt;
==== Testing Buffer Overflow ====&lt;br /&gt;
*  OllyDbg - http://www.ollydbg.de&lt;br /&gt;
** &amp;quot;A windows based debugger used for analyzing buffer overflow vulnerabilities&amp;quot;&lt;br /&gt;
* Spike - http://www.immunitysec.com/downloads/SPIKE2.9.tgz&lt;br /&gt;
** A fuzzer framework that can be used to explore vulnerabilities and perform length testing&lt;br /&gt;
* Brute Force Binary Tester (BFB) - http://bfbtester.sourceforge.net&lt;br /&gt;
** A proactive binary checker&lt;br /&gt;
&lt;br /&gt;
[[Category:FIXME|link not working&lt;br /&gt;
&lt;br /&gt;
* Metasploit - http://www.metasploit.com/projects/Framework/&lt;br /&gt;
** A rapid exploit development and Testing frame work&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
==== Fuzzer  ====&lt;br /&gt;
* '''[[:Category:OWASP_WSFuzzer_Project|OWASP WSFuzzer]]'''&lt;br /&gt;
* Wfuzz - http://www.darknet.org.uk/2007/07/wfuzz-a-tool-for-bruteforcingfuzzing-web-applications/&lt;br /&gt;
&lt;br /&gt;
==== Googling ====&lt;br /&gt;
* Stach &amp;amp; Liu's Google Hacking Diggity Project - http://www.stachliu.com/resources/tools/google-hacking-diggity-project/&lt;br /&gt;
* Foundstone Sitedigger (Google cached fault-finding) - http://www.mcafee.com/us/downloads/free-tools/sitedigger.aspx&lt;br /&gt;
&lt;br /&gt;
==Commercial Black Box Testing tools==&lt;br /&gt;
&lt;br /&gt;
* NGS Typhon III - http://www.nccgroup.com/en/our-services/security-testing-audit-compliance/information-security-software/ngs-typhon-iii/&lt;br /&gt;
* NGSSQuirreL - http://www.nccgroup.com/en/our-services/security-testing-audit-compliance/information-security-software/ngs-squirrel-vulnerability-scanners/&lt;br /&gt;
* IBM AppScan - http://www-01.ibm.com/software/awdtools/appscan/&lt;br /&gt;
* Cenzic Hailstorm - http://www.cenzic.com/products_services/cenzic_hailstorm.php&lt;br /&gt;
* Burp Intruder - http://www.portswigger.net/burp/intruder.html&lt;br /&gt;
* Acunetix Web Vulnerability Scanner - http://www.acunetix.com&lt;br /&gt;
* Sleuth - http://www.sandsprite.com&lt;br /&gt;
* NT Objectives NTOSpider - http://www.ntobjectives.com/products/ntospider.php&lt;br /&gt;
* MaxPatrol Security Scanner - http://www.maxpatrol.com&lt;br /&gt;
* Ecyware GreenBlue Inspector - http://www.ecyware.com&lt;br /&gt;
* Parasoft SOAtest (more QA-type tool)- http://www.parasoft.com/jsp/products/soatest.jsp?itemId=101&lt;br /&gt;
* MatriXay - http://www.dbappsecurity.com/webscan.html&lt;br /&gt;
* N-Stalker Web Application Security Scanner - http://www.nstalker.com&lt;br /&gt;
* HP WebInspect - http://www.hpenterprisesecurity.com/products/hp-fortify-software-security-center/hp-webinspect&lt;br /&gt;
* SoapUI (Web Service security testing) - http://www.soapui.org/Security/getting-started.html&lt;br /&gt;
* Netsparker - http://www.mavitunasecurity.com/netsparker/&lt;br /&gt;
* SAINT - http://www.saintcorporation.com/&lt;br /&gt;
&lt;br /&gt;
[[Category:FIXME|check these links&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Cenzic Hailstorm - http://www.cenzic.com/products_services/cenzic_hailstorm.php&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
link broken:&lt;br /&gt;
&lt;br /&gt;
* ScanDo - http://www.kavado.com&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
==Source Code Analyzers==&lt;br /&gt;
&lt;br /&gt;
===Open Source / Freeware===&lt;br /&gt;
* [[:Category:OWASP_Orizon_Project|Owasp Orizon]]&lt;br /&gt;
* '''[[:Category:OWASP_LAPSE_Project|OWASP LAPSE]]''' &lt;br /&gt;
* [[OWASP O2 Platform]]&lt;br /&gt;
* Google CodeSearchDiggity - http://www.stachliu.com/resources/tools/google-hacking-diggity-project/attack-tools/&lt;br /&gt;
* PMD - http://pmd.sourceforge.net/&lt;br /&gt;
* FlawFinder - http://www.dwheeler.com/flawfinder&lt;br /&gt;
* Microsoft’s [[FxCop]]&lt;br /&gt;
* Splint - http://splint.org&lt;br /&gt;
* Boon - http://www.cs.berkeley.edu/~daw/boon&lt;br /&gt;
* FindBugs - http://findbugs.sourceforge.net&lt;br /&gt;
* Oedipus - http://www.darknet.org.uk/2006/06/oedipus-open-source-web-application-security-analysis/&lt;br /&gt;
* W3af - http://w3af.sourceforge.net/&lt;br /&gt;
&lt;br /&gt;
[[Category:FIXME|broken link&lt;br /&gt;
&lt;br /&gt;
* Pscan - http://www.striker.ottawa.on.ca/~aland/pscan&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
===Commercial ===&lt;br /&gt;
&lt;br /&gt;
* Armorize CodeSecure - http://www.armorize.com/index.php?link_id=codesecure&lt;br /&gt;
* Parasoft C/C++ test - http://www.parasoft.com/jsp/products/cpptest.jsp/index.htm&lt;br /&gt;
* Checkmarx CxSuite  - http://www.checkmarx.com&lt;br /&gt;
* HP Fortify - http://www.hpenterprisesecurity.com/products/hp-fortify-software-security-center/hp-fortify-static-code-analyzer&lt;br /&gt;
* GrammaTech - http://www.grammatech.com&lt;br /&gt;
* ITS4 - http://seclab.cs.ucdavis.edu/projects/testing/tools/its4.html&lt;br /&gt;
* Appscan - http://www-01.ibm.com/software/rational/products/appscan/source/&lt;br /&gt;
* ParaSoft - http://www.parasoft.com&lt;br /&gt;
* Virtual Forge CodeProfiler for ABAP - http://www.virtualforge.de&lt;br /&gt;
* Veracode - http://www.veracode.com&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:FIXME|link not working&lt;br /&gt;
&lt;br /&gt;
* Armorize CodeSecure - http://www.armorize.com/product/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
==Acceptance Testing Tools==&lt;br /&gt;
Acceptance testing tools are used to validate the functionality of web applications.  Some follow a scripted approach and typically make use of a Unit Testing framework to construct test suites and test cases.  Most, if not all, can be adapted to perform security specific tests in addition to functional tests.&lt;br /&gt;
&lt;br /&gt;
===Open Source Tools===&lt;br /&gt;
&lt;br /&gt;
* WATIR - http://wtr.rubyforge.org&lt;br /&gt;
** A Ruby based web testing framework that provides an interface into Internet Explorer.&lt;br /&gt;
** Windows only.&lt;br /&gt;
* HtmlUnit - http://htmlunit.sourceforge.net &lt;br /&gt;
** A Java and JUnit based framework that uses the Apache HttpClient as the transport.&lt;br /&gt;
** Very robust and configurable and is used as the engine for a number of other testing tools.&lt;br /&gt;
* jWebUnit - http://jwebunit.sourceforge.net&lt;br /&gt;
** A Java based meta-framework that uses htmlunit or selenium as the testing engine.&lt;br /&gt;
* Canoo Webtest - http://webtest.canoo.com&lt;br /&gt;
** An XML based testing tool that provides a facade on top of htmlunit.&lt;br /&gt;
** No coding is necessary as the tests are completely specified in XML.&lt;br /&gt;
** There is the option of scripting some elements in Groovy if XML does not suffice.&lt;br /&gt;
** Very actively maintained.&lt;br /&gt;
* HttpUnit - http://httpunit.sourceforge.net&lt;br /&gt;
** One of the first web testing frameworks, suffers from using the native JDK provided HTTP transport, which can be a bit limiting for security testing.&lt;br /&gt;
* Watij - http://watij.com&lt;br /&gt;
** A Java implementation of WATIR.&lt;br /&gt;
** Windows only because it uses IE for its tests (Mozilla integration is in the works).&lt;br /&gt;
* Solex - http://solex.sourceforge.net&lt;br /&gt;
** An Eclipse plugin that provides a graphical tool to record HTTP sessions and make assertions based on the results.&lt;br /&gt;
* Selenium - http://seleniumhq.org/&lt;br /&gt;
** JavaScript based testing framework, cross-platform and provides a GUI for creating tests.&lt;br /&gt;
** Mature and popular tool, but the use of JavaScript could hamper certain security tests.&lt;br /&gt;
&lt;br /&gt;
==Other Tools==&lt;br /&gt;
&lt;br /&gt;
===Runtime Analysis===&lt;br /&gt;
&lt;br /&gt;
*  Rational PurifyPlus - http://www-01.ibm.com/software/awdtools/purify/&lt;br /&gt;
&lt;br /&gt;
===Binary Analysis===&lt;br /&gt;
&lt;br /&gt;
* BugScam IDC Package - http://sourceforge.net/projects/bugscam&lt;br /&gt;
* Veracode - http://www.veracode.com&lt;br /&gt;
&lt;br /&gt;
===Requirements Management===&lt;br /&gt;
&lt;br /&gt;
* Rational Requisite Pro - http://www-306.ibm.com/software/awdtools/reqpro&lt;br /&gt;
&lt;br /&gt;
===Site Mirroring===&lt;br /&gt;
* wget - http://www.gnu.org/software/wget, http://www.interlog.com/~tcharron/wgetwin.html&lt;br /&gt;
* curl - http://curl.haxx.se &lt;br /&gt;
* Sam Spade - http://www.samspade.org&lt;br /&gt;
* Xenu's Link Sleuth - http://home.snafu.de/tilman/xenulink.html&lt;/div&gt;</summary>
		<author><name>Dimisec</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=AppSecEU2013/CfTrainings&amp;diff=142943</id>
		<title>AppSecEU2013/CfTrainings</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=AppSecEU2013/CfTrainings&amp;diff=142943"/>
				<updated>2013-01-28T07:21:37Z</updated>
		
		<summary type="html">&lt;p&gt;Dimisec: Created page with &amp;quot;Call for Trainings will be posted here shortly.&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Call for Trainings will be posted here shortly.&lt;/div&gt;</summary>
		<author><name>Dimisec</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=OWASP_Testing_Guide_v4_Table_of_Contents&amp;diff=138690</id>
		<title>OWASP Testing Guide v4 Table of Contents</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=OWASP_Testing_Guide_v4_Table_of_Contents&amp;diff=138690"/>
				<updated>2012-11-04T09:56:40Z</updated>
		
		<summary type="html">&lt;p&gt;Dimisec: typo - missing brackets&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
&lt;br /&gt;
'''This is the DRAFT of the table of content of the New Testing Guide v4.'''&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;You can download the stable version v3 [http://www.owasp.org/images/5/56/OWASP_Testing_Guide_v3.pdf here] &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Back to the OWASP Testing Guide Project:&lt;br /&gt;
http://www.owasp.org/index.php/OWASP_Testing_Project&lt;br /&gt;
&lt;br /&gt;
'''Updated: 22nd October 2012'''&lt;br /&gt;
&lt;br /&gt;
[[ OWTGv4 Contributors list|'''Contributors List]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following is a DRAFT of the Toc based on the feedback already received.&lt;br /&gt;
&lt;br /&gt;
== Table of Contents ==&lt;br /&gt;
&lt;br /&gt;
==[[Testing Guide Foreword|Foreword by OWASP Chair]]== &lt;br /&gt;
[To review--&amp;gt; OWASP Chair]&lt;br /&gt;
&lt;br /&gt;
==[[Testing Guide Frontispiece |1. Frontispiece]]== &lt;br /&gt;
[To review--&amp;gt; Mat]&lt;br /&gt;
&lt;br /&gt;
'''[[Testing Guide Frontispiece|1.1 About the OWASP Testing Guide Project]]''' &lt;br /&gt;
[To review--&amp;gt; Mat]&lt;br /&gt;
&lt;br /&gt;
'''[[About The Open Web Application Security Project|1.2 About The Open Web Application Security Project]]''' &lt;br /&gt;
[To review--&amp;gt; ]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==[[Testing Guide Introduction|2. Introduction]]==&lt;br /&gt;
&lt;br /&gt;
'''2.1 The OWASP Testing Project'''&lt;br /&gt;
&lt;br /&gt;
'''2.2 Principles of Testing'''&lt;br /&gt;
&lt;br /&gt;
'''2.3 Testing Techniques Explained''' &lt;br /&gt;
&lt;br /&gt;
2.4 [https://www.owasp.org/index.php/Testing_Guide_Introduction#Security_Requirements_Test_Derivation Security requirements test derivation],[https://www.owasp.org/index.php/Testing_Guide_Introduction#Functional_and_Non_Functional_Test_Requirements functional and non functional test requirements], and [https://www.owasp.org/index.php/Testing_Guide_Introduction#Test_Cases_Through_Use_and_Misuse_Cases test cases through use and misuse cases]&lt;br /&gt;
&lt;br /&gt;
2.5 [https://www.owasp.org/index.php/Testing_Guide_Introduction#Security_Test_Data_Analysis_and_Reporting Security test data analysis and reporting: root cause identification and business/role case test data reporting]&lt;br /&gt;
&lt;br /&gt;
==[[The OWASP Testing Framework|3. The OWASP Testing Framework]]==&lt;br /&gt;
&lt;br /&gt;
'''3.1. Overview'''&lt;br /&gt;
&lt;br /&gt;
'''3.2. Phase 1: Before Development Begins '''&lt;br /&gt;
&lt;br /&gt;
'''3.3. Phase 2: During Definition and Design'''&lt;br /&gt;
&lt;br /&gt;
'''3.4. Phase 3: During Development'''&lt;br /&gt;
&lt;br /&gt;
'''3.5. Phase 4: During Deployment'''&lt;br /&gt;
&lt;br /&gt;
'''3.6. Phase 5: Maintenance and Operations'''&lt;br /&gt;
&lt;br /&gt;
'''3.7. A Typical SDLC Testing Workflow '''&lt;br /&gt;
&lt;br /&gt;
==[[Web Application Penetration Testing |4. Web Application Penetration Testing ]]==&lt;br /&gt;
&lt;br /&gt;
[[Testing: Introduction and objectives|'''4.1 Introduction and Objectives''']] [To review--&amp;gt; Mat]&lt;br /&gt;
&lt;br /&gt;
[[Testing Checklist| 4.1.1 Testing Checklist]] [To review at the end of brainstorming --&amp;gt; Mat]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Testing: Information Gathering|'''4.2 Information Gathering ''']] [To review--&amp;gt; contributor here]&lt;br /&gt;
&lt;br /&gt;
[[Testing: Spiders, Robots, and Crawlers (OWASP-IG-001)|4.2.1 Spiders, Robots and Crawlers (OWASP-IG-001)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing: Search engine discovery/reconnaissance (OWASP-IG-002)|4.2.2 Search Engine Discovery/Reconnaissance (OWASP-IG-002)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing: Identify application entry points (OWASP-IG-003)|4.2.3 Identify application entry points (OWASP-IG-003)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Web Application Fingerprint (OWASP-IG-004)|4.2.4 Testing for Web Application Fingerprint (OWASP-IG-004)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Application Discovery (OWASP-IG-005)|4.2.5 Application Discovery (OWASP-IG-005)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Error Code (OWASP-IG-006)|4.2.6 Analysis of Error Codes (OWASP-IG-006)]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Testing for configuration management|'''4.3 Configuration and Deploy Management Testing ''']]&lt;br /&gt;
&lt;br /&gt;
[[Testing for infrastructure configuration management (OWASP-CM-003)|4.3.1 Testing for Infrastructure Configuration Management Testing weakness (OWASP-CM-001)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for application configuration management (OWASP-CM-004)|4.3.2 Testing for Application Configuration Management weakness (OWASP-CM-002)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for file extensions handling  (OWASP-CM-005)|4.3.3 Testing for File Extensions Handling  (OWASP-CM-003)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Old, Backup and Unreferenced Files (OWASP-CM-006)|4.3.4 Old, Backup and Unreferenced Files (OWASP-CM-004) ]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Admin Interfaces  (OWASP-CM-007)|4.3.5 Infrastructure and Application Admin Interfaces  (OWASP-CM-005)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for HTTP Methods and XST  (OWASP-CM-008)|4.3.6 Testing for Bad HTTP Methods (OWASP-CM-006)]][new - Abian Blome]&lt;br /&gt;
&lt;br /&gt;
&amp;gt; Informative Error Messages [MAT NOTE: in info gathering]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Database credentials/connection strings available|4.3.7 Testing for Database credentials/connection strings available (OWASP-CM-007)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Content Security Policy weakness|4.3.8 Testing for Content Security Policy weakness (OWASP-CM-008)]][New! - Simone Onofri]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Missing HSTS header|4.3.9 Testing for Missing HSTS header (OWASP-CM-009)]][New! Juan Manuel Bahamonde ]&lt;br /&gt;
&lt;br /&gt;
[[Testing for RIA policy files weakness|4.3.10 Testing for RIA policy files weakness (OWASP-CM-010)]] [New!]&lt;br /&gt;
&lt;br /&gt;
&amp;gt; Incorrect time[New! MAT NOTE: explain the test in detail please]&lt;br /&gt;
&lt;br /&gt;
&amp;gt; Unpatched components and libraries (e.g. JavaScript libraries)[New! NOTE: tu discuss it]&lt;br /&gt;
&lt;br /&gt;
&amp;gt; Test data in production systems (and vice versa)[New! MAT NOTE: this is not a particular test that could find a vulnerability]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Testing for authentication|'''4.4 Authentication Testing ''']] &lt;br /&gt;
&lt;br /&gt;
[[Testing for Credentials Transported over an Encrypted Channel (OWASP-AT-001)|4.4.1 Testing for Credentials Transported over an Encrypted Channel  (OWASP-AT-001)]] [Robert Winkel]&lt;br /&gt;
&lt;br /&gt;
[[Testing for User Enumeration and Guessable User Account (OWASP-AT-002)|4.4.2 Testing for User Enumeration and Guessable User Account  (OWASP-AT-002)]] [Robert Winkel]&lt;br /&gt;
&lt;br /&gt;
[[Testing for default credentials (OWASP-AT-003)|4.4.3 Testing for default credentials (OWASP-AT-003)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Weak lock out mechanism (OWASP-AT-004)|4.4.4 Testing for Weak lock out mechanism (OWASP-AT-004)]] [New! - Robert Winkel] &lt;br /&gt;
&lt;br /&gt;
&amp;gt; Account lockout DoS [New! - Robert Winkel - we can put it in the 4.4.4]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Bypassing Authentication Schema (OWASP-AT-005)|4.4.5 Testing for bypassing authentication schema (OWASP-AT-005)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Vulnerable Remember Password (OWASP-AT-006)|4.4.6 Testing for vulnerable remember &lt;br /&gt;
password functionality (OWASP-AT-006)]] [Robert Winkel]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Browser cache weakness (OWASP-AT-007)|4.4.7 Testing for Browser cache weakness (OWASP-AT-007)]] [New! - Abian Blome]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Weak password policy (OWASP-AT-008)|4.4.8 Testing for Weak password policy (OWASP-AT-008)]] [New! - Robert Winkel]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Weak or unenforced username policy (OWASP-AT-009)|4.4.9 Testing for Weak or unenforced username policy (OWASP-AT-009)]] [New! - Robert Winkel]&lt;br /&gt;
&lt;br /&gt;
&amp;gt; Weak security question/answer [New! - Robert Winkel - MAT Note: same as AT-006]&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
[[Testing for failure to restrict access to authenticated resource(OWASP-AT-010)|4.4.10 Testing for failure to restrict access to authenticated resource (OWASP-AT-010)]] [New!]&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
[[Testing for weak password change or reset functionalities (OWASP-AT-011)|4.4.11 Testing for weak password change or reset functionalities (OWASP-AT-011)]] [New! - Robert Winkel]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Captcha (OWASP-AT-012)|4.4.12 Testing for CAPTCHA (OWASP-AT-012)]]&lt;br /&gt;
&lt;br /&gt;
&amp;gt; Weaker authentication in alternative channel (e.g. mobile app, IVR, help desk) [New!: MAT Note: to explain better the kind of test to perform please]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Testing for Session Management|'''4.5 Session Management Testing''']] &lt;br /&gt;
&lt;br /&gt;
[[Testing for Session_Management_Schema (OWASP-SM-001)|4.5.1 Testing for Bypassing Session Management Schema (OWASP-SM-001)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for cookies attributes  (OWASP-SM-002)|4.5.2 Testing for Cookies attributes (Cookies are set not ‘HTTP Only’, ‘Secure’,  and no time validity) (OWASP-SM-002)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Session Fixation  (OWASP-SM-003)|4.5.3 Testing for Session Fixation  (OWASP-SM-003)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Exposed Session Variables  (OWASP-SM-004)|4.5.4 Testing for Exposed Session Variables   (OWASP-SM-004)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for CSRF  (OWASP-SM-005)|4.5.5 Testing for Cross Site Request Forgery (CSRF)  (OWASP-SM-005)]]&lt;br /&gt;
&lt;br /&gt;
&amp;gt; Weak Session Token (MAT NOTE included in 4.5.1)&lt;br /&gt;
 &lt;br /&gt;
[[Testing for Session token not restricted properly (OWASP-SM-006)|4.5.6 Testing for Session token not restricted properly (such as domain or path not set properly) (OWASP-SM-006)]] [New! - Abian Blome]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;gt; Session passed over http (NOTE: included in SM-004) [New!] &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Testing for logout functionality (OWASP-SM-007)|4.5.7 Testing for logout functionality (OWASP-SM-007)]]&lt;br /&gt;
&lt;br /&gt;
&amp;gt;Session token not removed on server after logout [New!: NOTE included in the above test]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;gt; Logout function not properly implemented (NOTE:same above)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;gt; Persistent session token [New! NOTE: this is not a vulnerability if session time out is correctly performed]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Session puzzling (OWASP-SM-008)|4.5.8 Testing for Session puzzling (OWASP-SM-008)]] [New! - Abian Blome]&lt;br /&gt;
&lt;br /&gt;
&amp;gt; Missing user-viewable log of authentication events [NOTE: needs more details: which test perform?]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Testing for Authorization|'''4.6 Authorization Testing''']] &lt;br /&gt;
&lt;br /&gt;
[[Testing for Path Traversal  (OWASP-AZ-001)|4.6.1 Testing Directory traversal/file include (OWASP-AZ-001) [Juan Galiana] ]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Bypassing Authorization Schema  (OWASP-AZ-002)|4.6.2 Testing for bypassing authorization schema  (OWASP-AZ-002)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Privilege escalation  (OWASP-AZ-003)|4.6.3 Testing for Privilege Escalation  (OWASP-AZ-003) [Irene Abezgauz]]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Insecure Direct Object References (OWASP-AZ-004)|4.6.4 Testing for Insecure Direct Object References (OWASP-AZ-004) [Irene Abezgauz] ]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Failure to Restrict access to authorized resource (OWASP-AZ-005)|4.6.5 Testing for Failure to Restrict access to authorized resource (OWASP-AZ-005) [New!] ]]&lt;br /&gt;
&lt;br /&gt;
&amp;gt; Server component has excessive privileges (e.g. indexing service, reporting interface, file generator)[New!]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;gt; Lack of enforcement of application entry points (including exposure of objects)[New!]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Testing for business logic   (OWASP-BL-001)|'''4.7 Business Logic Testing  (OWASP-BL-001)''']] [To review--&amp;gt; contributor here]&lt;br /&gt;
Business Logic&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Business logic data validation[New!] NOTE MAT: to discuss this section&amp;lt;br&amp;gt;&lt;br /&gt;
Ability to forge requests[New!]&amp;lt;br&amp;gt;&lt;br /&gt;
Lack of integrity checks (e.g. overwriting updates) [New!]&amp;lt;br&amp;gt;&lt;br /&gt;
Lack of tamper evidence[New!]&amp;lt;br&amp;gt;&lt;br /&gt;
Use of untrusted time source[New!]&amp;lt;br&amp;gt;&lt;br /&gt;
Lack of limits to excessive rate (speed) of use[New!]&amp;lt;br&amp;gt;&lt;br /&gt;
Lack of limits to size of request[New!]&amp;lt;br&amp;gt;&lt;br /&gt;
Lack of limit to number of times a function can be used[New!]&amp;lt;br&amp;gt;&lt;br /&gt;
Bypass of correct sequence[New!]&amp;lt;br&amp;gt;&lt;br /&gt;
Missing user-viewable log of actvity[New!]&amp;lt;br&amp;gt;&lt;br /&gt;
Self-hosted payment cardholder data processing[New!]&amp;lt;br&amp;gt;&lt;br /&gt;
Lack of security incident reporting information[New!]&amp;lt;br&amp;gt;&lt;br /&gt;
Defenses against application mis-use[New!]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Testing for Data Validation|'''4.8 Data Validation Testing''']] &lt;br /&gt;
&lt;br /&gt;
[[Testing for Reflected Cross site scripting (OWASP-DV-001) |4.8.1 Testing for Reflected Cross Site Scripting (OWASP-DV-001) ]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Stored Cross site scripting (OWASP-DV-002) |4.8.2 Testing for Stored Cross Site Scripting (OWASP-DV-002) ]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for HTTP Verb Tampering (OWASP-DV-003)|4.8.3 Testing for HTTP Verb Tampering   [Brad Causey] ]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for HTTP Parameter pollution (OWASP-DV-004)|4.8.4 Testing for HTTP Parameter pollution [Luca Carettoni, Stefano Di Paola, Brad Causey] ]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Unvalidated Redirects and Forwards (OWASP-DV-004)|4.8.5 Testing for Unvalidated Redirects and Forwards [Brad Causey] ]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for SQL Injection (OWASP-DV-005)| 4.8.5 Testing for SQL Injection (OWASP-DV-005) Ismael Gonçalves]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Oracle|4.8.5.1 Oracle Testing]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for MySQL|4.8.5.2 MySQL Testing]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for SQL Server|4.8.5.3 SQL Server Testing]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for MS Access |4.8.5.4 MS Access Testing]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for NoSQL injection|4.8.5.5 Testing for NoSQL injection [New!]]]&lt;br /&gt;
&lt;br /&gt;
[[OWASP_Backend_Security_Project_Testing_PostgreSQL|4.8.5.5 Testing PostgreSQL (from OWASP BSP) ]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for LDAP Injection  (OWASP-DV-006)|4.8.6 Testing for LDAP Injection  (OWASP-DV-006)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for ORM Injection   (OWASP-DV-007)|4.8.7 Testing for ORM Injection   (OWASP-DV-007)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for XML Injection (OWASP-DV-008)|4.8.8 Testing for XML Injection (OWASP-DV-008)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for SSI Injection  (OWASP-DV-009)|4.8.9 Testing for SSI Injection  (OWASP-DV-009)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for XPath Injection  (OWASP-DV-010)|4.8.10 Testing for XPath Injection  (OWASP-DV-010)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for IMAP/SMTP Injection  (OWASP-DV-011)|4.8.11 IMAP/SMTP Injection  (OWASP-DV-011)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Code Injection  (OWASP-DV-012)|4.8.12 Testing for Code Injection  (OWASP-DV-012)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Command Injection   (OWASP-DV-013)|4.8.13 Testing for Command Injection   (OWASP-DV-013) [Juan Galiana]]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Buffer Overflow (OWASP-DV-014)|4.8.14 Testing for Buffer overflow (OWASP-DV-014)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Heap Overflow|4.8.14.1 Testing for Heap overflow]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Stack Overflow|4.8.14.2 Testing for Stack overflow]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Format String|4.8.14.3 Testing for Format string]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Incubated Vulnerability (OWASP-DV-015)|4.8.15 Testing for incubated vulnerabilities (OWASP-DV-015)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for HTTP Splitting/Smuggling  (OWASP-DV-016)|4.8.16 Testing for HTTP Splitting/Smuggling  (OWASP-DV-016) [Juan Galiana] ]]&lt;br /&gt;
&lt;br /&gt;
&amp;gt; Regular expression DoS[New!] note: to understand better&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Data Encryption (New!)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Insecure encryption usage (OWASP-EN-001)| 4.9.1  Testing for Insecure encryption usage (OWASP-EN-001]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Weak SSL/TSL Ciphers, Insufficient Transport Layer Protection (OWASP-EN-002)| 4.9.2 Testing for Weak SSL/TSL Ciphers, Insufficient Transport Layer Protection (OWASP-EN-002)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Padding Oracle (OWASP-EN-003)| 4.9.3 Testing for Padding Oracle (OWASP-EN-003) [Giorgio Fedon]]]&lt;br /&gt;
&lt;br /&gt;
&amp;gt; [[Testing for Cacheable HTTPS Response | x.x.3 Testing for Cacheable HTTPS Response&amp;lt;br&amp;gt;&lt;br /&gt;
Cache directives insecure&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;gt; Testing for Insecure Cryptographic Storage [put in x.x.1]&amp;lt;br&amp;gt;&lt;br /&gt;
[[Testing for Sensitive information sent via unencrypted channels | x.x.4&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Web Service (XML Interpreter)|'''4.10 Web Service Testing''']] [Tom Eston] &lt;br /&gt;
&lt;br /&gt;
[[Scoping a Web Service Test (OWASP-WS-001)|4.10.1 Scoping a Web Service Test (OWASP-WS-001)]]&lt;br /&gt;
&lt;br /&gt;
[[WS Information Gathering (OWASP-WS-002)|4.10.2 WS Information Gathering (OWASP-WS-002)]]&lt;br /&gt;
&lt;br /&gt;
[[WS Authentication Testing (OWASP-WS-003)|4.10.3 WS Authentication Testing (OWASP-WS-003)]]&lt;br /&gt;
&lt;br /&gt;
[[WS Management Interface Testing (OWASP-WS-004)|4.10.4 WS Management Interface Testing (OWASP-WS-004)]]&lt;br /&gt;
&lt;br /&gt;
[[Weak XML Structure Testing (OWASP-WS-005)|4.10.5 Weak XML Structure Testing (OWASP-WS-005)]]&lt;br /&gt;
&lt;br /&gt;
[[XML Content-Level Testing (OWASP-WS-006)|4.10.6 XML Content-Level Testing (OWASP-WS-006)]]&lt;br /&gt;
&lt;br /&gt;
[[WS HTTP GET Parameters/REST Testing (OWASP-WS-007)|4.10.7 WS HTTP GET Parameters/REST Testing (OWASP-WS-007)]]&lt;br /&gt;
&lt;br /&gt;
[[WS Naughty SOAP Attachment Testing (OWASP-WS-008)|4.10.8 WS Naughty SOAP Attachment Testing (OWASP-WS-008)]]&lt;br /&gt;
&lt;br /&gt;
[[WS Replay/MiTM Testing (OWASP-WS-009)|4.10.9 WS Replay/MiTM Testing (OWASP-WS-009)]]&lt;br /&gt;
&lt;br /&gt;
[[WS BEPL Testing (OWASP-WS-010)|4.10.10 WS BEPL Testing (OWASP-WS-010)]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Client Side Testing|'''4.11 Client Side Testing''']] [New!] &lt;br /&gt;
&lt;br /&gt;
[[Testing for DOM-based Cross site scripting  (OWASP-DV-003)|4.11.1 Testing for DOM based Cross Site Scripting  (OWASP-CS-001) [Stefano Di Paola] ]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for HTML5 (OWASP CS-002)|4.11.2 Testing for HTML5 (OWASP CS-002) [Juan Galiana] ]]&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Cross site flashing (OWASP-DV-004)|4.11.3 Testing for Cross Site Flashing   (OWASP-CS-003)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Testing for ClickHijacking (OWASP-CS-004)|4.11.4 Testing for Testing for ClickHijacking (OWASP-CS-004) ]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==[[Writing Reports: value the real risk |5. Writing Reports: value the real risk ]]==&lt;br /&gt;
&lt;br /&gt;
[[How to value the real risk |5.1 How to value the real risk]] [To review--&amp;gt; contributor here]&lt;br /&gt;
&lt;br /&gt;
[[How to write the report of the testing |5.2 How to write the report of the testing]] [To review--&amp;gt; contributor here]&lt;br /&gt;
&lt;br /&gt;
==[[Appendix A: Testing Tools |Appendix A: Testing Tools ]]==&lt;br /&gt;
&lt;br /&gt;
* Black Box Testing Tools [To review--&amp;gt; Amro. We need only tools for webapp testing]&lt;br /&gt;
&lt;br /&gt;
==[[OWASP Testing Guide Appendix B: Suggested Reading | Appendix B: Suggested Reading]]==&lt;br /&gt;
* Whitepapers [To review--&amp;gt; David Fern]&lt;br /&gt;
* Books [To review--&amp;gt; David Fern]&lt;br /&gt;
* Useful Websites [To review--&amp;gt; David Fern]&lt;br /&gt;
&lt;br /&gt;
==[[OWASP Testing Guide Appendix C: Fuzz Vectors | Appendix C: Fuzz Vectors]]==&lt;br /&gt;
&lt;br /&gt;
* Fuzz Categories [To review--&amp;gt; contributor here]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==[[OWASP Testing Guide Appendix D: Encoded Injection | Appendix D: Encoded Injection]]==&lt;br /&gt;
&lt;br /&gt;
[To review--&amp;gt; contributor here]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP Testing Project]]&lt;/div&gt;</summary>
		<author><name>Dimisec</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=OWASP_Testing_Guide_v4_Table_of_Contents&amp;diff=138689</id>
		<title>OWASP Testing Guide v4 Table of Contents</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=OWASP_Testing_Guide_v4_Table_of_Contents&amp;diff=138689"/>
				<updated>2012-11-04T09:54:14Z</updated>
		
		<summary type="html">&lt;p&gt;Dimisec: typo (&amp;quot;We ned only tools fo webapp testing&amp;quot; =&amp;gt; for)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
&lt;br /&gt;
'''This is the DRAFT of the table of content of the New Testing Guide v4.'''&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;You can download the stable version v3 [http://www.owasp.org/images/5/56/OWASP_Testing_Guide_v3.pdf here] &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Back to the OWASP Testing Guide Project:&lt;br /&gt;
http://www.owasp.org/index.php/OWASP_Testing_Project&lt;br /&gt;
&lt;br /&gt;
'''Updated: 22nd October 2012'''&lt;br /&gt;
&lt;br /&gt;
[[ OWTGv4 Contributors list|'''Contributors List]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following is a DRAFT of the Toc based on the feedback already received.&lt;br /&gt;
&lt;br /&gt;
== Table of Contents ==&lt;br /&gt;
&lt;br /&gt;
==[[Testing Guide Foreword|Foreword by OWASP Chair]]== &lt;br /&gt;
[To review--&amp;gt; OWASP Chair]&lt;br /&gt;
&lt;br /&gt;
==[[Testing Guide Frontispiece |1. Frontispiece]]== &lt;br /&gt;
[To review--&amp;gt; Mat]&lt;br /&gt;
&lt;br /&gt;
'''[[Testing Guide Frontispiece|1.1 About the OWASP Testing Guide Project]]''' &lt;br /&gt;
[To review--&amp;gt; Mat]&lt;br /&gt;
&lt;br /&gt;
'''[[About The Open Web Application Security Project|1.2 About The Open Web Application Security Project]]''' &lt;br /&gt;
[To review--&amp;gt; ]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==[[Testing Guide Introduction|2. Introduction]]==&lt;br /&gt;
&lt;br /&gt;
'''2.1 The OWASP Testing Project'''&lt;br /&gt;
&lt;br /&gt;
'''2.2 Principles of Testing'''&lt;br /&gt;
&lt;br /&gt;
'''2.3 Testing Techniques Explained''' &lt;br /&gt;
&lt;br /&gt;
2.4 [https://www.owasp.org/index.php/Testing_Guide_Introduction#Security_Requirements_Test_Derivation Security requirements test derivation],[https://www.owasp.org/index.php/Testing_Guide_Introduction#Functional_and_Non_Functional_Test_Requirements functional and non functional test requirements], and [https://www.owasp.org/index.php/Testing_Guide_Introduction#Test_Cases_Through_Use_and_Misuse_Cases test cases through use and misuse cases]&lt;br /&gt;
&lt;br /&gt;
2.5 [https://www.owasp.org/index.php/Testing_Guide_Introduction#Security_Test_Data_Analysis_and_Reporting Security test data analysis and reporting: root cause identification and business/role case test data reporting]&lt;br /&gt;
&lt;br /&gt;
==[[The OWASP Testing Framework|3. The OWASP Testing Framework]]==&lt;br /&gt;
&lt;br /&gt;
'''3.1. Overview'''&lt;br /&gt;
&lt;br /&gt;
'''3.2. Phase 1: Before Development Begins '''&lt;br /&gt;
&lt;br /&gt;
'''3.3. Phase 2: During Definition and Design'''&lt;br /&gt;
&lt;br /&gt;
'''3.4. Phase 3: During Development'''&lt;br /&gt;
&lt;br /&gt;
'''3.5. Phase 4: During Deployment'''&lt;br /&gt;
&lt;br /&gt;
'''3.6. Phase 5: Maintenance and Operations'''&lt;br /&gt;
&lt;br /&gt;
'''3.7. A Typical SDLC Testing Workflow '''&lt;br /&gt;
&lt;br /&gt;
==[[Web Application Penetration Testing |4. Web Application Penetration Testing ]]==&lt;br /&gt;
&lt;br /&gt;
[[Testing: Introduction and objectives|'''4.1 Introduction and Objectives''']] [To review--&amp;gt; Mat]&lt;br /&gt;
&lt;br /&gt;
[[Testing Checklist| 4.1.1 Testing Checklist]] [To review at the end of brainstorming --&amp;gt; Mat]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Testing: Information Gathering|'''4.2 Information Gathering ''']] [To review--&amp;gt; contributor here]&lt;br /&gt;
&lt;br /&gt;
[[Testing: Spiders, Robots, and Crawlers (OWASP-IG-001)|4.2.1 Spiders, Robots and Crawlers (OWASP-IG-001)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing: Search engine discovery/reconnaissance (OWASP-IG-002)|4.2.2 Search Engine Discovery/Reconnaissance (OWASP-IG-002)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing: Identify application entry points (OWASP-IG-003)|4.2.3 Identify application entry points (OWASP-IG-003)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Web Application Fingerprint (OWASP-IG-004)|4.2.4 Testing for Web Application Fingerprint (OWASP-IG-004)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Application Discovery (OWASP-IG-005)|4.2.5 Application Discovery (OWASP-IG-005)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Error Code (OWASP-IG-006)|4.2.6 Analysis of Error Codes (OWASP-IG-006)]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Testing for configuration management|'''4.3 Configuration and Deploy Management Testing ''']]&lt;br /&gt;
&lt;br /&gt;
[[Testing for infrastructure configuration management (OWASP-CM-003)|4.3.1 Testing for Infrastructure Configuration Management Testing weakness (OWASP-CM-001)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for application configuration management (OWASP-CM-004)|4.3.2 Testing for Application Configuration Management weakness (OWASP-CM-002)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for file extensions handling  (OWASP-CM-005)|4.3.3 Testing for File Extensions Handling  (OWASP-CM-003)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Old, Backup and Unreferenced Files (OWASP-CM-006)|4.3.4 Old, Backup and Unreferenced Files (OWASP-CM-004) ]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Admin Interfaces  (OWASP-CM-007)|4.3.5 Infrastructure and Application Admin Interfaces  (OWASP-CM-005)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for HTTP Methods and XST  (OWASP-CM-008)|4.3.6 Testing for Bad HTTP Methods (OWASP-CM-006)]][new - Abian Blome]&lt;br /&gt;
&lt;br /&gt;
&amp;gt; Informative Error Messages [MAT NOTE: in info gathering]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Database credentials/connection strings available|4.3.7 Testing for Database credentials/connection strings available (OWASP-CM-007)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Content Security Policy weakness|4.3.8 Testing for Content Security Policy weakness (OWASP-CM-008)]][New! - Simone Onofri]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Missing HSTS header|4.3.9 Testing for Missing HSTS header (OWASP-CM-009)]][New! Juan Manuel Bahamonde ]&lt;br /&gt;
&lt;br /&gt;
[[Testing for RIA policy files weakness|4.3.10 Testing for RIA policy files weakness (OWASP-CM-010)]] [New!]&lt;br /&gt;
&lt;br /&gt;
&amp;gt; Incorrect time[New! MAT NOTE: explain the test in detail please]&lt;br /&gt;
&lt;br /&gt;
&amp;gt; Unpatched components and libraries (e.g. JavaScript libraries)[New! NOTE: tu discuss it]&lt;br /&gt;
&lt;br /&gt;
&amp;gt; Test data in production systems (and vice versa)[New! MAT NOTE: this is not a particular test that could find a vulnerability]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Testing for authentication|'''4.4 Authentication Testing ''']] &lt;br /&gt;
&lt;br /&gt;
[[Testing for Credentials Transported over an Encrypted Channel (OWASP-AT-001)|4.4.1 Testing for Credentials Transported over an Encrypted Channel  (OWASP-AT-001)]] [Robert Winkel]&lt;br /&gt;
&lt;br /&gt;
[[Testing for User Enumeration and Guessable User Account (OWASP-AT-002)|4.4.2 Testing for User Enumeration and Guessable User Account  (OWASP-AT-002)]] [Robert Winkel]&lt;br /&gt;
&lt;br /&gt;
[[Testing for default credentials (OWASP-AT-003)|4.4.3 Testing for default credentials (OWASP-AT-003)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Weak lock out mechanism (OWASP-AT-004)|4.4.4 Testing for Weak lock out mechanism (OWASP-AT-004)]] [New! - Robert Winkel] &lt;br /&gt;
&lt;br /&gt;
&amp;gt; Account lockout DoS [New! - Robert Winkel - we can put it in the 4.4.4]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Bypassing Authentication Schema (OWASP-AT-005)|4.4.5 Testing for bypassing authentication schema (OWASP-AT-005)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Vulnerable Remember Password (OWASP-AT-006)|4.4.6 Testing for vulnerable remember &lt;br /&gt;
password functionality (OWASP-AT-006)]] [Robert Winkel]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Browser cache weakness (OWASP-AT-007)|4.4.7 Testing for Browser cache weakness (OWASP-AT-007)]] [New! - Abian Blome]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Weak password policy (OWASP-AT-008)|4.4.8 Testing for Weak password policy (OWASP-AT-008)]] [New! - Robert Winkel]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Weak or unenforced username policy (OWASP-AT-009)|4.4.9 Testing for Weak or unenforced username policy (OWASP-AT-009)]] [New! - Robert Winkel]&lt;br /&gt;
&lt;br /&gt;
&amp;gt; Weak security question/answer [New! - Robert Winkel - MAT Note: same as AT-006]&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
[[Testing for failure to restrict access to authenticated resource(OWASP-AT-010)|4.4.10 Testing for failure to restrict access to authenticated resource (OWASP-AT-010)]] [New!]&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
[[Testing for weak password change or reset functionalities (OWASP-AT-011)|4.4.11 Testing for weak password change or reset functionalities (OWASP-AT-011)]] [New! - Robert Winkel]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Captcha (OWASP-AT-012)|4.4.12 Testing for CAPTCHA (OWASP-AT-012)]]&lt;br /&gt;
&lt;br /&gt;
&amp;gt; Weaker authentication in alternative channel (e.g. mobile app, IVR, help desk) [New!: MAT Note: to explain better the kind of test to perform please]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Testing for Session Management|'''4.5 Session Management Testing''']] &lt;br /&gt;
&lt;br /&gt;
[[Testing for Session_Management_Schema (OWASP-SM-001)|4.5.1 Testing for Bypassing Session Management Schema (OWASP-SM-001)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for cookies attributes  (OWASP-SM-002)|4.5.2 Testing for Cookies attributes (Cookies are set not ‘HTTP Only’, ‘Secure’,  and no time validity) (OWASP-SM-002)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Session Fixation  (OWASP-SM-003)|4.5.3 Testing for Session Fixation  (OWASP-SM-003)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Exposed Session Variables  (OWASP-SM-004)|4.5.4 Testing for Exposed Session Variables   (OWASP-SM-004)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for CSRF  (OWASP-SM-005)|4.5.5 Testing for Cross Site Request Forgery (CSRF)  (OWASP-SM-005)]]&lt;br /&gt;
&lt;br /&gt;
&amp;gt; Weak Session Token (MAT NOTE included in 4.5.1)&lt;br /&gt;
 &lt;br /&gt;
[[Testing for Session token not restricted properly (OWASP-SM-006)|4.5.6 Testing for Session token not restricted properly (such as domain or path not set properly) (OWASP-SM-006)]] [New! - Abian Blome]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;gt; Session passed over http (NOTE: included in SM-004) [New!] &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Testing for logout functionality (OWASP-SM-007)|4.5.7 Testing for logout functionality (OWASP-SM-007)]]&lt;br /&gt;
&lt;br /&gt;
&amp;gt;Session token not removed on server after logout [New!: NOTE included in the above test]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;gt; Logout function not properly implemented (NOTE:same above)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;gt; Persistent session token [New! NOTE: this is not a vulnerability if session time out is correctly performed]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Session puzzling (OWASP-SM-008)|4.5.8 Testing for Session puzzling (OWASP-SM-008)]] [New! - Abian Blome]&lt;br /&gt;
&lt;br /&gt;
&amp;gt; Missing user-viewable log of authentication events [NOTE: needs more details: which test perform?]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Testing for Authorization|'''4.6 Authorization Testing''']] &lt;br /&gt;
&lt;br /&gt;
[[Testing for Path Traversal  (OWASP-AZ-001)|4.6.1 Testing Directory traversal/file include (OWASP-AZ-001) [Juan Galiana] ]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Bypassing Authorization Schema  (OWASP-AZ-002)|4.6.2 Testing for bypassing authorization schema  (OWASP-AZ-002)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Privilege escalation  (OWASP-AZ-003)|4.6.3 Testing for Privilege Escalation  (OWASP-AZ-003) [Irene Abezgauz]]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Insecure Direct Object References (OWASP-AZ-004)|4.6.4 Testing for Insecure Direct Object References (OWASP-AZ-004) [Irene Abezgauz] ]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Failure to Restrict access to authorized resource (OWASP-AZ-005)|4.6.5 Testing for Failure to Restrict access to authorized resource (OWASP-AZ-005) [New!] ]]&lt;br /&gt;
&lt;br /&gt;
&amp;gt; Server component has excessive privileges (e.g. indexing service, reporting interface, file generator)[New!]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;gt; Lack of enforcement of application entry points (including exposure of objects)[New!]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Testing for business logic   (OWASP-BL-001)|'''4.7 Business Logic Testing  (OWASP-BL-001)''']] [To review--&amp;gt; contributor here]&lt;br /&gt;
Business Logic&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Business logic data validation[New!] NOTE MAT: to discuss this section&amp;lt;br&amp;gt;&lt;br /&gt;
Ability to forge requests[New!]&amp;lt;br&amp;gt;&lt;br /&gt;
Lack of integrity checks (e.g. overwriting updates) [New!]&amp;lt;br&amp;gt;&lt;br /&gt;
Lack of tamper evidence[New!]&amp;lt;br&amp;gt;&lt;br /&gt;
Use of untrusted time source[New!]&amp;lt;br&amp;gt;&lt;br /&gt;
Lack of limits to excessive rate (speed) of use[New!]&amp;lt;br&amp;gt;&lt;br /&gt;
Lack of limits to size of request[New!]&amp;lt;br&amp;gt;&lt;br /&gt;
Lack of limit to number of times a function can be used[New!]&amp;lt;br&amp;gt;&lt;br /&gt;
Bypass of correct sequence[New!]&amp;lt;br&amp;gt;&lt;br /&gt;
Missing user-viewable log of actvity[New!]&amp;lt;br&amp;gt;&lt;br /&gt;
Self-hosted payment cardholder data processing[New!]&amp;lt;br&amp;gt;&lt;br /&gt;
Lack of security incident reporting information[New!]&amp;lt;br&amp;gt;&lt;br /&gt;
Defenses against application mis-use[New!]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Testing for Data Validation|'''4.8 Data Validation Testing''']] &lt;br /&gt;
&lt;br /&gt;
[[Testing for Reflected Cross site scripting (OWASP-DV-001) |4.8.1 Testing for Reflected Cross Site Scripting (OWASP-DV-001) ]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Stored Cross site scripting (OWASP-DV-002) |4.8.2 Testing for Stored Cross Site Scripting (OWASP-DV-002) ]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for HTTP Verb Tampering (OWASP-DV-003)|4.8.3 Testing for HTTP Verb Tampering   [Brad Causey] ]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for HTTP Parameter pollution (OWASP-DV-004)|4.8.4 Testing for HTTP Parameter pollution [Luca Carettoni, Stefano Di Paola, Brad Causey] ]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Unvalidated Redirects and Forwards (OWASP-DV-004)|4.8.5 Testing for Unvalidated Redirects and Forwards [Brad Causey] ]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for SQL Injection (OWASP-DV-005)| 4.8.5 Testing for SQL Injection (OWASP-DV-005) Ismael Gonçalves]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Oracle|4.8.5.1 Oracle Testing]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for MySQL|4.8.5.2 MySQL Testing]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for SQL Server|4.8.5.3 SQL Server Testing]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for MS Access |4.8.5.4 MS Access Testing]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for NoSQL injection|4.8.5.5 Testing for NoSQL injection [New!]]]&lt;br /&gt;
&lt;br /&gt;
[[OWASP_Backend_Security_Project_Testing_PostgreSQL|4.8.5.5 Testing PostgreSQL (from OWASP BSP) ]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for LDAP Injection  (OWASP-DV-006)|4.8.6 Testing for LDAP Injection  (OWASP-DV-006)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for ORM Injection   (OWASP-DV-007)|4.8.7 Testing for ORM Injection   (OWASP-DV-007)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for XML Injection (OWASP-DV-008)|4.8.8 Testing for XML Injection (OWASP-DV-008)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for SSI Injection  (OWASP-DV-009)|4.8.9 Testing for SSI Injection  (OWASP-DV-009)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for XPath Injection  (OWASP-DV-010)|4.8.10 Testing for XPath Injection  (OWASP-DV-010)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for IMAP/SMTP Injection  (OWASP-DV-011)|4.8.11 IMAP/SMTP Injection  (OWASP-DV-011)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Code Injection  (OWASP-DV-012)|4.8.12 Testing for Code Injection  (OWASP-DV-012)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Command Injection   (OWASP-DV-013)|4.8.13 Testing for Command Injection   (OWASP-DV-013) [Juan Galiana]]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Buffer Overflow (OWASP-DV-014)|4.8.14 Testing for Buffer overflow (OWASP-DV-014)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Heap Overflow|4.8.14.1 Testing for Heap overflow]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Stack Overflow|4.8.14.2 Testing for Stack overflow]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Format String|4.8.14.3 Testing for Format string]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Incubated Vulnerability (OWASP-DV-015)|4.8.15 Testing for incubated vulnerabilities (OWASP-DV-015)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for HTTP Splitting/Smuggling  (OWASP-DV-016)|4.8.16 Testing for HTTP Splitting/Smuggling  (OWASP-DV-016) [Juan Galiana] ]]&lt;br /&gt;
&lt;br /&gt;
&amp;gt; Regular expression DoS[New!] note: to understand better&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Data Encryption (New!)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Insecure encryption usage (OWASP-EN-001)| 4.9.1  Testing for Insecure encryption usage (OWASP-EN-001]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Weak SSL/TSL Ciphers, Insufficient Transport Layer Protection (OWASP-EN-002)| 4.9.2 Testing for Weak SSL/TSL Ciphers, Insufficient Transport Layer Protection (OWASP-EN-002)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Padding Oracle (OWASP-EN-003)| 4.9.3 Testing for Padding Oracle (OWASP-EN-003) [Giorgio Fedon]]]&lt;br /&gt;
&lt;br /&gt;
&amp;gt; [[Testing for Cacheable HTTPS Response | x.x.3 Testing for Cacheable HTTPS Response&amp;lt;br&amp;gt;&lt;br /&gt;
Cache directives insecure&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;gt; Testing for Insecure Cryptographic Storage [put in x.x.1]&amp;lt;br&amp;gt;&lt;br /&gt;
[[Testing for Sensitive information sent via unencrypted channels | x.x.4&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Web Service (XML Interpreter)|'''4.10 Web Service Testing''']] [Tom Eston] &lt;br /&gt;
&lt;br /&gt;
[[Scoping a Web Service Test (OWASP-WS-001)|4.10.1 Scoping a Web Service Test (OWASP-WS-001)]]&lt;br /&gt;
&lt;br /&gt;
[[WS Information Gathering (OWASP-WS-002)|4.10.2 WS Information Gathering (OWASP-WS-002)]]&lt;br /&gt;
&lt;br /&gt;
[[WS Authentication Testing (OWASP-WS-003)|4.10.3 WS Authentication Testing (OWASP-WS-003)]]&lt;br /&gt;
&lt;br /&gt;
[[WS Management Interface Testing (OWASP-WS-004)|4.10.4 WS Management Interface Testing (OWASP-WS-004)]]&lt;br /&gt;
&lt;br /&gt;
[[Weak XML Structure Testing (OWASP-WS-005)|4.10.5 Weak XML Structure Testing (OWASP-WS-005)]]&lt;br /&gt;
&lt;br /&gt;
[[XML Content-Level Testing (OWASP-WS-006)|4.10.6 XML Content-Level Testing (OWASP-WS-006)]]&lt;br /&gt;
&lt;br /&gt;
[[WS HTTP GET Parameters/REST Testing (OWASP-WS-007)|4.10.7 WS HTTP GET Parameters/REST Testing (OWASP-WS-007)]]&lt;br /&gt;
&lt;br /&gt;
[[WS Naughty SOAP Attachment Testing (OWASP-WS-008)|4.10.8 WS Naughty SOAP Attachment Testing (OWASP-WS-008)]]&lt;br /&gt;
&lt;br /&gt;
[[WS Replay/MiTM Testing (OWASP-WS-009)|4.10.9 WS Replay/MiTM Testing (OWASP-WS-009)]]&lt;br /&gt;
&lt;br /&gt;
[[WS BEPL Testing (OWASP-WS-010)|4.10.10 WS BEPL Testing (OWASP-WS-010)]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Client Side Testing|'''4.11 Client Side Testing''']] [New!] &lt;br /&gt;
&lt;br /&gt;
[[Testing for DOM-based Cross site scripting  (OWASP-DV-003)|4.11.1 Testing for DOM based Cross Site Scripting  (OWASP-CS-001) [Stefano Di Paola]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for HTML5 (OWASP CS-002)|4.11.2 Testing for HTML5 (OWASP CS-002) [Juan Galiana] ]]&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Cross site flashing (OWASP-DV-004)|4.11.3 Testing for Cross Site Flashing   (OWASP-CS-003)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Testing for ClickHijacking (OWASP-CS-004)|4.11.4 Testing for Testing for ClickHijacking (OWASP-CS-004) ]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==[[Writing Reports: value the real risk |5. Writing Reports: value the real risk ]]==&lt;br /&gt;
&lt;br /&gt;
[[How to value the real risk |5.1 How to value the real risk]] [To review--&amp;gt; contributor here]&lt;br /&gt;
&lt;br /&gt;
[[How to write the report of the testing |5.2 How to write the report of the testing]] [To review--&amp;gt; contributor here]&lt;br /&gt;
&lt;br /&gt;
==[[Appendix A: Testing Tools |Appendix A: Testing Tools ]]==&lt;br /&gt;
&lt;br /&gt;
* Black Box Testing Tools [To review--&amp;gt; Amro. We need only tools for webapp testing]&lt;br /&gt;
&lt;br /&gt;
==[[OWASP Testing Guide Appendix B: Suggested Reading | Appendix B: Suggested Reading]]==&lt;br /&gt;
* Whitepapers [To review--&amp;gt; David Fern]&lt;br /&gt;
* Books [To review--&amp;gt; David Fern]&lt;br /&gt;
* Useful Websites [To review--&amp;gt; David Fern]&lt;br /&gt;
&lt;br /&gt;
==[[OWASP Testing Guide Appendix C: Fuzz Vectors | Appendix C: Fuzz Vectors]]==&lt;br /&gt;
&lt;br /&gt;
* Fuzz Categories [To review--&amp;gt; contributor here]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==[[OWASP Testing Guide Appendix D: Encoded Injection | Appendix D: Encoded Injection]]==&lt;br /&gt;
&lt;br /&gt;
[To review--&amp;gt; contributor here]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP Testing Project]]&lt;/div&gt;</summary>
		<author><name>Dimisec</name></author>	</entry>

	<entry>
		<id>https://wiki.owasp.org/index.php?title=OWASP_Testing_Guide_v4_Table_of_Contents&amp;diff=138688</id>
		<title>OWASP Testing Guide v4 Table of Contents</title>
		<link rel="alternate" type="text/html" href="https://wiki.owasp.org/index.php?title=OWASP_Testing_Guide_v4_Table_of_Contents&amp;diff=138688"/>
				<updated>2012-11-04T09:51:29Z</updated>
		
		<summary type="html">&lt;p&gt;Dimisec: missing space&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
&lt;br /&gt;
'''This is the DRAFT of the table of content of the New Testing Guide v4.'''&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;You can download the stable version v3 [http://www.owasp.org/images/5/56/OWASP_Testing_Guide_v3.pdf here] &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Back to the OWASP Testing Guide Project:&lt;br /&gt;
http://www.owasp.org/index.php/OWASP_Testing_Project&lt;br /&gt;
&lt;br /&gt;
'''Updated: 22nd October 2012'''&lt;br /&gt;
&lt;br /&gt;
[[ OWTGv4 Contributors list|'''Contributors List]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following is a DRAFT of the Toc based on the feedback already received.&lt;br /&gt;
&lt;br /&gt;
== Table of Contents ==&lt;br /&gt;
&lt;br /&gt;
==[[Testing Guide Foreword|Foreword by OWASP Chair]]== &lt;br /&gt;
[To review--&amp;gt; OWASP Chair]&lt;br /&gt;
&lt;br /&gt;
==[[Testing Guide Frontispiece |1. Frontispiece]]== &lt;br /&gt;
[To review--&amp;gt; Mat]&lt;br /&gt;
&lt;br /&gt;
'''[[Testing Guide Frontispiece|1.1 About the OWASP Testing Guide Project]]''' &lt;br /&gt;
[To review--&amp;gt; Mat]&lt;br /&gt;
&lt;br /&gt;
'''[[About The Open Web Application Security Project|1.2 About The Open Web Application Security Project]]''' &lt;br /&gt;
[To review--&amp;gt; ]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==[[Testing Guide Introduction|2. Introduction]]==&lt;br /&gt;
&lt;br /&gt;
'''2.1 The OWASP Testing Project'''&lt;br /&gt;
&lt;br /&gt;
'''2.2 Principles of Testing'''&lt;br /&gt;
&lt;br /&gt;
'''2.3 Testing Techniques Explained''' &lt;br /&gt;
&lt;br /&gt;
2.4 [https://www.owasp.org/index.php/Testing_Guide_Introduction#Security_Requirements_Test_Derivation Security requirements test derivation],[https://www.owasp.org/index.php/Testing_Guide_Introduction#Functional_and_Non_Functional_Test_Requirements functional and non functional test requirements], and [https://www.owasp.org/index.php/Testing_Guide_Introduction#Test_Cases_Through_Use_and_Misuse_Cases test cases through use and misuse cases]&lt;br /&gt;
&lt;br /&gt;
2.5 [https://www.owasp.org/index.php/Testing_Guide_Introduction#Security_Test_Data_Analysis_and_Reporting Security test data analysis and reporting: root cause identification and business/role case test data reporting]&lt;br /&gt;
&lt;br /&gt;
==[[The OWASP Testing Framework|3. The OWASP Testing Framework]]==&lt;br /&gt;
&lt;br /&gt;
'''3.1. Overview'''&lt;br /&gt;
&lt;br /&gt;
'''3.2. Phase 1: Before Development Begins '''&lt;br /&gt;
&lt;br /&gt;
'''3.3. Phase 2: During Definition and Design'''&lt;br /&gt;
&lt;br /&gt;
'''3.4. Phase 3: During Development'''&lt;br /&gt;
&lt;br /&gt;
'''3.5. Phase 4: During Deployment'''&lt;br /&gt;
&lt;br /&gt;
'''3.6. Phase 5: Maintenance and Operations'''&lt;br /&gt;
&lt;br /&gt;
'''3.7. A Typical SDLC Testing Workflow '''&lt;br /&gt;
&lt;br /&gt;
==[[Web Application Penetration Testing |4. Web Application Penetration Testing ]]==&lt;br /&gt;
&lt;br /&gt;
[[Testing: Introduction and objectives|'''4.1 Introduction and Objectives''']] [To review--&amp;gt; Mat]&lt;br /&gt;
&lt;br /&gt;
[[Testing Checklist| 4.1.1 Testing Checklist]] [To review at the end of brainstorming --&amp;gt; Mat]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Testing: Information Gathering|'''4.2 Information Gathering ''']] [To review--&amp;gt; contributor here]&lt;br /&gt;
&lt;br /&gt;
[[Testing: Spiders, Robots, and Crawlers (OWASP-IG-001)|4.2.1 Spiders, Robots and Crawlers (OWASP-IG-001)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing: Search engine discovery/reconnaissance (OWASP-IG-002)|4.2.2 Search Engine Discovery/Reconnaissance (OWASP-IG-002)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing: Identify application entry points (OWASP-IG-003)|4.2.3 Identify application entry points (OWASP-IG-003)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Web Application Fingerprint (OWASP-IG-004)|4.2.4 Testing for Web Application Fingerprint (OWASP-IG-004)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Application Discovery (OWASP-IG-005)|4.2.5 Application Discovery (OWASP-IG-005)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Error Code (OWASP-IG-006)|4.2.6 Analysis of Error Codes (OWASP-IG-006)]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Testing for configuration management|'''4.3 Configuration and Deploy Management Testing ''']]&lt;br /&gt;
&lt;br /&gt;
[[Testing for infrastructure configuration management (OWASP-CM-003)|4.3.1 Testing for Infrastructure Configuration Management Testing weakness (OWASP-CM-001)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for application configuration management (OWASP-CM-004)|4.3.2 Testing for Application Configuration Management weakness (OWASP-CM-002)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for file extensions handling  (OWASP-CM-005)|4.3.3 Testing for File Extensions Handling  (OWASP-CM-003)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Old, Backup and Unreferenced Files (OWASP-CM-006)|4.3.4 Old, Backup and Unreferenced Files (OWASP-CM-004) ]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Admin Interfaces  (OWASP-CM-007)|4.3.5 Infrastructure and Application Admin Interfaces  (OWASP-CM-005)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for HTTP Methods and XST  (OWASP-CM-008)|4.3.6 Testing for Bad HTTP Methods (OWASP-CM-006)]][new - Abian Blome]&lt;br /&gt;
&lt;br /&gt;
&amp;gt; Informative Error Messages [MAT NOTE: in info gathering]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Database credentials/connection strings available|4.3.7 Testing for Database credentials/connection strings available (OWASP-CM-007)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Content Security Policy weakness|4.3.8 Testing for Content Security Policy weakness (OWASP-CM-008)]][New! - Simone Onofri]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Missing HSTS header|4.3.9 Testing for Missing HSTS header (OWASP-CM-009)]][New! Juan Manuel Bahamonde ]&lt;br /&gt;
&lt;br /&gt;
[[Testing for RIA policy files weakness|4.3.10 Testing for RIA policy files weakness (OWASP-CM-010)]] [New!]&lt;br /&gt;
&lt;br /&gt;
&amp;gt; Incorrect time[New! MAT NOTE: explain the test in detail please]&lt;br /&gt;
&lt;br /&gt;
&amp;gt; Unpatched components and libraries (e.g. JavaScript libraries)[New! NOTE: tu discuss it]&lt;br /&gt;
&lt;br /&gt;
&amp;gt; Test data in production systems (and vice versa)[New! MAT NOTE: this is not a particular test that could find a vulnerability]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Testing for authentication|'''4.4 Authentication Testing ''']] &lt;br /&gt;
&lt;br /&gt;
[[Testing for Credentials Transported over an Encrypted Channel (OWASP-AT-001)|4.4.1 Testing for Credentials Transported over an Encrypted Channel  (OWASP-AT-001)]] [Robert Winkel]&lt;br /&gt;
&lt;br /&gt;
[[Testing for User Enumeration and Guessable User Account (OWASP-AT-002)|4.4.2 Testing for User Enumeration and Guessable User Account  (OWASP-AT-002)]] [Robert Winkel]&lt;br /&gt;
&lt;br /&gt;
[[Testing for default credentials (OWASP-AT-003)|4.4.3 Testing for default credentials (OWASP-AT-003)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Weak lock out mechanism (OWASP-AT-004)|4.4.4 Testing for Weak lock out mechanism (OWASP-AT-004)]] [New! - Robert Winkel] &lt;br /&gt;
&lt;br /&gt;
&amp;gt; Account lockout DoS [New! - Robert Winkel - we can put it in the 4.4.4]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Bypassing Authentication Schema (OWASP-AT-005)|4.4.5 Testing for bypassing authentication schema (OWASP-AT-005)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Vulnerable Remember Password (OWASP-AT-006)|4.4.6 Testing for vulnerable remember &lt;br /&gt;
password functionality (OWASP-AT-006)]] [Robert Winkel]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Browser cache weakness (OWASP-AT-007)|4.4.7 Testing for Browser cache weakness (OWASP-AT-007)]] [New! - Abian Blome]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Weak password policy (OWASP-AT-008)|4.4.8 Testing for Weak password policy (OWASP-AT-008)]] [New! - Robert Winkel]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Weak or unenforced username policy (OWASP-AT-009)|4.4.9 Testing for Weak or unenforced username policy (OWASP-AT-009)]] [New! - Robert Winkel]&lt;br /&gt;
&lt;br /&gt;
&amp;gt; Weak security question/answer [New! - Robert Winkel - MAT Note: same as AT-006]&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
[[Testing for failure to restrict access to authenticated resource(OWASP-AT-010)|4.4.10 Testing for failure to restrict access to authenticated resource (OWASP-AT-010)]] [New!]&amp;lt;br&amp;gt; &lt;br /&gt;
&lt;br /&gt;
[[Testing for weak password change or reset functionalities (OWASP-AT-011)|4.4.11 Testing for weak password change or reset functionalities (OWASP-AT-011)]] [New! - Robert Winkel]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Captcha (OWASP-AT-012)|4.4.12 Testing for CAPTCHA (OWASP-AT-012)]]&lt;br /&gt;
&lt;br /&gt;
&amp;gt; Weaker authentication in alternative channel (e.g. mobile app, IVR, help desk) [New!: MAT Note: to explain better the kind of test to perform please]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Testing for Session Management|'''4.5 Session Management Testing''']] &lt;br /&gt;
&lt;br /&gt;
[[Testing for Session_Management_Schema (OWASP-SM-001)|4.5.1 Testing for Bypassing Session Management Schema (OWASP-SM-001)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for cookies attributes  (OWASP-SM-002)|4.5.2 Testing for Cookies attributes (Cookies are set not ‘HTTP Only’, ‘Secure’,  and no time validity) (OWASP-SM-002)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Session Fixation  (OWASP-SM-003)|4.5.3 Testing for Session Fixation  (OWASP-SM-003)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Exposed Session Variables  (OWASP-SM-004)|4.5.4 Testing for Exposed Session Variables   (OWASP-SM-004)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for CSRF  (OWASP-SM-005)|4.5.5 Testing for Cross Site Request Forgery (CSRF)  (OWASP-SM-005)]]&lt;br /&gt;
&lt;br /&gt;
&amp;gt; Weak Session Token (MAT NOTE included in 4.5.1)&lt;br /&gt;
 &lt;br /&gt;
[[Testing for Session token not restricted properly (OWASP-SM-006)|4.5.6 Testing for Session token not restricted properly (such as domain or path not set properly) (OWASP-SM-006)]] [New! - Abian Blome]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;gt; Session passed over http (NOTE: included in SM-004) [New!] &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Testing for logout functionality (OWASP-SM-007)|4.5.7 Testing for logout functionality (OWASP-SM-007)]]&lt;br /&gt;
&lt;br /&gt;
&amp;gt;Session token not removed on server after logout [New!: NOTE included in the above test]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;gt; Logout function not properly implemented (NOTE:same above)&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;gt; Persistent session token [New! NOTE: this is not a vulnerability if session time out is correctly performed]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Session puzzling (OWASP-SM-008)|4.5.8 Testing for Session puzzling (OWASP-SM-008)]] [New! - Abian Blome]&lt;br /&gt;
&lt;br /&gt;
&amp;gt; Missing user-viewable log of authentication events [NOTE: needs more details: which test perform?]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Testing for Authorization|'''4.6 Authorization Testing''']] &lt;br /&gt;
&lt;br /&gt;
[[Testing for Path Traversal  (OWASP-AZ-001)|4.6.1 Testing Directory traversal/file include (OWASP-AZ-001) [Juan Galiana] ]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Bypassing Authorization Schema  (OWASP-AZ-002)|4.6.2 Testing for bypassing authorization schema  (OWASP-AZ-002)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Privilege escalation  (OWASP-AZ-003)|4.6.3 Testing for Privilege Escalation  (OWASP-AZ-003) [Irene Abezgauz]]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Insecure Direct Object References (OWASP-AZ-004)|4.6.4 Testing for Insecure Direct Object References (OWASP-AZ-004) [Irene Abezgauz] ]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Failure to Restrict access to authorized resource (OWASP-AZ-005)|4.6.5 Testing for Failure to Restrict access to authorized resource (OWASP-AZ-005) [New!] ]]&lt;br /&gt;
&lt;br /&gt;
&amp;gt; Server component has excessive privileges (e.g. indexing service, reporting interface, file generator)[New!]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;gt; Lack of enforcement of application entry points (including exposure of objects)[New!]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Testing for business logic   (OWASP-BL-001)|'''4.7 Business Logic Testing  (OWASP-BL-001)''']] [To review--&amp;gt; contributor here]&lt;br /&gt;
Business Logic&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Business logic data validation[New!] NOTE MAT: to discuss this section&amp;lt;br&amp;gt;&lt;br /&gt;
Ability to forge requests[New!]&amp;lt;br&amp;gt;&lt;br /&gt;
Lack of integrity checks (e.g. overwriting updates) [New!]&amp;lt;br&amp;gt;&lt;br /&gt;
Lack of tamper evidence[New!]&amp;lt;br&amp;gt;&lt;br /&gt;
Use of untrusted time source[New!]&amp;lt;br&amp;gt;&lt;br /&gt;
Lack of limits to excessive rate (speed) of use[New!]&amp;lt;br&amp;gt;&lt;br /&gt;
Lack of limits to size of request[New!]&amp;lt;br&amp;gt;&lt;br /&gt;
Lack of limit to number of times a function can be used[New!]&amp;lt;br&amp;gt;&lt;br /&gt;
Bypass of correct sequence[New!]&amp;lt;br&amp;gt;&lt;br /&gt;
Missing user-viewable log of actvity[New!]&amp;lt;br&amp;gt;&lt;br /&gt;
Self-hosted payment cardholder data processing[New!]&amp;lt;br&amp;gt;&lt;br /&gt;
Lack of security incident reporting information[New!]&amp;lt;br&amp;gt;&lt;br /&gt;
Defenses against application mis-use[New!]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Testing for Data Validation|'''4.8 Data Validation Testing''']] &lt;br /&gt;
&lt;br /&gt;
[[Testing for Reflected Cross site scripting (OWASP-DV-001) |4.8.1 Testing for Reflected Cross Site Scripting (OWASP-DV-001) ]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Stored Cross site scripting (OWASP-DV-002) |4.8.2 Testing for Stored Cross Site Scripting (OWASP-DV-002) ]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for HTTP Verb Tampering (OWASP-DV-003)|4.8.3 Testing for HTTP Verb Tampering   [Brad Causey] ]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for HTTP Parameter pollution (OWASP-DV-004)|4.8.4 Testing for HTTP Parameter pollution [Luca Carettoni, Stefano Di Paola, Brad Causey] ]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Unvalidated Redirects and Forwards (OWASP-DV-004)|4.8.5 Testing for Unvalidated Redirects and Forwards [Brad Causey] ]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for SQL Injection (OWASP-DV-005)| 4.8.5 Testing for SQL Injection (OWASP-DV-005) Ismael Gonçalves]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Oracle|4.8.5.1 Oracle Testing]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for MySQL|4.8.5.2 MySQL Testing]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for SQL Server|4.8.5.3 SQL Server Testing]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for MS Access |4.8.5.4 MS Access Testing]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for NoSQL injection|4.8.5.5 Testing for NoSQL injection [New!]]]&lt;br /&gt;
&lt;br /&gt;
[[OWASP_Backend_Security_Project_Testing_PostgreSQL|4.8.5.5 Testing PostgreSQL (from OWASP BSP) ]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for LDAP Injection  (OWASP-DV-006)|4.8.6 Testing for LDAP Injection  (OWASP-DV-006)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for ORM Injection   (OWASP-DV-007)|4.8.7 Testing for ORM Injection   (OWASP-DV-007)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for XML Injection (OWASP-DV-008)|4.8.8 Testing for XML Injection (OWASP-DV-008)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for SSI Injection  (OWASP-DV-009)|4.8.9 Testing for SSI Injection  (OWASP-DV-009)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for XPath Injection  (OWASP-DV-010)|4.8.10 Testing for XPath Injection  (OWASP-DV-010)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for IMAP/SMTP Injection  (OWASP-DV-011)|4.8.11 IMAP/SMTP Injection  (OWASP-DV-011)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Code Injection  (OWASP-DV-012)|4.8.12 Testing for Code Injection  (OWASP-DV-012)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Command Injection   (OWASP-DV-013)|4.8.13 Testing for Command Injection   (OWASP-DV-013) [Juan Galiana]]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Buffer Overflow (OWASP-DV-014)|4.8.14 Testing for Buffer overflow (OWASP-DV-014)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Heap Overflow|4.8.14.1 Testing for Heap overflow]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Stack Overflow|4.8.14.2 Testing for Stack overflow]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Format String|4.8.14.3 Testing for Format string]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Incubated Vulnerability (OWASP-DV-015)|4.8.15 Testing for incubated vulnerabilities (OWASP-DV-015)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for HTTP Splitting/Smuggling  (OWASP-DV-016)|4.8.16 Testing for HTTP Splitting/Smuggling  (OWASP-DV-016) [Juan Galiana] ]]&lt;br /&gt;
&lt;br /&gt;
&amp;gt; Regular expression DoS[New!] note: to understand better&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Data Encryption (New!)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Insecure encryption usage (OWASP-EN-001)| 4.9.1  Testing for Insecure encryption usage (OWASP-EN-001]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Weak SSL/TSL Ciphers, Insufficient Transport Layer Protection (OWASP-EN-002)| 4.9.2 Testing for Weak SSL/TSL Ciphers, Insufficient Transport Layer Protection (OWASP-EN-002)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Padding Oracle (OWASP-EN-003)| 4.9.3 Testing for Padding Oracle (OWASP-EN-003) [Giorgio Fedon]]]&lt;br /&gt;
&lt;br /&gt;
&amp;gt; [[Testing for Cacheable HTTPS Response | x.x.3 Testing for Cacheable HTTPS Response&amp;lt;br&amp;gt;&lt;br /&gt;
Cache directives insecure&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;gt; Testing for Insecure Cryptographic Storage [put in x.x.1]&amp;lt;br&amp;gt;&lt;br /&gt;
[[Testing for Sensitive information sent via unencrypted channels | x.x.4&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Web Service (XML Interpreter)|'''4.10 Web Service Testing''']] [Tom Eston] &lt;br /&gt;
&lt;br /&gt;
[[Scoping a Web Service Test (OWASP-WS-001)|4.10.1 Scoping a Web Service Test (OWASP-WS-001)]]&lt;br /&gt;
&lt;br /&gt;
[[WS Information Gathering (OWASP-WS-002)|4.10.2 WS Information Gathering (OWASP-WS-002)]]&lt;br /&gt;
&lt;br /&gt;
[[WS Authentication Testing (OWASP-WS-003)|4.10.3 WS Authentication Testing (OWASP-WS-003)]]&lt;br /&gt;
&lt;br /&gt;
[[WS Management Interface Testing (OWASP-WS-004)|4.10.4 WS Management Interface Testing (OWASP-WS-004)]]&lt;br /&gt;
&lt;br /&gt;
[[Weak XML Structure Testing (OWASP-WS-005)|4.10.5 Weak XML Structure Testing (OWASP-WS-005)]]&lt;br /&gt;
&lt;br /&gt;
[[XML Content-Level Testing (OWASP-WS-006)|4.10.6 XML Content-Level Testing (OWASP-WS-006)]]&lt;br /&gt;
&lt;br /&gt;
[[WS HTTP GET Parameters/REST Testing (OWASP-WS-007)|4.10.7 WS HTTP GET Parameters/REST Testing (OWASP-WS-007)]]&lt;br /&gt;
&lt;br /&gt;
[[WS Naughty SOAP Attachment Testing (OWASP-WS-008)|4.10.8 WS Naughty SOAP Attachment Testing (OWASP-WS-008)]]&lt;br /&gt;
&lt;br /&gt;
[[WS Replay/MiTM Testing (OWASP-WS-009)|4.10.9 WS Replay/MiTM Testing (OWASP-WS-009)]]&lt;br /&gt;
&lt;br /&gt;
[[WS BEPL Testing (OWASP-WS-010)|4.10.10 WS BEPL Testing (OWASP-WS-010)]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Client Side Testing|'''4.11 Client Side Testing''']] [New!] &lt;br /&gt;
&lt;br /&gt;
[[Testing for DOM-based Cross site scripting  (OWASP-DV-003)|4.11.1 Testing for DOM based Cross Site Scripting  (OWASP-CS-001) [Stefano Di Paola]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for HTML5 (OWASP CS-002)|4.11.2 Testing for HTML5 (OWASP CS-002) [Juan Galiana] ]]&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Testing for Cross site flashing (OWASP-DV-004)|4.11.3 Testing for Cross Site Flashing   (OWASP-CS-003)]]&lt;br /&gt;
&lt;br /&gt;
[[Testing for Testing for ClickHijacking (OWASP-CS-004)|4.11.4 Testing for Testing for ClickHijacking (OWASP-CS-004) ]]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==[[Writing Reports: value the real risk |5. Writing Reports: value the real risk ]]==&lt;br /&gt;
&lt;br /&gt;
[[How to value the real risk |5.1 How to value the real risk]] [To review--&amp;gt; contributor here]&lt;br /&gt;
&lt;br /&gt;
[[How to write the report of the testing |5.2 How to write the report of the testing]] [To review--&amp;gt; contributor here]&lt;br /&gt;
&lt;br /&gt;
==[[Appendix A: Testing Tools |Appendix A: Testing Tools ]]==&lt;br /&gt;
&lt;br /&gt;
* Black Box Testing Tools [To review--&amp;gt; Amro. We need only tools fo webapp testing]&lt;br /&gt;
&lt;br /&gt;
==[[OWASP Testing Guide Appendix B: Suggested Reading | Appendix B: Suggested Reading]]==&lt;br /&gt;
* Whitepapers [To review--&amp;gt; David Fern]&lt;br /&gt;
* Books [To review--&amp;gt; David Fern]&lt;br /&gt;
* Useful Websites [To review--&amp;gt; David Fern]&lt;br /&gt;
&lt;br /&gt;
==[[OWASP Testing Guide Appendix C: Fuzz Vectors | Appendix C: Fuzz Vectors]]==&lt;br /&gt;
&lt;br /&gt;
* Fuzz Categories [To review--&amp;gt; contributor here]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==[[OWASP Testing Guide Appendix D: Encoded Injection | Appendix D: Encoded Injection]]==&lt;br /&gt;
&lt;br /&gt;
[To review--&amp;gt; contributor here]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:OWASP Testing Project]]&lt;/div&gt;</summary>
		<author><name>Dimisec</name></author>	</entry>

	</feed>