I have implemented a nonce for a csp inline js. Struggling with finding why it doesn't work. When accessing a page get this error:
Content Security Policy: The page's settings blocked the loading of a resource at https://loca.../script.js ("script-src").
Content Security Policy: The page's settings blocked the loading of a resource at inline ("script-src").
Implempleted to flask: // Inside timer.py file implemented a function to create nonce.
def GetCspNonce():
"""Returns a random nonce."""
NONCE_LENGTH = 16
return base64.b64encode(os.urandom(NONCE_LENGTH))
nonce = GetCspNonce()
function to redirect to a template:
return render_template('base/timer.html', timer= timer, nonce=nonce)
// Added to init.py csp nonce.
def create_app():
# create and configure the app
....
csp = {
'default-src': ['\'self\''],
'script-src': ['https://www.goog....], 'nonce-{nonce}'],...
//timer.html
<td>
<p> ...</p>
<script type="text/javascript" src="../static/text/script.js" nonce="{nonce}"></script>
</td>