简体   繁体   中英

Refused to execute inline script because it violates the following Content Security Policy directive: "default-src 'self'"

My Html file looks like below. When I launch the HTML file it says, content security policy is broken. How do I fix it from the HTML side?

<html>

<head>

  <title></title>
</head>
<script type="text/javascript" src="URLCode.js"></script>

<body onload='window.location.replace(URLalter(window.location.href));'>
</body>

</html>

Js code:

function URLalter(entryURL) {
  var entryPoint= entryURL+" ";
  return entryPoint;
}

How do I fix it from the HTML side?

Easy answer, you don't. The server is most definitely responsible for this and with good reason but let's say those reasons are simply security. You may bypass this by adjusting your headers but it will not be done on a client level side at all!

That's bad.

You can maybe get comfortable with these security features often applied and understand the different headers/measures taken: contentSecurityPolicy, dnsPrefetchControl, expectCt, frameguard, hidePoweredBy, hsts, ieNoOpen, noSniff, permittedCrossDomainPolicies, referrerPolicy, and xssFilter

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

Related Question Refused to load the font '<URL>' because it violates the following Content Security Policy directive default-src ,so default-src is used as a fallback Javascript throwing : Refused to execute inline event handler because it violates the following Content Security Policy directive: "script-src 'self' Refused to load the script because it violates the following Content Security Policy directive: "style-src 'self' 'unsafe-inline' Inline script because it violates the following Content Security Policy directive: “script-src 'self'” Cordova error: Refused to execute inline script because it violates the following Content Security Policy directive Refused to execute inline script because it violates the following Content Security Policy directive Firebase Chrome Extension - Refused to execute inline script because it violates the following Content Security Policy directive Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script Content Security Policy directive:default-src self Refused to load the font 'data:font/woff.....'it violates the following Content Security Policy directive: "default-src 'self'". Note that 'font-src' Chrome extension policy error: Refused to execute inline event handler because it violates the following Content Security Policy directive
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM