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

Avoid preloading ActionController::Base #855

Merged
merged 5 commits into from
Jan 15, 2020
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
11.7.0
-----
* Move ExtensionVerificationController from engine to app controllers, as being in the engine makes ActionController::Base get loaded before app initiates [#855](https://github.com/Shopify/shopify_app/pull/855)

11.6.0
-----
* Enable SameSite=None; Secure by default on all cookies for embedded apps [#851](https://github.com/Shopify/shopify_app/pull/851)
Expand Down
20 changes: 20 additions & 0 deletions app/controllers/shopify_app/extension_verification_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

module ShopifyApp
class ExtensionVerificationController < ActionController::Base
protect_from_forgery with: :null_session
before_action :verify_request

private

def verify_request
hmac_header = request.headers['HTTP_X_SHOPIFY_HMAC_SHA256']
request_body = request.body.read
secret = ShopifyApp.configuration.secret
digest = OpenSSL::Digest.new('sha256')

expected_hmac = Base64.strict_encode64(OpenSSL::HMAC.digest(digest, secret, request_body))
head(:unauthorized) unless ActiveSupport::SecurityUtils.secure_compare(expected_hmac, hmac_header)
end
end
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class MarketingActivitiesController < ExtensionVerificationController
class MarketingActivitiesController < ShopifyApp::ExtensionVerificationController
def preload_form_data
preload_data = {
"form_data": {
Expand Down
3 changes: 0 additions & 3 deletions lib/shopify_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ def self.use_webpacker?
# utils
require 'shopify_app/utils'

# controllers
require 'shopify_app/controllers/extension_verification_controller'

# controller concerns
require 'shopify_app/controller_concerns/localization'
require 'shopify_app/controller_concerns/itp'
Expand Down
18 changes: 0 additions & 18 deletions lib/shopify_app/controllers/extension_verification_controller.rb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/shopify_app/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module ShopifyApp
VERSION = '11.6.0'.freeze
VERSION = '11.7.0'.freeze
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'test_helper'

class ExtensionController < ExtensionVerificationController
class ExtensionController < ShopifyApp::ExtensionVerificationController
def extension_action
head :ok
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class AddMarketingActivityExtensionGeneratorTest < Rails::Generators::TestCase
run_generator

assert_file "app/controllers/marketing_activities_controller.rb" do |controller|
assert_match 'class MarketingActivitiesController < ExtensionVerificationController', controller
assert_match 'class MarketingActivitiesController < ShopifyApp::ExtensionVerificationController', controller
end
end

Expand Down