mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-14 23:24:46 -04:00
Merge pull request #598 from xxyy/feature/csp
Implement basic CSP support
This commit is contained in:
commit
7de6e3211f
12 changed files with 132 additions and 15 deletions
14
app.js
14
app.js
|
@ -24,6 +24,7 @@ var config = require('./lib/config')
|
|||
var logger = require('./lib/logger')
|
||||
var response = require('./lib/response')
|
||||
var models = require('./lib/models')
|
||||
var csp = require('./lib/csp')
|
||||
|
||||
// generate front-end constants by template
|
||||
var constpath = path.join(__dirname, './public/js/lib/common/constant.ejs')
|
||||
|
@ -108,6 +109,19 @@ if (config.hsts.enable) {
|
|||
logger.info('https://en.wikipedia.org/wiki/HTTP_Strict_Transport_Security')
|
||||
}
|
||||
|
||||
// Generate a random nonce per request, for CSP with inline scripts
|
||||
app.use(csp.addNonceToLocals)
|
||||
|
||||
// use Content-Security-Policy to limit XSS, dangerous plugins, etc.
|
||||
// https://helmetjs.github.io/docs/csp/
|
||||
if (config.csp.enable) {
|
||||
app.use(helmet.contentSecurityPolicy({
|
||||
directives: csp.computeDirectives()
|
||||
}))
|
||||
} else {
|
||||
logger.info('Content-Security-Policy is disabled. This may be a security risk.')
|
||||
}
|
||||
|
||||
i18n.configure({
|
||||
locales: ['en', 'zh', 'zh-CN', 'zh-TW', 'fr', 'de', 'ja', 'es', 'ca', 'el', 'pt', 'it', 'tr', 'ru', 'nl', 'hr', 'pl', 'uk', 'hi', 'sv', 'eo', 'da'],
|
||||
cookie: 'locale',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue