summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOmar Roth <omarroth@hotmail.com>2018-09-05 21:06:30 -0500
committerOmar Roth <omarroth@hotmail.com>2018-09-05 21:06:30 -0500
commit96234e509f57a30cac5529725ecc8f550e24941f (patch)
treef357b3b478155644e1c2cd21c02c112fa500053c
parenta749ac73acb19ec2e3897006183a4bb1f63ef99a (diff)
downloadinvidious-96234e509f57a30cac5529725ecc8f550e24941f.tar.gz
invidious-96234e509f57a30cac5529725ecc8f550e24941f.tar.bz2
invidious-96234e509f57a30cac5529725ecc8f550e24941f.zip
Add X-Frame-Options, X-XSS-Protection, and X-Content-Type-Options
-rw-r--r--src/invidious.cr4
-rw-r--r--src/invidious/helpers/helpers.cr11
2 files changed, 15 insertions, 0 deletions
diff --git a/src/invidious.cr b/src/invidious.cr
index f38a1343..6a32736c 100644
--- a/src/invidious.cr
+++ b/src/invidious.cr
@@ -106,6 +106,9 @@ spawn do
end
before_all do |env|
+ env.response.headers["X-XSS-Protection"] = "1; mode=block;"
+ env.response.headers["X-Content-Type-Options"] = "nosniff"
+
# CSRF
if Kemal.config.ssl || CONFIG.https_only
host = env.request.headers["Host"]?
@@ -2945,6 +2948,7 @@ public_folder "assets"
Kemal.config.powered_by_header = false
add_handler FilteredCompressHandler.new
+add_handler DenyFrame.new
add_context_storage_type(User)
Kemal.run
diff --git a/src/invidious/helpers/helpers.cr b/src/invidious/helpers/helpers.cr
index 39538950..2af65e74 100644
--- a/src/invidious/helpers/helpers.cr
+++ b/src/invidious/helpers/helpers.cr
@@ -41,6 +41,17 @@ class FilteredCompressHandler < Kemal::Handler
end
end
+class DenyFrame < Kemal::Handler
+ exclude ["/embed/*"]
+
+ def call(env)
+ return call_next env if exclude_match? env
+
+ env.response.headers["X-Frame-Options"] = "sameorigin"
+ call_next env
+ end
+end
+
def rank_videos(db, n, filter, url)
top = [] of {Float64, String}