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,7 +4,7 @@ namespace App\Util\Lexer;
class RestrictedNames
{
public static $blacklist = [
public static $additional = [
'autoconfig',
'blog',
'broadcasthost',
@ -294,16 +294,18 @@ class RestrictedNames
public static function get()
{
$reserved = $blacklist = [];
$banned = [];
if (true == config('pixelfed.restricted_names.use_blacklist')) {
$blacklist = self::$blacklist;
if(config('instance.username.banned')) {
$banned = array_map('trim', explode(',', config('instance.username.banned')));
}
if (true == config('pixelfed.restricted_names.reserved_routes')) {
$additional = self::$additional;
$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' => [
'banned' => env('BANNED_USERNAMES'),
'remote' => [
'formats' => ['@', 'from', 'custom'],
'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'),
/*
|--------------------------------------------------------------------------
| 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
@ -278,4 +264,6 @@ return [
'admin' => [
'env_editor' => env('ADMIN_ENV_EDITOR', false)
],
'links_per_post' => env('MAX_LINKS_PER_POST', 0)
];