8000 Handle async processing of the brute force detection when counting login failures by ahus1 · Pull Request #52429 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Handle async processing of the brute force detection when counting login failures - #52429

Merged
stianst merged 1 commit into
keycloak:mainfrom
ahus1:is-52428-stabilize-AttackDetectionResourceTest
Sep 7, 2026
Merged

stianst merged 1 commit into
keycloak:mainfrom
ahus1:is-52428-stabilize-AttackDetectionResourceTest

Conversation

@ahus1
@ahus1 ahus1 commented Sep 4, 2026 •
Copy link
Copy Markdown
Member

Closes #52428

Summary

Stabilizes AttackDetectionResourceTest.test by waiting for each brute force failure to be fully processed before sending the next login request for the same user.

Root cause

DefaultBlockingBruteForceProtector tracks concurrent login attempts per user in a loginAttempts map. When a second request for the same user arrives while the first is still being processed:

  1. isTemporarilyDisabled() returns true (login in progress)
  2. ValidateUsername calls context.forceChallenge() (not failureChallenge())
  3. FORCE_CHALLENGE does not call logFailure() / failedLogin() (unlike FAILURE_CHALLENGE)
  4. The failure counter is never incremented for the blocked request

This means numFailures stays at 1 instead of reaching the expected 2 — permanently, not just slowly. Increasing the awaitility timeout would not help.

Fix

After sending each login request, poll bruteForceUserStatus until numFailures reaches the expected value before sending the next request for the same user. This ensures the async executor task has completed and the loginAttempts entry has been cleared.

For testUser (3 requests, failureFactor=2):

  • Request 1 → wait for numFailures=1
  • Request 2 → wait for numFailures=2 (user is now locked)
  • Request 3 → user is temporarily disabled by the real lockout, no counter increment expected

For testUser2 (2 requests):

  • Request 1 → wait for numFailures=1
  • Request 2 → counter increments to 2

These waits can be removed once brute force processing is synchronous (#52128).

…gin failures

Closes keycloak#52428

Signed-off-by: Alexander Schwartz <alexander.schwartz@ibm.com>
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused test change correctly addresses the documented race without altering production behavior.

Pull request overview

Stabilizes the brute-force detection integration test by waiting for asynchronous failure processing between login attempts.

Changes:

  • Adds per-user failure-count waits between requests.
  • Extracts polling into awaitNumFailures.
File summaries
File Description
tests/base/src/test/java/org/keycloak/tests/admin/AttackDetectionResourceTest.java Prevents concurrent login attempts from racing with failure processing.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 0
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

8000

@ahus1
ahus1 marked this pull request as ready for review September 4, 2026 10:59
@ahus1
ahus1 requested a review from a team as a code owner September 4, 2026 10:59
@stianst
stianst merged commit e835e65 into keycloak:main Sep 7, 2026
94 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flaky test: AttackDetectionResourceTest due to DefaultBlockingBruteForceProtector concurrent login blocking

4 participants

0