29
loading...
This website collects cookies to deliver better user experience
<div class="comment">
<script>alert("HAXXED")</script>
</div>
const data = {
comment: "Hi, there <script>console.log('you are hacked')</script>"
}
console.log(encodeURI(data.comment)); // => Hi,%20there%20%3Cscript%3Econsole.log('you%20are%20hacked')%3C/script%3E
return <div dangerouslySetInnerHTML={createMarkup()} />;
<div [innerHTML]='<a href="#">Unescaped link</a>'</div>
<div v-html="htmlData"></div>
v-html
it does not execute. Measures may be already taken by these frameworks, but be careful, there may be still some exceptions, make sure you read the security recommendation provided in the documentation. encodeForHTML
, encodeForCSS
, encodeForJS
, encodeForURL
, encodeForHTMLAttribute
etc.<html>
tag of a web page (known as inline script). CSP tells the browser to never execute inline scripts unless it is imported via src
attribute in the <script>
tag. Content-Security-Policy: script-src 'self' https://api.foo.com
<meta>
tag in the <head>
element of the HTML.<meta http-equiv="Content-Security-Policy" content="script-src 'self' https://api.foo.com">
api.foo.com
even if say the website's domain is https://foowebsite.com
.unsafe-inline
.Content-Security-Policy: script-src 'unsafe-inline';
inline-script
like google tag manager and still want to block any other suspicious inline scripts being added, cryptographic nonce
can be added<script nonce=E9h3sdfn3f03nce9DNnIOefn3fa>
(function googleTagFunction(){....})();
!</script>
Content-Security-Policy: script-src 'nonce-E9h3sdfn3f03nce9DNnIOefn3fa'
unsafe-inline
read #unsafe inline script documentation. report-uri
directive ( multiple directives are separated by semi-colon) and include a URI where the report should be sent.Content-Security-Policy: default-src 'self'; report-uri http://reportcollector.example.com/collector.cgi
Content-Security-Policy-Report-Only: default-src 'self'; report-uri http://reportcollector.example.com/collector.cgi