From 2c5a516aefa065cc785dbc8020b815a080deeddc Mon Sep 17 00:00:00 2001 From: William Jacoby Date: Tue, 10 Nov 2026 13:45:23 -0600 Subject: [PATCH] Skip failed-login logging when the result has no user_row login_box() builds a result with only status and error_msg when the login form key check fails. With "Log failed login attempts" enabled, log_failed_login_attempts() then read $event['result']['user_row'] and raised undefined array key warnings on PHP 8. Check isset() first, as the master branch already does, and add a regression test. Co-Authored-By: Claude Opus 5.5 --- event/listener.php | 3 ++- tests/event/failed_logins_test.php | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/event/listener.php b/event/listener.php index 2c6ebc3..a4c4edd 100644 --- a/event/listener.php +++ b/event/listener.php @@ -185,7 +185,8 @@ public function log_failed_login_attempts($event) return; } - if ($this->in_watch_group($event['result']['user_row']['user_id'])) + // A failed login form key check returns a result without user_row + if (isset($event['result']['user_row']) && $this->in_watch_group($event['result']['user_row']['user_id'])) { $this->log->add('user', $event['result']['user_row']['user_id'], $this->user->ip, 'LOG_TEAM_AUTH_FAIL', time(), array('reportee_id' => $event['result']['user_row']['user_id'])); } diff --git a/tests/event/failed_logins_test.php b/tests/event/failed_logins_test.php index 41d3ab9..ed098dc 100644 --- a/tests/event/failed_logins_test.php +++ b/tests/event/failed_logins_test.php @@ -56,4 +56,33 @@ public function test_log_failed_login_attempts($enabled, $in_watch_group, $resul $event_data = array('result'); $dispatcher->trigger_event('core.login_box_failed', compact($event_data)); } + + /** + * Test a failed login without user data (invalid login form key) is ignored + * without raising undefined index warnings + */ + public function test_log_failed_login_attempts_without_user_row() + { + $this->config = new \phpbb\config\config(array( + 'sec_login_attempts' => true, + )); + + $this->set_listener(); + + $this->listener->expects(self::never()) + ->method('in_watch_group'); + + $this->log->expects(self::never()) + ->method('add'); + + $dispatcher = new \phpbb\event\dispatcher(); + $dispatcher->addListener('core.login_box_failed', array($this->listener, 'log_failed_login_attempts')); + + $result = array( + 'status' => false, + 'error_msg' => 'FORM_INVALID', + ); + $event_data = array('result'); + $dispatcher->trigger_event('core.login_box_failed', compact($event_data)); + } }