Skip to content

Commit

Permalink
CSP for all localhost pages
Browse files Browse the repository at this point in the history
  • Loading branch information
david-asher committed Apr 25, 2021
1 parent 24f3421 commit cda6d2f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
36 changes: 18 additions & 18 deletions lib/webserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,23 +83,6 @@ function _getWebOptions()
}
}

function _useStaticFolders( folderList )
{
const folderOptions = {
index: false,
maxAge: '1d',
redirect: false,
setHeaders: function (res, path, stat) {
res.set( 'Content-Security-Policy', global.ContentSecurityString )
}
}
if ( !Array.isArray( folderList ) ) folderList = [ folderList ]
folderList.forEach( (folder) => {
const slashFolder = '/' + folder.replace(/^\/+/, '')
appserver.use( slashFolder, express.static( process.env.INIT_CWD + slashFolder, folderOptions ) )
})
}

/*
* This function will start the HTTPS local webserver and configure static document serving.
* @param {app} mainApp - The Electron main app
Expand Down Expand Up @@ -164,8 +147,25 @@ function start( mainApp, staticFolders )
appserver.use( '/api', _checkOurApp )
appserver.use( helmet() )

_useStaticFolders( staticFolders )
// set ContentSecurityPolicy header for all local web pages
appserver.use((req, res, next) => {
res.set( 'Content-Security-Policy', global.ContentSecurityString )
next();
});

// set up static web content folders
const folderOptions = {
index: false,
maxAge: '1d',
redirect: false,
}
if ( 'string' == typeof (staticFolders) ) staticFolders = staticFolders.split( /,|;/ )
staticFolders.forEach( (folder) => {
const slashFolder = '/' + folder.replace(/^\/+/, '')
appserver.use( slashFolder, express.static( process.env.INIT_CWD + slashFolder, folderOptions ) )
})

// start the secure web server
webtls = https.createServer( _getWebOptions(), appserver )
webtls.listen( global.appConfig.webapp.port, () => {
// console.log( "TLS server on port " + webtls.address().port )
Expand Down
3 changes: 1 addition & 2 deletions lib/windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,9 @@ class open extends BrowserWindow

if ( !urlOptions ) urlOptions = {}
if ( global.userAgent && !urlOptions.userAgent ) urlOptions.userAgent = global.userAgent

// now that the window is configured, open it with the URL
super.loadURL( urlToOpen, urlOptions )

}

/**
Expand Down

0 comments on commit cda6d2f

Please sign in to comment.