From bd2f2ae56c4beb744a231235403e9492c002e720 Mon Sep 17 00:00:00 2001 From: Tobias Sorn Date: Wed, 20 May 2020 17:33:32 +0200 Subject: [PATCH] Add cspReportPath parameter such that it can be set from the outside when serving --- lib/middleware/MiddlewareManager.js | 5 +++++ lib/server.js | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/middleware/MiddlewareManager.js b/lib/middleware/MiddlewareManager.js index 537d70fd..5586c1d5 100644 --- a/lib/middleware/MiddlewareManager.js +++ b/lib/middleware/MiddlewareManager.js @@ -118,6 +118,11 @@ class MiddlewareManager { defaultPolicy2IsReportOnly: true, }); } + if (this.options.cspReportPath) { + Object.assign(oCspConfig, { + cspReportPath: this.options.cspReportPath + }); + } return () => { return cspModule("sap-ui-xx-csp-policy", oCspConfig); }; diff --git a/lib/server.js b/lib/server.js index 8cf1b0f4..1d2cd61a 100644 --- a/lib/server.js +++ b/lib/server.js @@ -111,6 +111,7 @@ module.exports = { * aim for (AKA 'target policies'), are send for any requested * *.html file * @param {boolean} [options.simpleIndex=false] Use a simplified view for the server directory listing + * @param {string} [options.cspReportPath] Enable csp report logging to the given path * @returns {Promise} Promise resolving once the server is listening. * It resolves with an object containing the port, * h2-flag and a close function, @@ -118,7 +119,7 @@ module.exports = { */ async serve(tree, { port: requestedPort, changePortIfInUse = false, h2 = false, key, cert, - acceptRemoteConnections = false, sendSAPTargetCSP = false, simpleIndex = false + acceptRemoteConnections = false, sendSAPTargetCSP = false, simpleIndex = false, cspReportPath }) { const projectResourceCollections = resourceFactory.createCollectionsForTree(tree); @@ -140,6 +141,7 @@ module.exports = { resources, options: { sendSAPTargetCSP, + cspReportPath, simpleIndex } });