Skip to content

Commit ae7cb11

Browse files
authored
Merge pull request #114 from kumarrishav/patch-1
Add style/script directive if nonce is true
2 parents 61387e9 + 539f01c commit ae7cb11

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
##### v1.5.2
2+
3+
* Bugfix: Add style/script directive if nonce is true
4+
15
##### v1.5.1
26

37
* Bugfix: style-src nonce updates properly, speed improvement on match

lib/csp.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ module.exports = function (options) {
1919
name += '-report-only';
2020
}
2121

22+
if (policyRules && policyRules["default-src"]) {
23+
if (styleNonce && !policyRules["style-src"]) {
24+
policyRules["style-src"] = policyRules["default-src"];
25+
}
26+
27+
if (scriptNonce && !policyRules["script-src"]) {
28+
policyRules["script-src"] = policyRules["default-src"];
29+
}
30+
}
31+
2232
value = createPolicyString(policyRules);
2333

2434
if (reportUri) {

0 commit comments

Comments
 (0)