Aónio
Aónio

Reputation: 579

How to use nonce in CSP

I've been reading the CSP documentation regarding using inline scripts with nonce (Number used only once), but I still don't get it fully.

HTTP layer:

Content-Security-Policy: script-src 'nonce-2726c7f26c'

Javascript inlined in HTML

<script nonce="2726c7f26c">
  var inline = 1;
</script>
<script nonce="2726c7f26c">
  var inline2 = 2;
</script>

Upvotes: 13

Views: 8554

Answers (1)

A&#243;nio
A&#243;nio

Reputation: 579

My solution was correct

We create one nonce per HTTP request, we should not create one per script. So, my initial solution was correct. The CSP rules go into the HTTP layer, and thus one nonce per HTTP request.

Upvotes: 24

Related Questions