Commit 5091cc4f authored by Jan Provaznik's avatar Jan Provaznik

Merge branch 'security-2717-fix-issue-title-xss' into 'master'

[master] Escape issue title while template rendering to prevent XSS

See merge request gitlab/gitlabhq!2556
parents 5b0b73d9 898462d7
...@@ -201,7 +201,7 @@ class GfmAutoComplete { ...@@ -201,7 +201,7 @@ class GfmAutoComplete {
displayTpl(value) { displayTpl(value) {
let tmpl = GfmAutoComplete.Loading.template; let tmpl = GfmAutoComplete.Loading.template;
if (value.title != null) { if (value.title != null) {
tmpl = GfmAutoComplete.Issues.template; tmpl = GfmAutoComplete.Issues.templateFunction(value.id, value.title);
} }
return tmpl; return tmpl;
}, },
...@@ -267,7 +267,7 @@ class GfmAutoComplete { ...@@ -267,7 +267,7 @@ class GfmAutoComplete {
displayTpl(value) { displayTpl(value) {
let tmpl = GfmAutoComplete.Loading.template; let tmpl = GfmAutoComplete.Loading.template;
if (value.title != null) { if (value.title != null) {
tmpl = GfmAutoComplete.Issues.template; tmpl = GfmAutoComplete.Issues.templateFunction(value.id, value.title);
} }
return tmpl; return tmpl;
}, },
...@@ -370,7 +370,7 @@ class GfmAutoComplete { ...@@ -370,7 +370,7 @@ class GfmAutoComplete {
displayTpl(value) { displayTpl(value) {
let tmpl = GfmAutoComplete.Loading.template; let tmpl = GfmAutoComplete.Loading.template;
if (value.title != null) { if (value.title != null) {
tmpl = GfmAutoComplete.Issues.template; tmpl = GfmAutoComplete.Issues.templateFunction(value.id, value.title);
} }
return tmpl; return tmpl;
}, },
...@@ -557,8 +557,9 @@ GfmAutoComplete.Labels = { ...@@ -557,8 +557,9 @@ GfmAutoComplete.Labels = {
}; };
// Issues, MergeRequests and Snippets // Issues, MergeRequests and Snippets
GfmAutoComplete.Issues = { GfmAutoComplete.Issues = {
// eslint-disable-next-line no-template-curly-in-string templateFunction(id, title) {
template: '<li><small>${id}</small> ${title}</li>', return `<li><small>${id}</small> ${_.escape(title)}</li>`;
},
}; };
// Milestones // Milestones
GfmAutoComplete.Milestones = { GfmAutoComplete.Milestones = {
......
---
title: Escape entity title while autocomplete template rendering to prevent XSS
merge_request: 2556
author:
type: security
...@@ -35,6 +35,21 @@ describe 'GFM autocomplete', :js do ...@@ -35,6 +35,21 @@ describe 'GFM autocomplete', :js do
expect(page).to have_selector('.atwho-container') expect(page).to have_selector('.atwho-container')
end end
it 'opens autocomplete menu when field starts with text with item escaping HTML characters' do
alert_title = 'This will execute alert<img src=x onerror=alert(2)&lt;img src=x onerror=alert(1)&gt;'
create(:issue, project: project, title: alert_title)
page.within '.timeline-content-form' do
find('#note-body').native.send_keys('#')
end
expect(page).to have_selector('.atwho-container')
page.within '.atwho-container #at-view-issues' do
expect(page.all('li').first.text).to include(alert_title)
end
end
it 'doesnt open autocomplete menu character is prefixed with text' do it 'doesnt open autocomplete menu character is prefixed with text' do
page.within '.timeline-content-form' do page.within '.timeline-content-form' do
find('#note-body').native.send_keys('testing') find('#note-body').native.send_keys('testing')
......
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