Commit 927f608f authored by Patrick Derichs's avatar Patrick Derichs

Fix HTML injection for label description

Add changelog entry

Add spec
parent 52b857f1
......@@ -71,7 +71,7 @@ module LabelsHelper
end
def label_tooltip_title(label)
label.description
Sanitize.clean(label.description)
end
def suggested_colors
......
......@@ -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
##
......@@ -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
......
---
title: Fix HTML injection for label description
merge_request:
author:
type: security
......@@ -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
......@@ -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) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment