Skip to content
Open
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
17 changes: 13 additions & 4 deletions Framework/Backend/http/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ class HttpServer {
* @param {object} httpConfig - configuration of HTTP server
* @param {object} [jwtConfig] - configuration of JWT
* @param {object} [connectIdConfig] - configuration of OpenID Connect
* @param {object} CspAdditionalSources - additional CSP configuration
* @param {string[]} [CspAdditionalSources.scriptSrc] - list of sources that will be allowed
* @param {string[]} [CspAdditionalSources.styleSrc] - list of sources that will be allowed
* @param {string[]} [CspAdditionalSources.connectSrc] - list of sources that will be allowed
*/
constructor(httpConfig, jwtConfig, connectIdConfig = null) {
assert(httpConfig, 'Missing config');
Expand Down Expand Up @@ -131,8 +135,13 @@ class HttpServer {
* @param {string} hostname whitelisted hostname for websocket connection
* @param {list} iframeCsp list of URLs for frame-src CSP
* @param {number} port secure port number
* @param {object} CspAdditionalSources additional CSP configuration
* @param {string[]} [CspAdditionalSources.scriptSrc] list of sources that will be allowed
* @param {string[]} [CspAdditionalSources.styleSrc] list of sources that will be allowed
* @param {string[]} [CspAdditionalSources.connectSrc] list of sources that will be allowed
*/
configureHelmet({hostname, port, iframeCsp = [], allow = false}) {
configureHelmet({hostname, port, iframeCsp = [], allow = false, CspAdditionalSources = {}}) {
const { scriptSrc = [], styleSrc = [], connectSrc = [] } = CspAdditionalSources;
// 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 @@ -152,9 +161,9 @@ class HttpServer {
directives: {
/* eslint-disable */
defaultSrc: ["'self'", "data:", hostname + ':*'],
scriptSrc: ["'self'", ...(allow ? ["'unsafe-eval'"] : [])],
styleSrc: ["'self'", "'unsafe-inline'"],
connectSrc: ["'self'", 'http://' + hostname + ':' + port, 'https://' + hostname, 'wss://' + hostname, 'ws://' + hostname + ':' + port],
scriptSrc: ["'self'", ...(allow ? ["'unsafe-eval'"] : []), ...scriptSrc],
styleSrc: ["'self'", "'unsafe-inline'", ...styleSrc],
connectSrc: ["'self'", 'http://' + hostname + ':' + port, 'https://' + hostname, 'wss://' + hostname, 'ws://' + hostname + ':' + port, ...connectSrc],
upgradeInsecureRequests: null,
frameSrc: iframeCsp
/* eslint-enable */
Expand Down