Skip to content

Commit

Permalink
add another comment about random nonces
Browse files Browse the repository at this point in the history
  • Loading branch information
pietroalbini committed Apr 8, 2021
1 parent 8cb95d2 commit 022fdbd
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/web/csp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ pub(super) struct Csp {

impl Csp {
fn new() -> Self {
// Nonces need to be different for each single request in order to maintain security, so we
// generate a new one with a cryptographically-secure generator for each request.
let mut random = [0u8; 36];
getrandom::getrandom(&mut random).expect("failed to generate a nonce");

Self {
nonce: base64::encode(&random),
suppress: false,
Expand Down

0 comments on commit 022fdbd

Please sign in to comment.