Sha256: f5cf1cbc75570d998ff110459ff07e8594a3ab36128cab6c19faa169d1e75122

Contents?: true

Size: 984 Bytes

Versions: 42

Compression:

Stored size: 984 Bytes

Contents

module ShopifyApp
  module AppProxyVerification
    extend ActiveSupport::Concern

    included do
      skip_before_action :verify_authenticity_token, raise: false
      before_action :verify_proxy_request
    end

    def verify_proxy_request
      return head :forbidden unless query_string_valid?(request.query_string)
    end

    private

    def query_string_valid?(query_string)
      query_hash = Rack::Utils.parse_query(query_string)

      signature = query_hash.delete('signature')
      return false if signature.nil?

      ActiveSupport::SecurityUtils.secure_compare(
        calculated_signature(query_hash),
        signature
      )
    end

    def calculated_signature(query_hash_without_signature)
      sorted_params = query_hash_without_signature.collect{|k,v| "#{k}=#{Array(v).join(',')}"}.sort.join

      OpenSSL::HMAC.hexdigest(
        OpenSSL::Digest.new('sha256'),
        ShopifyApp.configuration.secret,
        sorted_params
      )
    end
  end
end

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
shopify_app-13.0.0 lib/shopify_app/controller_concerns/app_proxy_verification.rb
shopify_app-12.0.7 lib/shopify_app/controller_concerns/app_proxy_verification.rb
shopify_app-12.0.6 lib/shopify_app/controller_concerns/app_proxy_verification.rb
shopify_app-12.0.5 lib/shopify_app/controller_concerns/app_proxy_verification.rb
shopify_app-12.0.4 lib/shopify_app/controller_concerns/app_proxy_verification.rb
shopify_app-12.0.3 lib/shopify_app/controller_concerns/app_proxy_verification.rb
shopify_app-12.0.2 lib/shopify_app/controller_concerns/app_proxy_verification.rb
shopify_app-12.0.1 lib/shopify_app/controller_concerns/app_proxy_verification.rb
shopify_app-12.0.0 lib/shopify_app/controller_concerns/app_proxy_verification.rb
shopify_app-11.7.1 lib/shopify_app/controller_concerns/app_proxy_verification.rb
shopify_app-11.7.0 lib/shopify_app/controller_concerns/app_proxy_verification.rb
shopify_app-11.6.0 lib/shopify_app/controller_concerns/app_proxy_verification.rb
shopify_app-11.5.1 lib/shopify_app/controller_concerns/app_proxy_verification.rb
shopify_app-11.5.0 lib/shopify_app/controller_concerns/app_proxy_verification.rb
shopify_app-11.4.0 lib/shopify_app/controller_concerns/app_proxy_verification.rb
shopify_app-11.3.2 lib/shopify_app/controller_concerns/app_proxy_verification.rb
shopify_app-11.3.1 lib/shopify_app/controller_concerns/app_proxy_verification.rb
shopify_app-11.3.0 lib/shopify_app/controller_concerns/app_proxy_verification.rb
shopify_app-11.2.0 lib/shopify_app/controller_concerns/app_proxy_verification.rb
shopify_app-11.1.0 lib/shopify_app/controller_concerns/app_proxy_verification.rb