Skip to content

Commit 23387d7

Browse files
committed
Make sure Scratch assets can be displayed in library
The library uses an <img> tag to load and embed the assets, which is different to how assets are loaded in projects For this to work, the asset needs to have a Cross-Origin-Resource-Policy set.
1 parent 39dd62c commit 23387d7

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

lib/corp_middleware.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def call(env)
1212
request_origin = env['HTTP_HOST']
1313
allowed_origins = OriginParser.parse_origins
1414

15-
if env['PATH_INFO'].start_with?('/rails/active_storage') && allowed_origins.any? do |origin|
15+
if env['PATH_INFO'].start_with?('/rails/active_storage', '/api/scratch/assets/internalapi/asset/') && allowed_origins.any? do |origin|
1616
origin.is_a?(Regexp) ? origin =~ request_origin : origin == request_origin
1717
end
1818
headers['Cross-Origin-Resource-Policy'] = 'cross-origin'

spec/lib/corp_middleware_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818
expect(headers['Cross-Origin-Resource-Policy']).to eq('cross-origin')
1919
end
2020

21+
it 'sets the Cross-Origin-Resource-Policy header for requests to scratch assets' do
22+
_status, headers, _response = middleware.call(env.merge('PATH_INFO' => '/api/scratch/assets/internalapi/asset/123/get/'))
23+
24+
expect(headers['Cross-Origin-Resource-Policy']).to eq('cross-origin')
25+
end
26+
2127
it 'sets the Cross-Origin-Resource-Policy header for regex origin' do
2228
allow(ENV).to receive(:[]).with('ALLOWED_ORIGINS').and_return('/test\.com/')
2329

0 commit comments

Comments
 (0)