A platform for community discussion. Free, open, simple.
SECURITY: moderator shouldn't be able to import a theme via API (#18418)
Jarek Radoszae1e536e8394
diff --git a/app/controllers/admin/themes_controller.rb b/app/controllers/admin/themes_controller.rbindex c22228ab6fe..49da3418fac 100644--- a/app/controllers/admin/themes_controller.rb+++ b/app/controllers/admin/themes_controller.rb@@ -5,6 +5,7 @@ require 'base64'class Admin::ThemesController < Admin::AdminControllerskip_before_action :check_xhr, only: [:show, :preview, :export]+ before_action :ensure_admindef previewtheme = Theme.find_by(id: params[:id])diff --git a/config/routes.rb b/config/routes.rbindex 7bd9ae757d3..0b1931aaeb9 100644--- a/config/routes.rb+++ b/config/routes.rb@@ -206,13 +206,17 @@ Discourse::Application.routes.draw doget "customize/embedding" => "embedding#show", constraints: AdminConstraint.newput "customize/embedding" => "embedding#update", constraints: AdminConstraint.new- resources :themes, constraints: AdminConstraint.new-- post "themes/import" => "themes#import"- post "themes/upload_asset" => "themes#upload_asset"- post "themes/generate_key_pair" => "themes#generate_key_pair"- get "themes/:id/preview" => "themes#preview"- put "themes/:id/setting" => "themes#update_single_setting"+ resources :themes, constraints: AdminConstraint.new do+ member do+ get "preview" => "themes#preview"+ put "setting" => "themes#update_single_setting"+ end+ collection do+ post "import" => "themes#import"+ post "upload_asset" => "themes#upload_asset"+ post "generate_key_pair" => "themes#generate_key_pair"+ end+ endscope "/customize", constraints: AdminConstraint.new doresources :user_fields, constraints: AdminConstraint.newdiff --git a/spec/requests/admin/themes_controller_spec.rb b/spec/requests/admin/themes_controller_spec.rbindex 70e06609e4b..1fc23f2abb9 100644--- a/spec/requests/admin/themes_controller_spec.rb+++ b/spec/requests/admin/themes_controller_spec.rb@@ -160,6 +160,13 @@ RSpec.describe Admin::ThemesController doexpect(response.status).to eq(201)end+ it 'should not be able to import a theme by moderator' do+ sign_in(Fabricate(:moderator))++ post "/admin/themes/import.json", params: { theme: theme_json_file }+ expect(response.status).to eq(404)+ end+it 'imports a theme' dopost "/admin/themes/import.json", params: { theme: theme_json_file }expect(response.status).to eq(201)