-
Notifications
You must be signed in to change notification settings - Fork 415
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
Dispose object in JsonWebTokenHandler.CreateToken.cs #3064
Dispose object in JsonWebTokenHandler.CreateToken.cs #3064
Conversation
var kwp = key.CryptoProviderFactory.CreateKeyWrapProviderForUnwrap(); 'kwp' becomes out of scope and is not disposed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 1 out of 1 changed files in this pull request and generated no comments.
@@ -1365,15 +1365,15 @@ internal IEnumerable<SecurityKey> GetContentEncryptionKeys(JsonWebToken jwtToken | |||
jwtToken.TryGetHeaderValue(JwtHeaderParameterNames.Apu, out string apu); | |||
jwtToken.TryGetHeaderValue(JwtHeaderParameterNames.Apv, out string apv); | |||
SecurityKey kdf = ecdhKeyExchangeProvider.GenerateKdf(apu, apv); | |||
var kwp = key.CryptoProviderFactory.CreateKeyWrapProviderForUnwrap(kdf, ecdhKeyExchangeProvider.GetEncryptionAlgorithm()); | |||
using var kwp = key.CryptoProviderFactory.CreateKeyWrapProviderForUnwrap(kdf, ecdhKeyExchangeProvider.GetEncryptionAlgorithm()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is the right change - we shouldn't dispose here.
CryptoProviderFactory.CreateKeyWrapProviderForUnwrap
ends up calling CustomCryptoProvider.Create
if it was set. CustomCryptoProvider
implements ICryptoProvider
which has a Create
and a Release
. So the interface intends for the creator to release the provider.
The more appropriate change would probably be to call CryptoProviderFactory.ReleaseKeyWrapProvider
maybe in the finally
.
Base on comments from: AzureAD#3064
Based on comments from: AzureAD#3064
var kwp = key.CryptoProviderFactory.CreateKeyWrapProviderForUnwrap();
'kwp' becomes out of scope and is not disposed.