Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow configuration of CSP, sources directives #2332

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
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