shopify-sinatra-app 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3d4212df144a7d460c275e8f7cbfea4c5a0332d5293bb4ea3c1138764748bc37
4
- data.tar.gz: 2f637570f3210796ec09f812e1c4c58b9110db590eeb7366eb2fc58286f20c84
3
+ metadata.gz: 734844728b60f961f5439fd7220d3fec58fd6f70cd71419ba9596d9c3686c592
4
+ data.tar.gz: c01746bc29a918be96c56b0c374c0c34108552eb5cc9090b73c24fe28cec735a
5
5
  SHA512:
6
- metadata.gz: 4cfbca73509abcf9b7b77b9e73e2ee0694f2dc280797b8f9188a2adef9acc5c266dcce5503fa3df69e1269ad8db48e1daee27e63305dd65ce0e4f73a7fd41bc6
7
- data.tar.gz: 5d85a7eafcfced73d5d08d9a8212d764c8ae3ca06b0e05849b6074bef007c5ec3dd3b42974e0c25d0a76c3062a2bb7dbc833fce41360c5114086297420371191
6
+ metadata.gz: c1b690cabf25ceed9607ab97faf426748793b3ab069ac75111c489e81da4ff950041d4efdaf5be7b8cd32da3cdf6c9b04e32dff2842e1363d007a978effa1d0e
7
+ data.tar.gz: 219d6efdfb4716e03d84773e31e8be04a403cfd36cff2bea04e6d7457148dad86c69deac9278a4095001b02b6b131e3296d405723f581ccbda37c0b22a64958f
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ 1.1.1
2
+ -----
3
+ * fix how the CSP is set
4
+
1
5
  1.1.0
2
6
  -----
3
7
  * update to Shopify App Bridge 3
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- shopify-sinatra-app [![Build Status](https://travis-ci.org/kevinhughes27/shopify-tax-receipts.svg)](https://travis-ci.org/kevinhughes27/shopify-sinatra-app)
1
+ shopify-sinatra-app [![CircleCI](https://dl.circleci.com/status-badge/img/gh/kevinhughes27/shopify-sinatra-app/tree/master.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/gh/kevinhughes27/shopify-sinatra-app/tree/master)
2
2
  ===================
3
3
 
4
4
  "A classy shopify app"
@@ -5,7 +5,7 @@ ENV['SECRET'] = 'secret'
5
5
 
6
6
  require 'minitest/autorun'
7
7
  require 'rack/test'
8
- require 'mocha/setup'
8
+ require 'mocha/minitest'
9
9
  require 'fakeweb'
10
10
 
11
11
  FakeWeb.allow_net_connect = false
@@ -117,6 +117,37 @@ module Sinatra
117
117
  end
118
118
  end
119
119
 
120
+ # needs to be dynamic to incude the current shop
121
+ class ContentSecurityPolicy < Rack::Protection::Base
122
+ def csp_policy(env)
123
+ "frame-ancestors: #{current_shop(env)} https://admin.shopify.com;"
124
+ end
125
+
126
+ def call(env)
127
+ status, headers, body = @app.call(env)
128
+ header = 'Content-Security-Policy'
129
+ headers[header] ||= csp_policy(env) if html? headers
130
+ [status, headers, body]
131
+ end
132
+
133
+ private
134
+
135
+ def current_shop(env)
136
+ s = session(env)
137
+ if s.has_key?("return_params")
138
+ "https://#{s["return_params"]["shop"]}"
139
+ elsif s.has_key?(:shopify)
140
+ "https://#{s[:shopify][:shop]}"
141
+ end
142
+ end
143
+
144
+ def html?(headers)
145
+ return false unless (header = headers.detect { |k, _v| k.downcase == 'content-type' })
146
+
147
+ options[:html_types].include? header.last[%r{^\w+/\w+}]
148
+ end
149
+ end
150
+
120
151
  def shopify_webhook(route, &blk)
121
152
  settings.webhook_routes << route
122
153
  post(route) do
@@ -135,7 +166,7 @@ module Sinatra
135
166
  app.set :public_folder, File.expand_path('public')
136
167
  app.enable :inline_templates
137
168
 
138
- app.set :protection, except: :frame_options, frame_ancestors: "https://admin.shopify.com;"
169
+ app.set :protection, except: :frame_options
139
170
 
140
171
  app.set :api_version, '2019-07'
141
172
  app.set :scope, 'read_products, read_orders'
@@ -157,6 +188,8 @@ module Sinatra
157
188
  secret: app.settings.secret,
158
189
  expire_after: 60 * 30 # half an hour in seconds
159
190
 
191
+ app.use Shopify::ContentSecurityPolicy
192
+
160
193
  app.use Rack::Protection::AuthenticityToken, allow_if: lambda { |env|
161
194
  app.settings.webhook_routes.include?(env["PATH_INFO"])
162
195
  }
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'shopify-sinatra-app'
3
- s.version = '1.1.0'
3
+ s.version = '1.1.1'
4
4
 
5
5
  s.summary = 'A classy shopify app'
6
6
  s.description = 'A Sinatra extension for building Shopify Apps. Akin to the shopify_app gem but for Sinatra'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shopify-sinatra-app
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Hughes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-08 00:00:00.000000000 Z
11
+ date: 2022-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra