]> BookStack Code Mirror - bookstack/commitdiff
Set a fairly sensible limit on user name validation
authorDan Brown <redacted>
Tue, 9 Aug 2022 11:40:59 +0000 (12:40 +0100)
committerDan Brown <redacted>
Tue, 9 Aug 2022 11:40:59 +0000 (12:40 +0100)
Also updated controller properties with types within modified files.
Related to #3614

app/Http/Controllers/Api/UserApiController.php
app/Http/Controllers/Auth/RegisterController.php
app/Http/Controllers/UserController.php

index 03d2a0f0689b2083e56b66f1606cb0af95b67f98..64e9d732da769496eb93e390e0941b1b77c57ae5 100644 (file)
@@ -36,7 +36,7 @@ class UserApiController extends ApiController
     {
         return [
             'create' => [
-                'name'  => ['required', 'min:2'],
+                'name'  => ['required', 'min:2', 'max:100'],
                 'email' => [
                     'required', 'min:2', 'email', new Unique('users', 'email'),
                 ],
@@ -48,7 +48,7 @@ class UserApiController extends ApiController
                 'send_invite'      => ['boolean'],
             ],
             'update' => [
-                'name'  => ['min:2'],
+                'name'  => ['min:2', 'max:100'],
                 'email' => [
                     'min:2',
                     'email',
index 9399e8b7f53339c373278742800604a3247b5a48..b0aec117791bc1a64fec7ceb713a898099b0353b 100644 (file)
@@ -30,9 +30,9 @@ class RegisterController extends Controller
 
     use RegistersUsers;
 
-    protected $socialAuthService;
-    protected $registrationService;
-    protected $loginService;
+    protected SocialAuthService $socialAuthService;
+    protected RegistrationService $registrationService;
+    protected LoginService $loginService;
 
     /**
      * Where to redirect users after login / registration.
@@ -69,7 +69,7 @@ class RegisterController extends Controller
     protected function validator(array $data)
     {
         return Validator::make($data, [
-            'name'     => ['required', 'min:2', 'max:255'],
+            'name'     => ['required', 'min:2', 'max:100'],
             'email'    => ['required', 'email', 'max:255', 'unique:users'],
             'password' => ['required', Password::default()],
         ]);
index 88d44565c5060b16b60ef8e1453f51b0bf6a5ba5..895481d02405305c80198541883613941a69a13a 100644 (file)
@@ -18,8 +18,8 @@ use Illuminate\Validation\ValidationException;
 
 class UserController extends Controller
 {
-    protected $userRepo;
-    protected $imageRepo;
+    protected UserRepo $userRepo;
+    protected ImageRepo $imageRepo;
 
     /**
      * UserController constructor.
@@ -81,7 +81,7 @@ class UserController extends Controller
         $passwordRequired = ($authMethod === 'standard' && !$sendInvite);
 
         $validationRules = [
-            'name'             => ['required'],
+            'name'             => ['required', 'max:100'],
             'email'            => ['required', 'email', 'unique:users,email'],
             'language'         => ['string', 'max:15', 'alpha_dash'],
             'roles'            => ['array'],
@@ -139,7 +139,7 @@ class UserController extends Controller
         $this->checkPermissionOrCurrentUser('users-manage', $id);
 
         $validated = $this->validate($request, [
-            'name'             => ['min:2'],
+            'name'             => ['min:2', 'max:100'],
             'email'            => ['min:2', 'email', 'unique:users,email,' . $id],
             'password'         => ['required_with:password_confirm', Password::default()],
             'password-confirm' => ['same:password', 'required_with:password'],