Skip to content

Commit

Permalink
Avoid preloading ActionController::Base (#855)
Browse files Browse the repository at this point in the history
* moved extension verification controller from engine to app

* nest in module

* add changelog

* remove loading controller from engine

* minor version change, not a patch
  • Loading branch information
slucaskim committed Jan 15, 2020
1 parent 7a07288 commit b3ba6fa
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 25 deletions.
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

0 comments on commit b3ba6fa

Please sign in to comment.