Skip to content
Snippets Groups Projects
Commit 927f608f authored by Patrick Derichs's avatar Patrick Derichs
Browse files

Fix HTML injection for label description

Add changelog entry

Add spec
parent 52b857f1
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -71,7 +71,7 @@ module LabelsHelper
end
 
def label_tooltip_title(label)
label.description
Sanitize.clean(label.description)
end
 
def suggested_colors
Loading
Loading
Loading
Loading
@@ -197,7 +197,11 @@ class Label < ApplicationRecord
end
 
def title=(value)
write_attribute(:title, sanitize_title(value)) if value.present?
write_attribute(:title, sanitize_value(value)) if value.present?
end
def description=(value)
write_attribute(:description, sanitize_value(value)) if value.present?
end
 
##
Loading
Loading
@@ -258,7 +262,7 @@ class Label < ApplicationRecord
end
end
 
def sanitize_title(value)
def sanitize_value(value)
CGI.unescapeHTML(Sanitize.clean(value.to_s))
end
 
Loading
Loading
---
title: Fix HTML injection for label description
merge_request:
author:
type: security
Loading
Loading
@@ -278,4 +278,14 @@ describe LabelsHelper do
it { is_expected.to eq('Subscribe at group level') }
end
end
describe '#label_tooltip_title' do
let(:html) { '<img src="example.png">This is an image</img>' }
let(:label_with_html_content) { create(:label, title: 'test', description: html) }
it 'removes HTML' do
tooltip = label_tooltip_title(label_with_html_content)
expect(tooltip).to eq('This is an image')
end
end
end
Loading
Loading
@@ -84,6 +84,13 @@ describe Label do
end
end
 
describe '#description' do
it 'sanitizes description' do
label = described_class.new(description: '<b>foo & bar?</b>')
expect(label.description).to eq('foo & bar?')
end
end
describe 'priorization' do
subject(:label) { create(:label) }
 
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment