Skip to content

Commit

Permalink
fix: disable nonce creation by default
Browse files Browse the repository at this point in the history
As the nonce should be unique per request, it doesn't make sense to
enable this by default, as that requires additional work on the serving
side.

On the other side, having a (static) random value isn't correct either.

So we keep the current logic, but disable nonce generation by default,
making it opt-in.

Closes #941
  • Loading branch information
ctron committed Jan 21, 2025
1 parent 16cf708 commit da15f3f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
2 changes: 2 additions & 0 deletions Trunk.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ minify = "never" # can be one of: never, on_release, always
no_sri = false
# An optional cargo profile to use
# cargo_profile = "release-trunk"
# Allow injecting a nonce attribute
create_nonce = false

[watch]
# Paths to watch. The `build.target`'s parent folder is watched by default.
Expand Down
4 changes: 2 additions & 2 deletions schemas/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"all_features": false,
"allow_self_closing_script": false,
"cargo_profile": null,
"create_nonce": true,
"create_nonce": false,
"dist": "dist",
"filehash": true,
"frozen": false,
Expand Down Expand Up @@ -120,7 +120,7 @@
},
"create_nonce": {
"description": "Create 'nonce' attributes with a placeholder.",
"default": true,
"default": false,
"type": "boolean"
},
"dist": {
Expand Down
8 changes: 2 additions & 6 deletions src/config/models/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ pub struct Build {
pub allow_self_closing_script: bool,

/// Create 'nonce' attributes with a placeholder.
#[serde(default = "default::create_nonce")]
#[serde(default)]
pub create_nonce: bool,

/// The placeholder which is used in the 'nonce' attribute.
Expand Down Expand Up @@ -230,7 +230,7 @@ impl Default for Build {
minify: Default::default(),
no_sri: false,
allow_self_closing_script: false,
create_nonce: true,
create_nonce: false,
nonce_placeholder: default::nonce_placeholder(),
}
}
Expand All @@ -256,10 +256,6 @@ mod default {
true
}

pub const fn create_nonce() -> bool {
true
}

pub fn nonce_placeholder() -> String {
"{{__TRUNK NONCE__}}".to_string()
}
Expand Down

0 comments on commit da15f3f

Please sign in to comment.