Fix security bug with whitelist

Username wasn't sanitized before being used in the regex to check
the whitelist with, so a user named ... (literally three periods)
would be allowed to use the script as long as any user on the list
had a name three characters long. Thanks to MusikAnimal for pointing
this out.
This commit is contained in:
Daniel Glus 2018-07-23 23:56:57 -04:00
parent b9f3b76eee
commit 33d2176754
2 changed files with 11 additions and 5 deletions

View File

@ -101,8 +101,14 @@
var user = AFCH.consts.user,
whitelist = new AFCH.Page( AFCH.consts.whitelistTitle );
whitelist.getText().done( function ( text ) {
// sanitizedUser is user, but escaped for use in the regex.
// Otherwise a user named ... would always be able to use
// the script, so long as there was a user whose name was
// three characters long on the list!
var $howToDisable,
userAllowed = ( new RegExp( '\\|\\s*' + user + '\\s*}' ) ).test( text );
sanitizedUser = user.replace( /[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&' ),
userAllowed = ( new RegExp( '\\|\\s*' + sanitizedUser + '\\s*}' ) ).test( text );
if ( !userAllowed ) {