A platform for community discussion. Free, open, simple.
DEV: escape provider display name in omniauth failure message (#38635)
Isaac Janzen611ea4212aa2
diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rbindex 5eed4da40b8..f8626e58d39 100644--- a/app/controllers/users/omniauth_callbacks_controller.rb+++ b/app/controllers/users/omniauth_callbacks_controller.rb@@ -122,7 +122,7 @@ class Users::OmniauthCallbacksController < ApplicationControllererror = provider.present? ? "generic_with_provider" : "generic_without_provider"end- flash[:error] = I18n.t("login.omniauth_error.#{error}", provider:).html_safe+ flash[:error] = I18n.t("login.omniauth_error.#{error}", provider:)render "failure"enddiff --git a/spec/requests/omniauth_callbacks_controller_spec.rb b/spec/requests/omniauth_callbacks_controller_spec.rbindex 69c40f7f967..c4d9023b60b 100644--- a/spec/requests/omniauth_callbacks_controller_spec.rb+++ b/spec/requests/omniauth_callbacks_controller_spec.rb@@ -136,6 +136,19 @@ RSpec.describe Users::OmniauthCallbacksController doI18n.t("login.omniauth_error.generic_with_provider", provider: "Google"),)end++ it "HTML-escapes the provider display name in the error message" do+ display_name = "<Custom & Provider>"+ authenticator = Auth::GoogleOAuth2Authenticator.new+ authenticator.stubs(:display_name).returns(display_name)+ Discourse.stubs(:enabled_authenticators).returns([authenticator])++ get "/auth/failure", params: { provider: "google_oauth2" }++ expect(response.status).to eq(200)+ expect(response.body).not_to include(display_name)+ expect(response.body).to include(CGI.escapeHTML(display_name))+ endenddescribe "request" do