refactor(it): static mutable user objects shared across test instances causing race condition - #2474
Open
kumburovicbranko682-boop wants to merge 1 commit into
Conversation
…s causing race condition The `sylvester` and `tweety` fields are static mutable `User` instances initialized with `auth = null`. The `login()` method checks `user.loggedIn()` (which returns true if `auth != null`) but returns a NEW User instance with the auth state, without updating the original static field. This means: 1. In parallel test execution, multiple threads could call `sylvester(browser)` simultaneously 2. Each call sees `auth == null` and creates a new registration + login flow 3. The first call returns and updates `auth` in its local copy, but the static field remains null 4. All subsequent calls still see `auth == null` and repeat registration This causes test flakiness due to race conditions on WebGoat's user database and wastes resources by creating multiple browser contexts/pages when only one was intended. Affected files: Authentication.java Signed-off-by: kumburovicbranko682-boop <295886834+kumburovicbranko682-boop@users.noreply.github.com>
aolle
force-pushed
the
contribai/improve/quality/static-mutable-user-objects-shared-acros
branch
from
August 2, 2026 10:52
0b00e93 to
6f817c3
Compare
Collaborator
|
Please ensure the test suite passes before submitting the PR for review. I'll take another look once CI is green. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
✨ Code Quality
Problem
The
sylvesterandtweetyfields are static mutableUserinstances initialized withauth = null.The
login()method checksuser.loggedIn()(which returns true ifauth != null) but returns a NEWUser instance with the auth state, without updating the original static field. This means:
sylvester(browser)simultaneouslyauth == nulland creates a new registration + login flowauthin its local copy, but the static field remains nullauth == nulland repeat registrationThis causes test flakiness due to race conditions on WebGoat's user database and wastes resources
by creating multiple browser contexts/pages when only one was intended.
Severity:
mediumFile:
src/it/java/org/owasp/webgoat/playwright/webgoat/helpers/Authentication.javaSolution
Either make the static fields
volatileand update them in the login methods, or change the designto avoid shared mutable state. The simplest fix is to update the static fields:
Changes
src/it/java/org/owasp/webgoat/playwright/webgoat/helpers/Authentication.java(modified)Thank you for submitting a pull request to the WebGoat!
🤖 About this PR
This pull request was generated by ContribAI, an AI agent
that helps improve open source projects. The change was:
If you have questions or feedback about this PR, please comment below.
We appreciate your time reviewing this contribution!
Closes #2473