Clean up strings on server

This commit is contained in:
Pavel Djundik 2020-01-21 15:42:29 +02:00
parent de6d6906f8
commit 1a7135c5e0

View File

@ -62,26 +62,24 @@ function Network(attr) {
} }
Network.prototype.validate = function(client) { Network.prototype.validate = function(client) {
// If entered nick is over 100 characters, limit it so we don't try to compile a big regex // Remove !, :, @ and whitespace characters from nicknames and usernames
if (this.nick && this.nick.length > 100) { const cleanNick = (str) => str.replace(/[\x00\s:!@]/g, "_").substring(0, 100);
this.nick = this.nick.substring(0, 100);
}
this.setNick(String(this.nick || Helper.getDefaultNick()).replace(/\s/g, "_")); // Remove new lines and limit length
const cleanString = (str) => str.replace(/[\x00\r\n]/g, "").substring(0, 300);
this.setNick(cleanNick(String(this.nick || Helper.getDefaultNick())));
if (!this.username) { if (!this.username) {
// If username is empty, make one from the provided nick
this.username = this.nick.replace(/[^a-zA-Z0-9]/g, ""); this.username = this.nick.replace(/[^a-zA-Z0-9]/g, "");
} else {
// Remove any whitespace from usernames as that is not valid
this.username = this.username.replace(/\s/g, "_").substring(0, 100);
} }
if (!this.realname) { this.username = cleanNick(this.username) || "thelounge";
this.realname = "The Lounge User"; this.realname = cleanString(this.realname) || "The Lounge User";
} else { this.password = cleanString(this.password);
// Remove newlines from realnames this.host = cleanString(this.host);
this.realname = this.realname.replace(/[\r\n]/g, "_").substring(0, 128); this.name = cleanString(this.name);
}
if (!this.port) { if (!this.port) {
this.port = this.tls ? 6697 : 6667; this.port = this.tls ? 6697 : 6667;