Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions Framework/Backend/http/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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`);
}

/**
Expand Down Expand Up @@ -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
* @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)
Expand All @@ -163,12 +165,18 @@ class HttpServer {
this.app.use(helmet.hidePoweredBy());
// Disable DNS prefetching
this.app.use(helmet.dnsPrefetchControl());

if (allowIframeCsp !== undefined) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that this option is only used by ECS GUI, I think we can drop this logging.

this.logger.warnMessage('http.allowIframeCsp is deprecated, use http.allowBlobImages');
}
const blobImages = allowBlobImages ?? allowIframeCsp ?? false;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for the check here. Make a note for next deployment ansible recipe to also include the recipe update for ECS GUI


// 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],
Expand Down
5 changes: 5 additions & 0 deletions Framework/docs/guide/http-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 displayed (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)

Expand Down
Loading