Skip to content

Commit da15f3f

Browse files
committed
fix: disable nonce creation by default
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
1 parent 16cf708 commit da15f3f

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

Trunk.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ minify = "never" # can be one of: never, on_release, always
3030
no_sri = false
3131
# An optional cargo profile to use
3232
# cargo_profile = "release-trunk"
33+
# Allow injecting a nonce attribute
34+
create_nonce = false
3335

3436
[watch]
3537
# Paths to watch. The `build.target`'s parent folder is watched by default.

schemas/config.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"all_features": false,
1111
"allow_self_closing_script": false,
1212
"cargo_profile": null,
13-
"create_nonce": true,
13+
"create_nonce": false,
1414
"dist": "dist",
1515
"filehash": true,
1616
"frozen": false,
@@ -120,7 +120,7 @@
120120
},
121121
"create_nonce": {
122122
"description": "Create 'nonce' attributes with a placeholder.",
123-
"default": true,
123+
"default": false,
124124
"type": "boolean"
125125
},
126126
"dist": {

src/config/models/build.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ pub struct Build {
153153
pub allow_self_closing_script: bool,
154154

155155
/// Create 'nonce' attributes with a placeholder.
156-
#[serde(default = "default::create_nonce")]
156+
#[serde(default)]
157157
pub create_nonce: bool,
158158

159159
/// The placeholder which is used in the 'nonce' attribute.
@@ -230,7 +230,7 @@ impl Default for Build {
230230
minify: Default::default(),
231231
no_sri: false,
232232
allow_self_closing_script: false,
233-
create_nonce: true,
233+
create_nonce: false,
234234
nonce_placeholder: default::nonce_placeholder(),
235235
}
236236
}
@@ -256,10 +256,6 @@ mod default {
256256
true
257257
}
258258

259-
pub const fn create_nonce() -> bool {
260-
true
261-
}
262-
263259
pub fn nonce_placeholder() -> String {
264260
"{{__TRUNK NONCE__}}".to_string()
265261
}

0 commit comments

Comments
 (0)