Skip to content

Commit

Permalink
Add X-Frame-Options, X-XSS-Protection, and X-Content-Type-Options
Browse files Browse the repository at this point in the history
  • Loading branch information
omarroth committed Sep 6, 2018
1 parent a749ac7 commit 96234e5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/invidious.cr
Expand Up @@ -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"]?
Expand Down Expand Up @@ -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
11 changes: 11 additions & 0 deletions src/invidious/helpers/helpers.cr
Expand Up @@ -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}

Expand Down

0 comments on commit 96234e5

Please sign in to comment.