]> BookStack Code Mirror - bookstack/commitdiff
Registration: Reviewed added simple honeypot, added testing
authorDan Brown <redacted>
Sat, 4 May 2024 12:59:41 +0000 (13:59 +0100)
committerDan Brown <redacted>
Sat, 4 May 2024 12:59:41 +0000 (13:59 +0100)
Also cleaned up old RegistrationController syntax.
Review of #4970

app/Access/Controllers/RegisterController.php
resources/views/auth/register.blade.php
tests/Auth/RegistrationTest.php

index 25b0a30366a97ef25bebfe10d2fc1c0babe857f7..e9812aa5d0627cb219f9060dec94e770d1fa167a 100644 (file)
@@ -15,24 +15,13 @@ use Illuminate\Validation\Rules\Password;
 
 class RegisterController extends Controller
 {
-    protected SocialDriverManager $socialDriverManager;
-    protected RegistrationService $registrationService;
-    protected LoginService $loginService;
-
-    /**
-     * Create a new controller instance.
-     */
     public function __construct(
-        SocialDriverManager $socialDriverManager,
-        RegistrationService $registrationService,
-        LoginService $loginService
+        protected SocialDriverManager $socialDriverManager,
+        protected RegistrationService $registrationService,
+        protected LoginService $loginService
     ) {
         $this->middleware('guest');
         $this->middleware('guard:standard');
-
-        $this->socialDriverManager = $socialDriverManager;
-        $this->registrationService = $registrationService;
-        $this->loginService = $loginService;
     }
 
     /**
@@ -87,7 +76,8 @@ class RegisterController extends Controller
             'name'     => ['required', 'min:2', 'max:100'],
             'email'    => ['required', 'email', 'max:255', 'unique:users'],
             'password' => ['required', Password::default()],
-            'username' => ['prohibited'], // this is a honeypot for bots that must not be filled in
+            // Basic honey for bots that must not be filled in
+            'username' => ['prohibited'],
         ]);
     }
 }
index f9f4e8cb3d568f4b8592fd56077043ede17f339c..1ea712e1d0aa8d6fd00626bc7ad77ed7679024a6 100644 (file)
@@ -13,8 +13,9 @@
             <form action="{{ url("/register") }}" method="POST" class="mt-l stretch-inputs">
                 {!! csrf_field() !!}
 
+                {{-- Simple honeypot field --}}
                 <div class="form-group ambrosia-container" aria-hidden="true">
-                    <label for="name">{{ trans('auth.name') }}</label>
+                    <label for="username">{{ trans('auth.name') }}</label>
                     @include('form.text', ['name' => 'username'])
                 </div>
 
index ff1a9d66b11b8ad942490189ffe9b61dfde9e992..60ae17573eb1560df60d0f34ea4dfda1c96183f9 100644 (file)
@@ -184,4 +184,23 @@ class RegistrationTest extends TestCase
         $resp->assertSee('The email must be a valid email address.');
         $resp->assertSee('The password must be at least 8 characters.');
     }
+
+    public function test_registration_simple_honeypot_active()
+    {
+        $this->setSettings(['registration-enabled' => 'true']);
+
+        $resp = $this->get('/register');
+        $this->withHtml($resp)->assertElementExists('form input[name="username"]');
+
+        $resp = $this->post('/register', [
+            'name' => 'Barry',
+            'email' => 'barrybot@example.com',
+            'password' => 'barryIsTheBestBot',
+            'username' => 'MyUsername'
+        ]);
+        $resp->assertRedirect('/register');
+
+        $resp = $this->followRedirects($resp);
+        $this->withHtml($resp)->assertElementExists('form input[name="username"].text-neg');
+    }
 }
Morty Proxy This is a proxified and sanitized view of the page, visit original site.