]> source.dussan.org Git - nextcloud-server.git/commitdiff
feat(security): Add a "testing mode" for bruteforce protection that doesn't sleep
authorJoas Schilling <coding@schilljs.com>
Mon, 14 Aug 2023 16:59:50 +0000 (18:59 +0200)
committerJoas Schilling <coding@schilljs.com>
Mon, 21 Aug 2023 14:36:03 +0000 (16:36 +0200)
Signed-off-by: Joas Schilling <coding@schilljs.com>
config/config.sample.php
lib/private/Security/Bruteforce/Throttler.php

index 210d0a8e8ce34b8cc85d5e1e56cdb702f25b6c68..77783021939ac139f9bc7be66acd3520564e75c4 100644 (file)
@@ -352,6 +352,19 @@ $CONFIG = [
  */
 'auth.bruteforce.protection.enabled' => true,
 
+/**
+ * Whether the bruteforce protection shipped with Nextcloud should be set to testing mode.
+ *
+ * In testing mode bruteforce attempts are still recorded, but the requests do
+ * not sleep/wait for the specified time. They will still abort with
+ * "429 Too Many Requests" when the maximum delay is reached.
+ * Enabling this is discouraged for security reasons
+ * and should only be done for debugging and on CI when running tests.
+ *
+ * Defaults to ``false``
+ */
+'auth.bruteforce.protection.testing' => false,
+
 /**
  * Whether the rate limit protection shipped with Nextcloud should be enabled or not.
  *
index cfd88801fcfd1b746e99770db4e3323040117751..2ee4c23cd1ef67b753d10267df34ba1219b7e92c 100644 (file)
@@ -280,7 +280,9 @@ class Throttler implements IThrottler {
         */
        public function sleepDelay(string $ip, string $action = ''): int {
                $delay = $this->getDelay($ip, $action);
-               usleep($delay * 1000);
+               if (!$this->config->getSystemValueBool('auth.bruteforce.protection.testing')) {
+                       usleep($delay * 1000);
+               }
                return $delay;
        }
 
@@ -304,7 +306,9 @@ class Throttler implements IThrottler {
                                'delay' => $delay,
                        ]);
                }
-               usleep($delay * 1000);
+               if (!$this->config->getSystemValueBool('auth.bruteforce.protection.testing')) {
+                       usleep($delay * 1000);
+               }
                return $delay;
        }
 }