mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 10:50:21 +08:00
FIX: Allow themes to upload and serve js files (#8188)
If you set `config.public_file_server.enabled = false` when you try to get uploaded js file you will get an error: `Security warning: an embedded <script> tag on another site requested protected JavaScript. If you know what you're doing, go ahead and disable forgery protection on this action to permit cross-origin JavaScript embedding.` The reason is that content type is `application/javascript` and in Rails 5 guard looked like that: https://github.com/rails/rails/blob/5-2-stable/actionpack/lib/action_controller/metal/request_forgery_protection.rb#L278-L280 However, in Rails 6 `application` was added to regex: https://github.com/rails/rails/blob/master/actionpack/lib/action_controller/metal/request_forgery_protection.rb#L282-L284 This pull request is related to https://meta.discourse.org/t/uploaded-js-file-for-theme-causes-a-rejection/129753/8
This commit is contained in:
parent
e4fe864c0b
commit
99086edf85
3 changed files with 9 additions and 0 deletions
|
@ -6,6 +6,7 @@ class UploadsController < ApplicationController
|
||||||
requires_login except: [:show, :show_short]
|
requires_login except: [:show, :show_short]
|
||||||
|
|
||||||
skip_before_action :preload_json, :check_xhr, :redirect_to_login_if_required, only: [:show, :show_short]
|
skip_before_action :preload_json, :check_xhr, :redirect_to_login_if_required, only: [:show, :show_short]
|
||||||
|
protect_from_forgery except: :show
|
||||||
|
|
||||||
def create
|
def create
|
||||||
# capture current user for block later on
|
# capture current user for block later on
|
||||||
|
|
1
spec/fixtures/themes/test.js
vendored
Normal file
1
spec/fixtures/themes/test.js
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
console.log("test");
|
|
@ -265,6 +265,13 @@ describe UploadsController do
|
||||||
.to eq(%Q|attachment; filename="logo.png"; filename*=UTF-8''logo.png|)
|
.to eq(%Q|attachment; filename="logo.png"; filename*=UTF-8''logo.png|)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'returns 200 when js file' do
|
||||||
|
ActionDispatch::FileHandler.any_instance.stubs(:match?).returns(false)
|
||||||
|
upload = upload_file("test.js", "themes")
|
||||||
|
get upload.url
|
||||||
|
expect(response.status).to eq(200)
|
||||||
|
end
|
||||||
|
|
||||||
it "handles image without extension" do
|
it "handles image without extension" do
|
||||||
SiteSetting.authorized_extensions = "*"
|
SiteSetting.authorized_extensions = "*"
|
||||||
upload = upload_file("image_no_extension")
|
upload = upload_file("image_no_extension")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue