X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server.ts;h=a688bb5d082a108ecee908a4366c1d2f39b690df;hb=0f7fedc39857ebc0eb29182c1588a92b9adfb75a;hp=fb01ed572bcdd9ac15ea3b2fef103f73ce257e85;hpb=9b67da3d9bc951c624f17dce7821036f8518d893;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server.ts b/server.ts index fb01ed572..a688bb5d0 100644 --- a/server.ts +++ b/server.ts @@ -1,4 +1,6 @@ // FIXME: https://github.com/nodejs/node/pull/16853 +import { VideosCaptionCache } from './server/lib/cache/videos-caption-cache' + require('tls').DEFAULT_ECDH_CURVE = 'auto' import { isTestInstance } from './server/helpers/core-utils' @@ -12,6 +14,8 @@ import * as bodyParser from 'body-parser' import * as express from 'express' import * as morgan from 'morgan' import * as cors from 'cors' +import * as cookieParser from 'cookie-parser' +import * as helmet from 'helmet' process.title = 'peertube' @@ -23,7 +27,7 @@ import { checkMissedConfig, checkFFmpeg, checkConfig, checkActivityPubUrls } fro // Do not use barrels because we don't want to load all modules here (we need to initialize database first) import { logger } from './server/helpers/logger' -import { API_VERSION, CONFIG, STATIC_PATHS } from './server/initializers/constants' +import { API_VERSION, CONFIG, STATIC_PATHS, CACHE } from './server/initializers/constants' const missed = checkMissedConfig() if (missed.length !== 0) { @@ -45,6 +49,31 @@ if (errorMessage !== null) { // Trust our proxy (IP forwarding...) app.set('trust proxy', CONFIG.TRUST_PROXY) +// Security middlewares +app.use(helmet({ + frameguard: { + action: 'deny' // we only allow it for /videos/embed, see server/controllers/client.ts + }, + dnsPrefetchControl: { + allow: true + }, + contentSecurityPolicy: { + directives: { + fontSrc: ["'self'"], + frameSrc: ["'none'"], + mediaSrc: ['*', 'https:'], + objectSrc: ["'none'"], + scriptSrc: ["'self'"], + styleSrc: ["'self'"], + upgradeInsecureRequests: true + }, + browserSniff: false // assumes a modern browser, but allows CDN in front + }, + referrerPolicy: { + policy: 'strict-origin-when-cross-origin' + } +})) + // ----------- Database ----------- // Initialize database and models @@ -89,7 +118,8 @@ if (isTestInstance()) { // These routes have already cors if ( req.path.indexOf(STATIC_PATHS.TORRENTS) === -1 && - req.path.indexOf(STATIC_PATHS.WEBSEED) === -1 + req.path.indexOf(STATIC_PATHS.WEBSEED) === -1 && + req.path.startsWith('/api/') === false ) { return (cors({ origin: '*', @@ -112,6 +142,8 @@ app.use(bodyParser.json({ type: [ 'application/json', 'application/*+json' ], limit: '500kb' })) +// Cookies +app.use(cookieParser()) // ----------- Views, routes and static files ----------- @@ -176,7 +208,8 @@ async function startApplication () { await JobQueue.Instance.init() // Caches initializations - VideosPreviewCache.Instance.init(CONFIG.CACHE.PREVIEWS.SIZE) + VideosPreviewCache.Instance.init(CONFIG.CACHE.PREVIEWS.SIZE, CACHE.PREVIEWS.MAX_AGE) + VideosCaptionCache.Instance.init(CONFIG.CACHE.VIDEO_CAPTIONS.SIZE, CACHE.VIDEO_CAPTIONS.MAX_AGE) // Enable Schedulers BadActorFollowScheduler.Instance.enable()