files/en-us/web/http/reference/headers/content-security-policy/script-src-attr/index.md
The HTTP {{HTTPHeader("Content-Security-Policy")}} (CSP) script-src-attr directive specifies valid sources for JavaScript inline event handlers.
This directive only specifies valid sources for inline script event handlers like onclick.
It does not apply to other JavaScript sources that can trigger script execution, such as URLs loaded directly into {{HTMLElement("script")}} elements and XSLT stylesheets.
(Valid sources can be specified for all JavaScript script sources using {{CSP("script-src")}}, or just for <script> elements using {{CSP("script-src-elem")}}.)
Content-Security-Policy: script-src-attr 'none';
Content-Security-Policy: script-src-attr <source-expression-list>;
This directive may have one of the following values:
'none'
<source-expression-list>
script-src-attr can be used in conjunction with {{CSP("script-src")}}, and will override that directive for checks on inline handlers:
Content-Security-Policy: script-src <source>;
Content-Security-Policy: script-src-attr <source>;
Given this CSP header:
Content-Security-Policy: script-src-attr 'none'
…the following inline event handler is blocked and won't be loaded or executed:
<button id="btn" onclick="doSomething()">Click me</button>
Note that generally you should replace inline event handlers with {{domxref("EventTarget.addEventListener", "addEventListener")}} calls:
document.getElementById("btn").addEventListener("click", doSomething);
{{Specifications}}
{{Compat}}