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

Potential issue with unawaited UpdateClientAssertion event #160

Open
ovska opened this issue Jul 15, 2022 · 5 comments
Open

Potential issue with unawaited UpdateClientAssertion event #160

ovska opened this issue Jul 15, 2022 · 5 comments
Assignees

Comments

@ovska
Copy link

ovska commented Jul 15, 2022

https://github.com/IdentityModel/IdentityModel.AspNetCore.OAuth2Introspection/blob/main/src/OAuth2IntrospectionHandler.cs#L211

The OnUpdateClientAssertion event is invoked without an await, probably because it is inside a lock. This can potentially cause hard to diagnose bugs if the event is assigned to something that requires awaiting. For example the current HttpContext is one of the properties, and using it after the request is ended can throw object disposed exceptions.

My suggestion is to replace the lock with a SemaphoreSlim which works fine in async context as well, and the lifetime of OAuth2IntrospectionOptions shouldn't be a problem as SemaphoreSlim wouldn't need to be disposed in this case.

Tangentially, ConfigureAwait(false) is missing from some all awaits on events. Is this intentional or an oversight?

@leastprivilege
Copy link
Contributor

leastprivilege commented Jul 22, 2022

My understanding is that ASP.NET Core has no synchronization context - so ConfigureAwait(false) is not required.

Would you agree?

@leastprivilege leastprivilege self-assigned this Jul 22, 2022
@ovska
Copy link
Author

ovska commented Jul 24, 2022

Correct, was just wondering why it was used in some awaits and not all :)

@leastprivilege
Copy link
Contributor

I guess because it is ultimately an old code base..

@leastprivilege
Copy link
Contributor

@brockallen could you have a look when time permits.

@ovska do you want to propose a PR?

@ovska
Copy link
Author

ovska commented Aug 7, 2022

Here's more or less the minimal fix I could come up with: #164

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

No branches or pull requests

3 participants