A platform for community discussion. Free, open, simple.
FIX: Validate theme imports before hijacking the request
Régis Hanol6a1aab2f11f5
diff --git a/app/controllers/admin/themes_controller.rb b/app/controllers/admin/themes_controller.rbindex 56bbaed377d..0a0a5929716 100644--- a/app/controllers/admin/themes_controller.rb+++ b/app/controllers/admin/themes_controller.rb@@ -65,25 +65,24 @@ class Admin::ThemesController < Admin::AdminControllerreturnend- hijack do- branch = params[:branch] ? params[:branch] : nil- private_key =- params[:public_key] ? Discourse.redis.get("ssh_key_#{params[:public_key]}") : nil- if params[:public_key].present? && private_key.blank?- return render_json_error I18n.t("themes.import_error.ssh_key_gone")- end-- if params[:placeholder]- if private_key.blank?- return render_json_error I18n.t("themes.import_error.git_authentication")- end+ branch = params[:branch]+ private_key =+ params[:public_key] ? Discourse.redis.get("ssh_key_#{params[:public_key]}") : nil- @theme = create_remote_theme_placeholder(remote, branch:, private_key:)- return render json: serialize_data(@theme, ThemeSerializer), status: :created- end+ if params[:public_key].present? && private_key.blank?+ return render_json_error I18n.t("themes.import_error.ssh_key_gone")+ end+ if params[:placeholder] && private_key.blank?+ return render_json_error I18n.t("themes.import_error.git_authentication")+ end+ hijack do@theme =- RemoteTheme.import_theme(remote, theme_user, private_key: private_key, branch: branch)+ if params[:placeholder]+ create_remote_theme_placeholder(remote, branch:, private_key:)+ else+ RemoteTheme.import_theme(remote, theme_user, private_key:, branch:)+ endrender json: serialize_data(@theme, ThemeSerializer), status: :createdrescue RemoteTheme::ImportError => eif params[:force]@@ -385,15 +384,15 @@ class Admin::ThemesController < Admin::AdminController)end+ private_key = nil+ if params[:public_key].present?+ private_key = Discourse.redis.get("ssh_key_#{params[:public_key]}")+ return render_json_error I18n.t("themes.import_error.ssh_key_gone") if private_key.blank?+ end+theme_id = @theme.idhijack do- private_key = nil- if params[:public_key].present?- private_key = Discourse.redis.get("ssh_key_#{params[:public_key]}")- return render_json_error I18n.t("themes.import_error.ssh_key_gone") if private_key.blank?- end-theme = Theme.include_relations.find(theme_id)remote_theme = theme.remote_theme