diff --git a/Framework/Backend/http/server.js b/Framework/Backend/http/server.js index f55090bb8..54cbd06d4 100644 --- a/Framework/Backend/http/server.js +++ b/Framework/Backend/http/server.js @@ -146,9 +146,10 @@ class HttpServer { * @param {number} config.port secure port number * @param {list} config.iframeCsp list of URLs for frame-src CSP * @param {boolean} config.allow allow unsafe-eval in CSP - * @param {boolean} config.allowIframeCsp allow iframe embedding from given URLs + * @param {boolean} config.allowIframeCsp allow blob: URLs in img-src (image previews/downloads) + * @param {list} [config.extraConnectSrc] sources appended to the default connect-src CSP */ - configureHelmet({ hostname, port, iframeCsp = [], allow = false, allowIframeCsp = false }) { + configureHelmet({ hostname, port, iframeCsp = [], allow = false, allowIframeCsp = false, extraConnectSrc = [] }) { // Sets "X-Frame-Options: DENY" (doesn't allow to be in any iframe) this.app.use(helmet.frameguard({ action: 'deny' })); // Sets "Strict-Transport-Security: max-age=5184000 (60 days) (stick to HTTPS) @@ -171,7 +172,8 @@ class HttpServer { ...(allowIframeCsp && { imgSrc: ["'self'", "data:", "blob:"] }), scriptSrc: ["'self'", ...(allow ? ["'unsafe-eval'"] : [])], styleSrc: ["'self'", "'unsafe-inline'"], - connectSrc: ["'self'", 'http://' + hostname + ':' + port, 'https://' + hostname, 'wss://' + hostname, 'ws://' + hostname + ':' + port], + connectSrc: ["'self'", 'http://' + hostname + ':' + port, 'https://' + hostname, 'wss://' + hostname, 'ws://' + hostname + ':' + port, + ...extraConnectSrc], upgradeInsecureRequests: null, frameSrc: iframeCsp /* eslint-enable */ diff --git a/Framework/docs/guide/http-server.md b/Framework/docs/guide/http-server.md index b8bed2252..ea5abfd7e 100644 --- a/Framework/docs/guide/http-server.md +++ b/Framework/docs/guide/http-server.md @@ -21,6 +21,10 @@ Where: * [`TLS_CERT`] - certificate filepath, TLS must be enabled * [`AUTO_LISTEN`] - flag that enables/disables automatic listening (default: `true`) * [`LIMIT`] - controls the maximum request body size. Defaults to '100kb'. + * [`iframeCsp`] - list of URLs allowed in the `frame-src` CSP directive (default: `[]`) + * [`allow`] - adds `'unsafe-eval'` to `script-src` (default: `false`) + * [`allowIframeCsp`] - adds `blob:` to `img-src` so blob-based images can be previewed/downloaded; despite the name, unrelated to iframes (default: `false`) + * [`extraConnectSrc`] - sources appended to the default `connect-src` CSP directive (default: `[]`) * [`JWT_CONF`] - JWT module config, see [JWT module](json-tokens.md) * [`OPENID_CONF`] - OpenID config, see [OpenID Connect module](openid.md)