]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Dissociate frameguard from csp
authorChocobozzz <me@florianbigard.com>
Mon, 12 Apr 2021 13:33:54 +0000 (15:33 +0200)
committerChocobozzz <me@florianbigard.com>
Mon, 12 Apr 2021 13:33:54 +0000 (15:33 +0200)
config/default.yaml
config/production.yaml.example
server.ts
server/initializers/checker-before-init.ts
server/initializers/config.ts
server/tests/api/server/config.ts

index f9b6c50a34d2db13187db376916f50a4003a8c82..281cc0577955f41ed4db936949986ce9b15a0bfe 100644 (file)
@@ -153,6 +153,11 @@ csp:
   report_only: true # CSP directives are still being tested, so disable the report only mode at your own risk!
   report_uri:
 
+security:
+  # Set the X-Frame-Options header to help to mitigate clickjacking attacks
+  frameguard:
+    enabled: true
+
 tracker:
   # If you disable the tracker, you disable the P2P aspect of PeerTube
   enabled: true
index f2e75af32935748e18c772ce33e826780022d93d..fed6b45ca871965164ab16191663bcc62afd30a6 100644 (file)
@@ -151,6 +151,11 @@ csp:
   report_only: true # CSP directives are still being tested, so disable the report only mode at your own risk!
   report_uri:
 
+security:
+  # Set the X-Frame-Options header to help to mitigate clickjacking attacks
+  frameguard:
+    enabled: true
+
 tracker:
   # If you disable the tracker, you disable the P2P aspect of PeerTube
   enabled: true
index f44202c9af982bb294dd5563049c40046aa50809..2531080a30819902b2063b90c6af097d454a8452 100644 (file)
--- a/server.ts
+++ b/server.ts
@@ -59,11 +59,11 @@ import { baseCSP } from './server/middlewares/csp'
 
 if (CONFIG.CSP.ENABLED) {
   app.use(baseCSP)
-  app.use(helmet({
-    frameguard: {
-      action: 'deny' // we only allow it for /videos/embed, see server/controllers/client.ts
-    },
-    hsts: false
+}
+
+if (CONFIG.SECURITY.FRAMEGUARD.ENABLED) {
+  app.use(helmet.frameguard({
+    action: 'deny' // we only allow it for /videos/embed, see server/controllers/client.ts
   }))
 }
 
index e92cc4d2cfd30e00ba01bec7686dcf23140fcf05..2864b02871b278ecefa2943bba921876dc58ad75 100644 (file)
@@ -17,6 +17,7 @@ function checkMissedConfig () {
     'log.level',
     'user.video_quota', 'user.video_quota_daily',
     'csp.enabled', 'csp.report_only', 'csp.report_uri',
+    'security.frameguard.enabled',
     'cache.previews.size', 'cache.captions.size', 'cache.torrents.size', 'admin.email', 'contact_form.enabled',
     'signup.enabled', 'signup.limit', 'signup.requires_email_verification',
     'signup.filters.cidr.whitelist', 'signup.filters.cidr.blacklist',
index 4e15acd0dc831ceb418ff1a7442afb3ed0725d41..5281d3a666386cd33dd7b5a091d9837d339b5d8b 100644 (file)
@@ -134,6 +134,11 @@ const CONFIG = {
     REPORT_ONLY: config.get<boolean>('csp.report_only'),
     REPORT_URI: config.get<string>('csp.report_uri')
   },
+  SECURITY: {
+    FRAMEGUARD: {
+      ENABLED: config.get<boolean>('security.frameguard.enabled')
+    }
+  },
   TRACKER: {
     ENABLED: config.get<boolean>('tracker.enabled'),
     PRIVATE: config.get<boolean>('tracker.private'),
index 0b0f48d2264331c50c43cbd58034983bc401aa79..1d9ea31df442bbca17480ecc05bab420b4c1055e 100644 (file)
@@ -12,6 +12,7 @@ import {
   getConfig,
   getCustomConfig,
   killallServers,
+  makeGetRequest,
   parallelTests,
   registerUser,
   reRunServer,
@@ -508,6 +509,39 @@ describe('Test config', function () {
     checkInitialConfig(server, data)
   })
 
+  it('Should enable frameguard', async function () {
+    this.timeout(25000)
+
+    {
+      const res = await makeGetRequest({
+        url: server.url,
+        path: '/api/v1/config',
+        statusCodeExpected: 200
+      })
+
+      expect(res.headers['x-frame-options']).to.exist
+    }
+
+    killallServers([ server ])
+
+    const config = {
+      security: {
+        frameguard: { enabled: false }
+      }
+    }
+    server = await reRunServer(server, config)
+
+    {
+      const res = await makeGetRequest({
+        url: server.url,
+        path: '/api/v1/config',
+        statusCodeExpected: 200
+      })
+
+      expect(res.headers['x-frame-options']).to.not.exist
+    }
+  })
+
   after(async function () {
     await cleanupTests([ server ])
   })