From fc9f90045d930641690f75e9bae25683dc67a24e Mon Sep 17 00:00:00 2001 From: Filipa Lacerda Date: Thu, 12 Jul 2018 15:58:33 +0100 Subject: [PATCH] Escapes milestone title shown in flash message when promoting a milestone --- app/controllers/projects/milestones_controller.rb | 5 +++-- spec/controllers/projects/milestones_controller_spec.rb | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/controllers/projects/milestones_controller.rb b/app/controllers/projects/milestones_controller.rb index 5e86ec93f34..17571935c1c 100644 --- a/app/controllers/projects/milestones_controller.rb +++ b/app/controllers/projects/milestones_controller.rb @@ -1,4 +1,5 @@ class Projects::MilestonesController < Projects::ApplicationController + include ActionView::Helpers::SanitizeHelper include Gitlab::Utils::StrongMemoize include MilestoneActions @@ -76,8 +77,8 @@ class Projects::MilestonesController < Projects::ApplicationController def promote promoted_milestone = Milestones::PromoteService.new(project, current_user).execute(milestone) - - flash[:notice] = "#{milestone.title} promoted to group milestone.".html_safe + milestone_title = sanitize(milestone.title) + flash[:notice] = "#{milestone_title} promoted to group milestone.".html_safe respond_to do |format| format.html do redirect_to project_milestones_path(project) diff --git a/spec/controllers/projects/milestones_controller_spec.rb b/spec/controllers/projects/milestones_controller_spec.rb index ea906cf7f32..e351e0fe07d 100644 --- a/spec/controllers/projects/milestones_controller_spec.rb +++ b/spec/controllers/projects/milestones_controller_spec.rb @@ -127,6 +127,14 @@ describe Projects::MilestonesController do expect(flash[:notice]).to eq("#{milestone.title} promoted to group milestone.") expect(response).to redirect_to(project_milestones_path(project)) end + + it 'renders milestone name without parsing it as HTML' do + milestone.update!(name: 'CCC<img src=x onerror=alert(document.domain)>') + + post :promote, namespace_id: project.namespace.id, project_id: project.id, id: milestone.iid + + expect(flash[:notice]).to eq("CCC promoted to group milestone.") + end end context 'promotion fails' do