diff --git a/Framework/Backend/http/server.js b/Framework/Backend/http/server.js index f55090bb8..e645be5f5 100644 --- a/Framework/Backend/http/server.js +++ b/Framework/Backend/http/server.js @@ -38,6 +38,8 @@ class HttpServer { * @param {object} [connectIdConfig] - configuration of OpenID Connect */ constructor(httpConfig, jwtConfig, connectIdConfig = null) { + this.logger = LogManager.getLogger(`${process.env.npm_config_log_label ?? 'framework'}/server`); + assert(httpConfig, 'Missing config'); assert(httpConfig.port, 'Missing config value: port'); httpConfig.tls = !httpConfig.tls ? false : httpConfig.tls; @@ -89,7 +91,6 @@ class HttpServer { * @value {object.lastLoggedTimestamp} - timestamp of the last log of the same error by the same key */ this._jwtErrorsByIp = new Map(); - this.logger = LogManager.getLogger(`${process.env.npm_config_log_label ?? 'framework'}/server`); } /** @@ -142,13 +143,14 @@ class HttpServer { /** * Configures Helmet rules to increase web app security * @param {object} config - configuration of HTTP server - * @param {string} config.hostname whitelisted hostname for websocket connection - * @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 {string} config.hostname - whitelisted hostname for websocket connection + * @param {number} config.port - secure port number + * @param {string[]} [config.iframeCsp] - list of URLs for frame-src CSP + * @param {boolean} [config.allow] - allow unsafe-eval in CSP + * @param {boolean} [config.allowBlobImages] - allow blob: URLs in img-src (image previews/downloads) + * @param {boolean} [config.allowIframeCsp] - Deprecated: Use `allowBlobImages` instead */ - configureHelmet({ hostname, port, iframeCsp = [], allow = false, allowIframeCsp = false }) { + configureHelmet({ hostname, port, iframeCsp = [], allow = false, allowBlobImages, allowIframeCsp }) { // 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) @@ -163,12 +165,18 @@ class HttpServer { this.app.use(helmet.hidePoweredBy()); // Disable DNS prefetching this.app.use(helmet.dnsPrefetchControl()); + + if (allowIframeCsp !== undefined) { + this.logger.warnMessage('http.allowIframeCsp is deprecated, use http.allowBlobImages'); + } + const blobImages = allowBlobImages ?? allowIframeCsp ?? false; + // Disables external resources this.app.use(helmet.contentSecurityPolicy({ directives: { /* eslint-disable */ defaultSrc: ["'self'", "data:", hostname + ':*'], - ...(allowIframeCsp && { imgSrc: ["'self'", "data:", "blob:"] }), + ...(blobImages && { 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], diff --git a/Framework/docs/guide/http-server.md b/Framework/docs/guide/http-server.md index b8bed2252..2f641e0ff 100644 --- a/Framework/docs/guide/http-server.md +++ b/Framework/docs/guide/http-server.md @@ -21,6 +21,11 @@ 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`) + * [`allowBlobImages`] - adds `blob:` to `img-src` so blob-based images can be previewed/downloaded (default: `false`) + * [`allowIframeCsp`] - **deprecated**, use `allowBlobImages`; + * [`JWT_CONF`] - JWT module config, see [JWT module](json-tokens.md) * [`OPENID_CONF`] - OpenID config, see [OpenID Connect module](openid.md)