Disable GA and Disqus in default CSP

Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
David Mehren 2021-06-07 20:06:44 +02:00
parent 5aeb7f4d0f
commit 52231f688d
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3
2 changed files with 24 additions and 2 deletions

View file

@ -22,8 +22,8 @@ module.exports = {
directives: { directives: {
}, },
addDefaults: true, addDefaults: true,
addDisqus: true, addDisqus: false,
addGoogleAnalytics: true, addGoogleAnalytics: false,
upgradeInsecureRequests: 'auto', upgradeInsecureRequests: 'auto',
reportURI: undefined reportURI: undefined
}, },

View file

@ -68,6 +68,15 @@ describe('Content security policies', function () {
assert(!csp.computeDirectives().scriptSrc.includes('https://www.google-analytics.com')) assert(!csp.computeDirectives().scriptSrc.includes('https://www.google-analytics.com'))
}) })
it('Enable Google Analytics', function () {
const testconfig = defaultConfig
testconfig.csp.addGoogleAnalytics = true
mock('../lib/config', testconfig)
csp = mock.reRequire('../lib/csp')
assert(csp.computeDirectives().scriptSrc.includes('https://www.google-analytics.com'))
})
it('Disable Disqus', function () { it('Disable Disqus', function () {
const testconfig = defaultConfig const testconfig = defaultConfig
testconfig.csp.addDisqus = false testconfig.csp.addDisqus = false
@ -81,6 +90,19 @@ describe('Content security policies', function () {
assert(!csp.computeDirectives().fontSrc.includes('https://*.disquscdn.com')) assert(!csp.computeDirectives().fontSrc.includes('https://*.disquscdn.com'))
}) })
it('Enable Disqus', function () {
const testconfig = defaultConfig
testconfig.csp.addDisqus = true
mock('../lib/config', testconfig)
csp = mock.reRequire('../lib/csp')
assert(csp.computeDirectives().scriptSrc.includes('https://disqus.com'))
assert(csp.computeDirectives().scriptSrc.includes('https://*.disqus.com'))
assert(csp.computeDirectives().scriptSrc.includes('https://*.disquscdn.com'))
assert(csp.computeDirectives().styleSrc.includes('https://*.disquscdn.com'))
assert(csp.computeDirectives().fontSrc.includes('https://*.disquscdn.com'))
})
it('Include dropbox if configured', function () { it('Include dropbox if configured', function () {
const testconfig = defaultConfig const testconfig = defaultConfig
testconfig.dropbox.appKey = 'hedgedoc' testconfig.dropbox.appKey = 'hedgedoc'