Skip to content

Commit 5c0f7c5

Browse files
committed
fix(titles): Fix XSS Attack in Session Titles.
Thanks to: zozokasu who submitted this via the security ticket system.
1 parent 5004f26 commit 5c0f7c5

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

helpers/preprocessing.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import DOMPurify from 'isomorphic-dompurify';
22

3+
function sanitizeHTML(input) {
4+
return DOMPurify.sanitize(input, {ALLOWED_TAGS: ['span']});
5+
}
6+
37
/**
48
* Converts the world or session name to its HTML equivalent.
59
*
@@ -8,8 +12,9 @@ import DOMPurify from 'isomorphic-dompurify';
812
*/
913
function preProcessName(name) {
1014
const start = /<color="?(.+?)"?>/gi;
11-
const end = /<\/color>/gi
12-
return name.replace(start, "<span style=\"color: $1;\">").replace(end, "</span>");
15+
const end = /<\/color>/gi;
16+
var styleTags = name.replace(start, "<span style=\"color: $1;\">").replace(end, "</span>");
17+
return sanitizeHTML(styleTags);
1318
}
1419

1520
/**
@@ -80,8 +85,9 @@ function preProcessWorld(json) {
8085
export function preProcess(json, type) {
8186

8287
if (type != "sessionList"){
83-
// ensure page title
84-
json.title = DOMPurify.sanitize(json.name);
88+
json.title = DOMPurify.sanitize(json.name); // No tags in title
89+
90+
// Handle name for inclusion in the actual page.
8591
json.name = preProcessName(json.name);
8692
}
8793

0 commit comments

Comments
 (0)