Skip to content

Commit

Permalink
fix(chat): Fix escapeString (#38)
Browse files Browse the repository at this point in the history
* fix(chat): Fix escapeString

* fix(chat-extended): Fix escapeString

* fix(chat): Fix another xss

* fix(chat-extended): Fix another xss
  • Loading branch information
xLuxy authored May 8, 2024
1 parent 665edb2 commit b1056bf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
8 changes: 3 additions & 5 deletions chat/client/html/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function escapeString(str) {
if (typeof str !== "string") return str;

return str
.replace(/&/g, "&")
//.replace(/&/g, "&")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
Expand All @@ -30,8 +30,6 @@ function colorify(text) {
let m = null;
let curPos = 0;

text = escapeString(text);

do {
m = /\{[A-Fa-f0-9]{3}\}|\{[A-Fa-f0-9]{6}\}/g.exec(text.substr(curPos));

Expand Down Expand Up @@ -180,7 +178,7 @@ function addString(text) {
highlightChat();
}

alt.on("addString", (text) => addString(colorify(text)));
alt.on("addMessage", (name, text) => addString("<b>" + name + ": </b>" + colorify(text)));
alt.on("addString", (text) => addString(colorify(escapeString(text))));
alt.on("addMessage", (name, text) => addString("<b>" + escapeString(name) + ": </b>" + colorify(escapeString(text))));
alt.on("openChat", openChat);
alt.on("closeChat", closeChat);
8 changes: 3 additions & 5 deletions freeroam-extended/client/html/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,14 @@ function escapeString(str) {
if (typeof str !== "string") return str;

return str
.replace(/&/g, "&amp;")
//.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#39;");
}

function colorify(text) {
text = escapeString(text);

let matches = [];
let m = null;
let curPos = 0;
Expand Down Expand Up @@ -235,8 +233,8 @@ function setVoiceConnectionState(state) {
el.textContent = stateText
}

alt.on("addString", (text) => addString(colorify(text)));
alt.on("addMessage", (name, text) => addString("<b>" + colorify(name) + ": </b>" + colorify(text)));
alt.on("addString", (text) => addString(colorify(escapeString(text))));
alt.on("addMessage", (name, text) => addString("<b>" + colorify(escapeString(name)) + ": </b>" + colorify(escapeString(text))));
alt.on("openChat", openChat);
alt.on("closeChat", closeChat);
alt.on("updatePlayersOnline", updatePlayersOnline);
Expand Down

0 comments on commit b1056bf

Please sign in to comment.