Merge pull request #2858 from thelounge/xpaw/limit-nick

Hard limit nicks to 100 characters, add maxlength on connect inputs
This commit is contained in:
Pavel Djundik 2018-10-20 23:08:20 +03:00 committed by GitHub
commit 5b40a6fb58
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 6 deletions

View file

@ -29,13 +29,13 @@
<label for="connect:name">Name</label> <label for="connect:name">Name</label>
</div> </div>
<div class="col-sm-9"> <div class="col-sm-9">
<input class="input" id="connect:name" name="name" value="{{defaults.name}}"> <input class="input" id="connect:name" name="name" value="{{defaults.name}}" maxlength="100">
</div> </div>
<div class="col-sm-3"> <div class="col-sm-3">
<label for="connect:host">Server</label> <label for="connect:host">Server</label>
</div> </div>
<div class="col-sm-6 col-xs-8"> <div class="col-sm-6 col-xs-8">
<input class="input" id="connect:host" name="host" value="{{defaults.host}}" aria-label="Server address" required {{#if lockNetwork}}disabled{{/if}}> <input class="input" id="connect:host" name="host" value="{{defaults.host}}" aria-label="Server address" maxlength="255" required {{#if lockNetwork}}disabled{{/if}}>
</div> </div>
<div class="col-sm-3 col-xs-4"> <div class="col-sm-3 col-xs-4">
<div class="port"> <div class="port">
@ -65,28 +65,28 @@
<label for="connect:nick">Nick</label> <label for="connect:nick">Nick</label>
</div> </div>
<div class="col-sm-9"> <div class="col-sm-9">
<input class="input nick" id="connect:nick" name="nick" value="{{defaults.nick}}" required> <input class="input nick" id="connect:nick" name="nick" value="{{defaults.nick}}" maxlength="100" required>
</div> </div>
{{#unless useHexIp}} {{#unless useHexIp}}
<div class="col-sm-3"> <div class="col-sm-3">
<label for="connect:username">Username</label> <label for="connect:username">Username</label>
</div> </div>
<div class="col-sm-9"> <div class="col-sm-9">
<input class="input username" id="connect:username" name="username" value="{{defaults.username}}"> <input class="input username" id="connect:username" name="username" value="{{defaults.username}}" maxlength="512">
</div> </div>
{{/unless}} {{/unless}}
<div class="col-sm-3"> <div class="col-sm-3">
<label for="connect:password">Password</label> <label for="connect:password">Password</label>
</div> </div>
<div class="col-sm-9 password-container"> <div class="col-sm-9 password-container">
<input class="input" id="connect:password" type="password" name="password" value="{{defaults.password}}"> <input class="input" id="connect:password" type="password" name="password" value="{{defaults.password}}" maxlength="512">
{{> ../reveal-password}} {{> ../reveal-password}}
</div> </div>
<div class="col-sm-3"> <div class="col-sm-3">
<label for="connect:realname">Real name</label> <label for="connect:realname">Real name</label>
</div> </div>
<div class="col-sm-9"> <div class="col-sm-9">
<input class="input" id="connect:realname" name="realname" value="{{defaults.realname}}"> <input class="input" id="connect:realname" name="realname" value="{{defaults.realname}}" maxlength="512">
</div> </div>
{{#if defaults.uuid}} {{#if defaults.uuid}}
<div class="col-sm-3"> <div class="col-sm-3">

View file

@ -64,6 +64,11 @@ 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
if (this.nick && this.nick.length > 100) {
this.nick = this.nick.substring(0, 100);
}
this.setNick(String(this.nick || Helper.getDefaultNick()).replace(" ", "_")); this.setNick(String(this.nick || Helper.getDefaultNick()).replace(" ", "_"));
if (!this.username) { if (!this.username) {

View file

@ -24,6 +24,14 @@ exports.input = function(network, chan, cmd, args) {
const newNick = args[0]; const newNick = args[0];
if (newNick.length > 100) {
chan.pushMessage(this, new Msg({
type: Msg.Type.ERROR,
text: "Nicknames may not be this long.",
}));
return;
}
// If connected to IRC, send to server and wait for ACK // If connected to IRC, send to server and wait for ACK
// otherwise update the nick and UI straight away // otherwise update the nick and UI straight away
if (network.irc && network.irc.connection) { if (network.irc && network.irc.connection) {