Add BANNED_USERNAMES env var support to RestrictedNames

This commit is contained in:
Daniel Supernault 2020-01-16 23:07:58 -07:00
parent be75a19260
commit 6cdd64c669
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
3 changed files with 299 additions and 308 deletions

View file

@ -4,306 +4,308 @@ namespace App\Util\Lexer;
class RestrictedNames class RestrictedNames
{ {
public static $blacklist = [ public static $additional = [
'autoconfig', 'autoconfig',
'blog', 'blog',
'broadcasthost', 'broadcasthost',
'copyright', 'copyright',
'download', 'download',
'domainadmin', 'domainadmin',
'domainadministrator', 'domainadministrator',
'errors', 'errors',
'events', 'events',
'example', 'example',
'faq', 'faq',
'faqs', 'faqs',
'features', 'features',
'ftp', 'ftp',
'guest', 'guest',
'guests', 'guests',
'hostmaster', 'hostmaster',
'hostmaster', 'hostmaster',
'imap', 'imap',
'info', 'info',
'information', 'information',
'is', 'is',
'isatap', 'isatap',
'it', 'it',
'localdomain', 'localdomain',
'localhost', 'localhost',
'mail', 'mail',
'mailer-daemon', 'mailer-daemon',
'mailerdaemon', 'mailerdaemon',
'marketing', 'marketing',
'me', 'me',
'mis', 'mis',
'mx', 'mx',
'no-reply', 'no-reply',
'nobody', 'nobody',
'noc', 'noc',
'noreply', 'noreply',
'ns0', 'ns0',
'ns1', 'ns1',
'ns2', 'ns2',
'ns3', 'ns3',
'ns4', 'ns4',
'ns5', 'ns5',
'ns6', 'ns6',
'ns7', 'ns7',
'ns8', 'ns8',
'ns9', 'ns9',
'owner', 'owner',
'pop', 'pop',
'pop3', 'pop3',
'postmaster', 'postmaster',
'pricing', 'pricing',
'root', 'root',
'sales', 'sales',
'security', 'security',
'signin', 'signin',
'signout', 'signout',
'smtp', 'smtp',
'src', 'src',
'ssladmin', 'ssladmin',
'ssladministrator', 'ssladministrator',
'sslwebmaster', 'sslwebmaster',
'sys', 'sys',
'sysadmin', 'sysadmin',
'system', 'system',
'tutorial', 'tutorial',
'tutorials', 'tutorials',
'usenet', 'usenet',
'uucp', 'uucp',
'webmaster', 'webmaster',
'wpad', 'wpad',
]; ];
public static $reserved = [ public static $reserved = [
// Reserved for instance admin // Reserved for instance admin
'admin', 'admin',
'administrator', 'administrator',
// Static Assets // Static Assets
'assets', 'assets',
'storage', 'storage',
// Laravel Horizon // Laravel Horizon
'horizon', 'horizon',
// Reserved routes // Reserved routes
'a', 'a',
'app', 'app',
'about', 'about',
'aboutus', 'aboutus',
'about-us', 'about-us',
'abuse', 'abuse',
'account', 'account',
'admins', 'admins',
'api', 'api',
'audio', 'audio',
'auth', 'auth',
'b', 'b',
'bartender', 'bartender',
'broadcast', 'broadcast',
'broadcaster', 'broadcaster',
'booth', 'booth',
'bouncer', 'bouncer',
'c', 'c',
'cdn', 'cdn',
'circle', 'circle',
'circles', 'circles',
'checkpoint', 'checkpoint',
'collection', 'collection',
'collections', 'collections',
'community', 'community',
'communities', 'communities',
'contact', 'contact',
'contact-us', 'contact-us',
'contact_us', 'contact_us',
'costar', 'costar',
'costars', 'costars',
'css', 'css',
'd', 'd',
'dashboard', 'dashboard',
'dmca', 'dmca',
'db', 'db',
'deck', 'deck',
'dev', 'dev',
'developer', 'developer',
'developers', 'developers',
'discover', 'discover',
'discovers', 'discovers',
'dj', 'dj',
'doc', 'doc',
'docs', 'docs',
'docs', 'docs',
'drive', 'drive',
'drives', 'drives',
'driver', 'driver',
'e', 'e',
'email', 'email',
'emails', 'emails',
'error', 'error',
'explore', 'explore',
'export', 'export',
'exports', 'exports',
'f', 'f',
'feed', 'feed',
'font', 'font',
'fonts', 'fonts',
'follow', 'follow',
'follows', 'follows',
'followme', 'followme',
'follow-me', 'follow-me',
'follow_me', 'follow_me',
'g', 'g',
'gdpr', 'gdpr',
'graph', 'graph',
'ghost', 'ghost',
'ghosts', 'ghosts',
'group', 'group',
'groups', 'groups',
'h', 'h',
'home', 'home',
'help', 'help',
'helpcenter', 'helpcenter',
'help-center', 'help-center',
'help_center', 'help_center',
'help_center_', 'help_center_',
'help-center-', 'help-center-',
'help-center_', 'help-center_',
'help_center-', 'help_center-',
'i', 'i',
'img', 'img',
'imgs', 'imgs',
'image', 'image',
'images', 'images',
'invite', 'invite',
'invites', 'invites',
'import', 'import',
'imports', 'imports',
'j', 'j',
'js', 'js',
'k', 'k',
'key', 'key',
'l', 'l',
'lab', 'lab',
'labs', 'labs',
'legal', 'legal',
'live', 'live',
'loop', 'loop',
'loops', 'loops',
'location', 'location',
'locations', 'locations',
'login', 'login',
'logout', 'logout',
'm', 'm',
'media', 'media',
'menu', 'menu',
'music', 'music',
'n', 'n',
'news', 'news',
'new', 'new',
'news', 'news',
'news', 'news',
'newsfeed', 'newsfeed',
'newsroom', 'newsroom',
'newsrooms', 'newsrooms',
'news-room', 'news-room',
'news-rooms', 'news-rooms',
'o', 'o',
'oauth', 'oauth',
'official', 'official',
'p', 'p',
'page', 'page',
'pages', 'pages',
'pin', 'pin',
'pins', 'pins',
'photo', 'photo',
'photos', 'photos',
'password', 'password',
'privacy', 'privacy',
'private', 'private',
'q', 'q',
'quote', 'quote',
'query', 'query',
'r', 'r',
'register', 'register',
'registers', 'registers',
'review', 'review',
'reset', 'reset',
'report', 'report',
'results', 'results',
'reports', 'reports',
'robot', 'robot',
'robots', 'robots',
's', 's',
'search', 'search',
'sell', 'sell',
'send', 'send',
'settings', 'settings',
'status', 'status',
'statuses', 'statuses',
'site', 'site',
'sites', 'sites',
'stage', 'stage',
'static', 'static',
'story', 'story',
'stories', 'stories',
'support', 'support',
'svg', 'svg',
'svgs', 'svgs',
't', 't',
'terms', 'terms',
'telescope', 'telescope',
'timeline', 'timeline',
'timelines', 'timelines',
'tour', 'tour',
'tv', 'tv',
'u', 'u',
'user', 'user',
'users', 'users',
'username', 'username',
'usernames', 'usernames',
'v', 'v',
'valet', 'valet',
'video', 'video',
'videos', 'videos',
'vendor', 'vendor',
'w', 'w',
'waiter', 'waiter',
'wall', 'wall',
'whats-new', 'whats-new',
'whatsnew', 'whatsnew',
'whatnew', 'whatnew',
'whats-news', 'whats-news',
'ws', 'ws',
'wss', 'wss',
'www', 'www',
'x', 'x',
'y', 'y',
'z', 'z',
'400', '400',
'401', '401',
'403', '403',
'404', '404',
'500', '500',
'503', '503',
'504', '504',
]; ];
public static function get() public static function get()
{ {
$reserved = $blacklist = []; $banned = [];
if (true == config('pixelfed.restricted_names.use_blacklist')) { if(config('instance.username.banned')) {
$blacklist = self::$blacklist; $banned = array_map('trim', explode(',', config('instance.username.banned')));
} }
if (true == config('pixelfed.restricted_names.reserved_routes')) { $additional = self::$additional;
$reserved = self::$reserved; $reserved = self::$reserved;
}
return array_merge($blacklist, $reserved); $res = array_merge($additional, $reserved, $banned);
} sort($res);
return $res;
}
} }

View file

@ -41,6 +41,7 @@ return [
] ]
], ],
'username' => [ 'username' => [
'banned' => env('BANNED_USERNAMES'),
'remote' => [ 'remote' => [
'formats' => ['@', 'from', 'custom'], 'formats' => ['@', 'from', 'custom'],
'format' => in_array(env('USERNAME_REMOTE_FORMAT', '@'), ['@','from','custom']) ? env('USERNAME_REMOTE_FORMAT', '@') : '@', 'format' => in_array(env('USERNAME_REMOTE_FORMAT', '@'), ['@','from','custom']) ? env('USERNAME_REMOTE_FORMAT', '@') : '@',

View file

@ -48,20 +48,6 @@ return [
*/ */
'memory_limit' => env('MEMORY_LIMIT', '1024M'), 'memory_limit' => env('MEMORY_LIMIT', '1024M'),
/*
|--------------------------------------------------------------------------
| Restricted Usernames
|--------------------------------------------------------------------------
|
| Optional blacklist to prevent registering usernames that could
| be confused for admin or system services.
|
*/
'restricted_names' => [
'reserved_routes' => true,
'use_blacklist' => env('USERNAME_BLACKLIST', false),
],
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
| Allow New Registrations | Allow New Registrations
@ -278,4 +264,6 @@ return [
'admin' => [ 'admin' => [
'env_editor' => env('ADMIN_ENV_EDITOR', false) 'env_editor' => env('ADMIN_ENV_EDITOR', false)
], ],
'links_per_post' => env('MAX_LINKS_PER_POST', 0)
]; ];