Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CSP headers to unauthenticated controller #1474

Merged
merged 1 commit into from
Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Unreleased
----------

* Set the appropriate CSP `frame-ancestor` directive in controllers using the `EmbeddedApp` concern. [#1474](https://github.com/Shopify/shopify_app/pull/1474)

20.0.2 (July 7, 2022)
----------

Expand Down
1 change: 1 addition & 0 deletions lib/shopify_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def self.use_webpacker?
# controller concerns
require "shopify_app/controller_concerns/csrf_protection"
require "shopify_app/controller_concerns/localization"
require "shopify_app/controller_concerns/frame_ancestors"
require "shopify_app/controller_concerns/itp"
require "shopify_app/controller_concerns/login_protection"
require "shopify_app/controller_concerns/ensure_billing"
Expand Down
2 changes: 2 additions & 0 deletions lib/shopify_app/controller_concerns/embedded_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ module ShopifyApp
module EmbeddedApp
extend ActiveSupport::Concern

include ShopifyApp::FrameAncestors

included do
if ShopifyApp.configuration.embedded_app?
after_action(:set_esdk_headers)
Expand Down
16 changes: 16 additions & 0 deletions lib/shopify_app/controller_concerns/frame_ancestors.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

module ShopifyApp
module FrameAncestors
extend ActiveSupport::Concern

included do
content_security_policy do |policy|
policy.frame_ancestors(-> do
domain_host = current_shopify_domain || "*.myshopify.com"
"https://#{domain_host} https://admin.shopify.com;"
end)
end
end
end
end