Skip to content

Commit 8c2f4ed

Browse files
committed
fix XSS in tab list
1 parent 73b57c6 commit 8c2f4ed

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

src/scripts/additional/tools.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const antiXSS = (str) => {
2+
const replacements = [
3+
[/&/g, '&'],
4+
[/</g, '&lt;'],
5+
[/>/g, '&gt;'],
6+
[/"/g, '&quot;']
7+
]
8+
for (const replacement of replacements) {
9+
str = str.replace(replacement[0], replacement[1])
10+
}
11+
return str
12+
}
13+
export { antiXSS }

src/scripts/gui/TabList.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import $ from 'jquery'
2-
2+
import { antiXSS } from './../additional/tools.js'
33
class TabList {
44
constructor (game) {
55
this.game = game
@@ -10,7 +10,7 @@ class TabList {
1010
let newHTML = ''
1111
if (players !== undefined && JSON.stringify(players) !== '{}') {
1212
for (const i in players) {
13-
newHTML += `<div class="tab_player clearfix"><span class="float-left">${i}</span><span class="float-right">${players[i].ping}ms</span></div>`
13+
newHTML += `<div class="tab_player clearfix"><span class="float-left">${antiXSS(i)}</span><span class="float-right">${players[i].ping}ms</span></div>`
1414
}
1515
if (newHTML !== this.lastHTML) {
1616
this.lastHTML = newHTML

src/scripts/proxy/Proxy.worker.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-env worker */
22
import vec3 from 'vec3'
33
import Convert from 'ansi-to-html'
4+
import { antiXSS } from './../additional/tools.js'
45
const convert = new Convert()
56

67
global.window = self
@@ -60,16 +61,7 @@ addEventListener('message', function (e) {
6061
emit('kicked', reason)
6162
})
6263
bot.on('message', function (msg) {
63-
let message = msg.toAnsi()
64-
65-
const replacements = [
66-
[/&/g, '&amp;'],
67-
[/</g, '&lt;'],
68-
[/>/g, '&gt;'],
69-
[/"/g, '&quot;']
70-
]
71-
for (const replacement of replacements) { message = message.replace(replacement[0], replacement[1]) }
72-
64+
const message = antiXSS(msg.toAnsi())
7365
emit('msg', convert.toHtml(message))
7466
})
7567
bot.on('death', () => {

0 commit comments

Comments
 (0)