Skip to content

Commit 11dcc17

Browse files
Improve HTML escaping helper (#12383)
The previous method did not escape single quotes which under some circumstances can lead to XSS vulnerabilites and the fact that it depends on jQuery is also not ideal. Replace it with a lightweight module. Co-authored-by: techknowlogick <[email protected]>
1 parent 24f8625 commit 11dcc17

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"css-loader": "4.0.0",
1919
"cssnano-webpack-plugin": "1.0.3",
2020
"dropzone": "5.7.2",
21+
"escape-goat": "3.0.0",
2122
"fast-glob": "3.2.4",
2223
"file-loader": "6.0.0",
2324
"fomantic-ui": "2.8.6",

web_src/js/index.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import './publicpath.js';
55

66
import Vue from 'vue';
7+
import {htmlEscape} from 'escape-goat';
78
import 'jquery.are-you-sure';
89
import './vendor/semanticdropdown.js';
910

@@ -25,10 +26,6 @@ import {svg, svgs} from './svg.js';
2526

2627
const {AppSubUrl, StaticUrlPrefix, csrf} = window.config;
2728

28-
function htmlEncode(text) {
29-
return jQuery('<div />').text(text).html();
30-
}
31-
3229
let previewFileModes;
3330
const commentMDEditors = {};
3431

@@ -528,12 +525,12 @@ function initCommentForm() {
528525
switch (input_id) {
529526
case '#milestone_id':
530527
$list.find('.selected').html(`<a class="item" href=${$(this).data('href')}>${
531-
htmlEncode($(this).text())}</a>`);
528+
htmlEscape($(this).text())}</a>`);
532529
break;
533530
case '#assignee_id':
534531
$list.find('.selected').html(`<a class="item" href=${$(this).data('href')}>` +
535532
`<img class="ui avatar image" src=${$(this).data('avatar')}>${
536-
htmlEncode($(this).text())}</a>`);
533+
htmlEscape($(this).text())}</a>`);
537534
}
538535
$(`.ui${select_id}.list .no-select`).addClass('hide');
539536
$(input_id).val($(this).data('id'));
@@ -1944,7 +1941,7 @@ function searchUsers() {
19441941
$.each(response.data, (_i, item) => {
19451942
let title = item.login;
19461943
if (item.full_name && item.full_name.length > 0) {
1947-
title += ` (${htmlEncode(item.full_name)})`;
1944+
title += ` (${htmlEscape(item.full_name)})`;
19481945
}
19491946
items.push({
19501947
title,
@@ -2220,7 +2217,7 @@ function initTemplateSearch() {
22202217
// Parse the response from the api to work with our dropdown
22212218
$.each(response.data, (_r, repo) => {
22222219
filteredResponse.results.push({
2223-
name: htmlEncode(repo.full_name),
2220+
name: htmlEscape(repo.full_name),
22242221
value: repo.id
22252222
});
22262223
});
@@ -3500,8 +3497,8 @@ function initIssueList() {
35003497
return;
35013498
}
35023499
filteredResponse.results.push({
3503-
name: `#${issue.number} ${htmlEncode(issue.title)
3504-
}<div class="text small dont-break-out">${htmlEncode(issue.repository.full_name)}</div>`,
3500+
name: `#${issue.number} ${htmlEscape(issue.title)
3501+
}<div class="text small dont-break-out">${htmlEscape(issue.repository.full_name)}</div>`,
35053502
value: issue.id
35063503
});
35073504
});

0 commit comments

Comments
 (0)