From 6b51c7e384fd8471c5dbdc83c6cef1cb6ec1271f Mon Sep 17 00:00:00 2001 From: John Peter Date: Tue, 29 Mar 2022 13:29:48 +0530 Subject: [PATCH 1/2] Adding nonce support to postcribe --- src/write-stream.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/write-stream.js b/src/write-stream.js index 4e84dd6d..576d4c3c 100644 --- a/src/write-stream.js +++ b/src/write-stream.js @@ -377,6 +377,17 @@ export default class WriteStream { } } + /** + * Sets nonce to scripts and style tags that are generated to support CSP + * + * @param {HTMLElement} el The script/ style tag to be associated with nonce + */ + _setNonce(el) { + if (this.options.nonce) { + el.nonce = this.options.nonce; + } + } + /** * Build a style and insert it into the DOM. * @@ -384,7 +395,7 @@ export default class WriteStream { */ _writeStyleToken(tok) { const el = this._buildStyle(tok); - + this._setNonce(el); this._insertCursor(el, PROXY_STYLE); // Set content @@ -485,7 +496,7 @@ export default class WriteStream { const el = this._buildScript(tok); const asyncRelease = this._shouldRelease(el); const afterAsync = this.options.afterAsync; - + this._setNonce(el); if (tok.src) { // Fix for attribute "SRC" (capitalized). IE does not recognize it. el.src = tok.src; From 149147469eea1f9200a2d9a9bc06832c0b0bfdc7 Mon Sep 17 00:00:00 2001 From: John Peter Date: Wed, 30 Mar 2022 10:23:20 +0530 Subject: [PATCH 2/2] minor space changes --- src/write-stream.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/write-stream.js b/src/write-stream.js index 576d4c3c..6779a0a6 100644 --- a/src/write-stream.js +++ b/src/write-stream.js @@ -380,7 +380,7 @@ export default class WriteStream { /** * Sets nonce to scripts and style tags that are generated to support CSP * - * @param {HTMLElement} el The script/ style tag to be associated with nonce + * @param {HTMLElement} el The script/style tag to be associated with nonce */ _setNonce(el) { if (this.options.nonce) {