diff options
author | Joas Schilling <coding@schilljs.com> | 2023-11-30 12:52:35 +0100 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2023-12-07 06:34:11 +0100 |
commit | 2fd8cf4b15f511f866dabacaf788e18e59eff1fd (patch) | |
tree | 46d532ffea30f79c77577af635151602540eee4d /index.php | |
parent | 84af629fa598b340c089c023db665238aee00c38 (diff) | |
download | nextcloud-server-2fd8cf4b15f511f866dabacaf788e18e59eff1fd.tar.gz nextcloud-server-2fd8cf4b15f511f866dabacaf788e18e59eff1fd.zip |
fix(bruteforce-protection): Don't throw a 500 when MaxDelayReached is thrown
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'index.php')
-rw-r--r-- | index.php | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/index.php b/index.php index 7b62f17e5bd..cf6329f6e53 100644 --- a/index.php +++ b/index.php @@ -30,6 +30,8 @@ */ require_once __DIR__ . '/lib/versioncheck.php'; +use OCP\Security\Bruteforce\MaxDelayReached; + try { require_once __DIR__ . '/lib/base.php'; @@ -67,6 +69,21 @@ try { exit(); } OC_Template::printErrorPage($ex->getMessage(), $ex->getMessage(), 401); +} catch (MaxDelayReached $ex) { + $request = \OC::$server->getRequest(); + /** + * Routes with the @CORS annotation and other API endpoints should + * not return a webpage, so we only print the error page when html is accepted, + * otherwise we reply with a JSON array like the BruteForceMiddleware would do. + */ + if (stripos($request->getHeader('Accept'), 'html') === false) { + http_response_code(429); + header('Content-Type: application/json; charset=utf-8'); + echo json_encode(['message' => $ex->getMessage()]); + exit(); + } + http_response_code(429); + OC_Template::printGuestPage('core', '429'); } catch (Exception $ex) { \OC::$server->getLogger()->logException($ex, ['app' => 'index']); |