aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/controllers/client.ts3
-rw-r--r--server/initializers/constants.ts1
-rw-r--r--server/middlewares/csp.ts45
-rw-r--r--server/middlewares/dnt.ts2
-rw-r--r--server/middlewares/index.ts2
5 files changed, 51 insertions, 2 deletions
diff --git a/server/controllers/client.ts b/server/controllers/client.ts
index 73b40cf65..e5bd487f1 100644
--- a/server/controllers/client.ts
+++ b/server/controllers/client.ts
@@ -2,7 +2,7 @@ import * as express from 'express'
2import { join } from 'path' 2import { join } from 'path'
3import { root } from '../helpers/core-utils' 3import { root } from '../helpers/core-utils'
4import { ACCEPT_HEADERS, STATIC_MAX_AGE } from '../initializers' 4import { ACCEPT_HEADERS, STATIC_MAX_AGE } from '../initializers'
5import { asyncMiddleware } from '../middlewares' 5import { asyncMiddleware, embedCSP } from '../middlewares'
6import { buildFileLocale, getCompleteLocale, is18nLocale, LOCALE_FILES } from '../../shared/models/i18n/i18n' 6import { buildFileLocale, getCompleteLocale, is18nLocale, LOCALE_FILES } from '../../shared/models/i18n/i18n'
7import { ClientHtml } from '../lib/client-html' 7import { ClientHtml } from '../lib/client-html'
8import { logger } from '../helpers/logger' 8import { logger } from '../helpers/logger'
@@ -22,6 +22,7 @@ clientsRouter.use('/videos/watch/:id',
22 22
23clientsRouter.use('' + 23clientsRouter.use('' +
24 '/videos/embed', 24 '/videos/embed',
25 embedCSP,
25 (req: express.Request, res: express.Response, next: express.NextFunction) => { 26 (req: express.Request, res: express.Response, next: express.NextFunction) => {
26 res.removeHeader('X-Frame-Options') 27 res.removeHeader('X-Frame-Options')
27 res.sendFile(embedPath) 28 res.sendFile(embedPath)
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts
index ad61bee73..f1a734f48 100644
--- a/server/initializers/constants.ts
+++ b/server/initializers/constants.ts
@@ -290,6 +290,7 @@ const CONFIG = {
290 get SECURITYTXT_CONTACT () { return config.get<string>('admin.email') } 290 get SECURITYTXT_CONTACT () { return config.get<string>('admin.email') }
291 }, 291 },
292 SERVICES: { 292 SERVICES: {
293 get 'CSP-LOGGER' () { return config.get<string>('services.csp-logger') },
293 TWITTER: { 294 TWITTER: {
294 get USERNAME () { return config.get<string>('services.twitter.username') }, 295 get USERNAME () { return config.get<string>('services.twitter.username') },
295 get WHITELISTED () { return config.get<boolean>('services.twitter.whitelisted') } 296 get WHITELISTED () { return config.get<boolean>('services.twitter.whitelisted') }
diff --git a/server/middlewares/csp.ts b/server/middlewares/csp.ts
new file mode 100644
index 000000000..a0ed3710b
--- /dev/null
+++ b/server/middlewares/csp.ts
@@ -0,0 +1,45 @@
1import * as helmet from 'helmet'
2import { CONFIG } from '../initializers/constants'
3
4const baseDirectives = Object.assign({},
5 {
6 defaultSrc: ["'none'"], // by default, not specifying default-src = '*'
7 connectSrc: ['*', 'data:'],
8 mediaSrc: ["'self'", 'https:', 'blob:'],
9 fontSrc: ["'self'", 'data:'],
10 imgSrc: ["'self'", 'data:'],
11 scriptSrc: ["'self' 'unsafe-inline'"],
12 styleSrc: ["'self' 'unsafe-inline'"],
13 // objectSrc: ["'none'"], // only define to allow plugins, else let defaultSrc 'none' block it
14 formAction: ["'self'"],
15 frameAncestors: ["'none'"],
16 baseUri: ["'self'"],
17 pluginTypes: ["'none'"],
18 manifestSrc: ["'self'"],
19 frameSrc: ["'self'"], // instead of deprecated child-src / self because of test-embed
20 workerSrc: ["'self'"], // instead of deprecated child-src
21 upgradeInsecureRequests: true
22 },
23 (CONFIG.SERVICES['CSP-LOGGER'] != null) ? { reportUri: CONFIG.SERVICES['CSP-LOGGER'] } : {}
24)
25
26const baseCSP = helmet.contentSecurityPolicy({
27 directives: baseDirectives,
28 browserSniff: false,
29 reportOnly: true
30})
31
32const embedCSP = helmet.contentSecurityPolicy({
33 directives: Object.assign(baseDirectives, {
34 frameAncestors: ['*']
35 }),
36 browserSniff: false, // assumes a modern browser, but allows CDN in front
37 reportOnly: true
38})
39
40// ---------------------------------------------------------------------------
41
42export {
43 baseCSP,
44 embedCSP
45}
diff --git a/server/middlewares/dnt.ts b/server/middlewares/dnt.ts
index cabad39c6..607def855 100644
--- a/server/middlewares/dnt.ts
+++ b/server/middlewares/dnt.ts
@@ -10,4 +10,4 @@ const advertiseDoNotTrack = (_, res, next) => {
10 10
11export { 11export {
12 advertiseDoNotTrack 12 advertiseDoNotTrack
13 } 13}
diff --git a/server/middlewares/index.ts b/server/middlewares/index.ts
index 0cef26953..b758a8586 100644
--- a/server/middlewares/index.ts
+++ b/server/middlewares/index.ts
@@ -6,3 +6,5 @@ export * from './pagination'
6export * from './servers' 6export * from './servers'
7export * from './sort' 7export * from './sort'
8export * from './user-right' 8export * from './user-right'
9export * from './dnt'
10export * from './csp'