Skip to content

refactor(it): static mutable user objects shared across test instances causing race condition - #2474

Open
kumburovicbranko682-boop wants to merge 1 commit into
WebGoat:mainfrom
kumburovicbranko682-boop:contribai/improve/quality/static-mutable-user-objects-shared-acros
Open

kumburovicbranko682-boop wants to merge 1 commit into
WebGoat:mainfrom
kumburovicbranko682-boop:contribai/improve/quality/static-mutable-user-objects-shared-acros

Conversation

@kumburovicbranko682-boop

Copy link
Copy Markdown

✨ Code Quality

Problem

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.

Severity: medium
File: src/it/java/org/owasp/webgoat/playwright/webgoat/helpers/Authentication.java

Solution

Either make the static fields volatile and update them in the login methods, or change the design
to 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:

  1. Discovered by automated code analysis
  2. Generated by AI with context-aware code generation
  3. Self-reviewed by AI quality checks

If you have questions or feedback about this PR, please comment below.
We appreciate your time reviewing this contribution!

Closes #2473

…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
aolle force-pushed the contribai/improve/quality/static-mutable-user-objects-shared-acros branch from 0b00e93 to 6f817c3 Compare August 2, 2026 10:52
@aolle aolle self-assigned this Aug 2, 2026
@aolle

aolle commented Aug 2, 2026

Copy link
Copy Markdown
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

No deployments
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.

fix(it): static mutable user objects shared across test instances causing race condition

2 participants