Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Race Condition in com.microsoft.identity.common.java.authorities.Authority #2554

Open
felgerl opened this issue Dec 9, 2024 · 0 comments
Open

Comments

@felgerl
Copy link

felgerl commented Dec 9, 2024

Hello,

I think I found a race condition in your code:

  • Invoking the com.microsoft.identity.client.PublicClientApplication.create(android.content.Context, String, String, String, com.microsoft.identity.client.IPublicClientApplication.ApplicationCreatedListener) method leads to invocations
    • com.microsoft.identity.common.java.authorities.Authority.getEquivalentConfiguredAuthority([...])
    • com.microsoft.identity.common.java.authorities.Authority.addKnownAuthorities([...])
  • These invocations can occur in different threads, because com.microsoft.identity.client.PublicClientApplication.create([...]) spawns a new thread on each invocation.
  • While getEquivalentConfiguredAuthority iterates over the java.util.ArrayList knownAuthorities instance, addKnownAuthorities inserts elements in the same instance. (knownAuthorities is defined static final.)
  • There is no (effective) synchronization to sequentialize the order of both calls. Hence, iteration and insertion can occur concurrently. This is not supported by java.util.ArrayList. Hence, there is a race condition. With some chance, a java.util.ConcurrentModificationException occurs.

Maybe you want to investigate this, if this is not the intended behavior.

Regards, Luis.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant