Skip to content

Commit

Permalink
Set correct header
Browse files Browse the repository at this point in the history
  • Loading branch information
allthesignals committed Jan 22, 2025
1 parent 5295521 commit 3fb78c6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
require "action_cable/engine"
# require "rails/test_unit/railtie"
require_relative "../lib/site_config.rb"
require_relative "../lib/middleware/add_cross_origin_opener_policy"

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Expand Down Expand Up @@ -41,5 +42,6 @@ class Application < Rails::Application
config.autoload_paths += %W[#{config.root}/app/helpers]
config.autoload_paths += %W[#{config.root}/app/controllers/concerns]
config.sites = SiteConfig.new(Rails.root.join("config", "site-config.yml"))
config.middleware.insert_before 0, Middleware::AddCrossOriginOpenerPolicy
end
end
15 changes: 15 additions & 0 deletions app/lib/middleware/add_cross_origin_opener_policy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Middleware
class AddCrossOriginOpenerPolicy
COOP_HEADER = "Cross-Origin-Opener-Policy"

def initialize(app)
@app = app
end

def call(env)
status, headers, response = @app.call(env)
headers[COOP_HEADER] = "same-origin" unless headers.key?(COOP_HEADER)
[status, headers, response]
end
end
end

0 comments on commit 3fb78c6

Please sign in to comment.