Escapes milestone title shown in flash message when promoting a milestone
This commit is contained in:
parent
cfe2121978
commit
fc9f90045d
2 changed files with 11 additions and 2 deletions
|
@ -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 <a href=\"#{group_milestone_path(project.group, promoted_milestone.iid)}\"><u>group milestone</u></a>.".html_safe
|
||||
milestone_title = sanitize(milestone.title)
|
||||
flash[:notice] = "#{milestone_title} promoted to <a href=\"#{group_milestone_path(project.group, promoted_milestone.iid)}\"><u>group milestone</u></a>.".html_safe
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
redirect_to project_milestones_path(project)
|
||||
|
|
|
@ -127,6 +127,14 @@ describe Projects::MilestonesController do
|
|||
expect(flash[:notice]).to eq("#{milestone.title} promoted to <a href=\"#{group_milestone_path(project.group, milestone.iid)}\"><u>group milestone</u></a>.")
|
||||
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<img src=\"x\"> promoted to <a href=\"#{group_milestone_path(project.group, milestone.iid)}\"><u>group milestone</u></a>.")
|
||||
end
|
||||
end
|
||||
|
||||
context 'promotion fails' do
|
||||
|
|
Loading…
Reference in a new issue