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

Add .NET 8.0 TFM and use new AesGcm constructor #248

Closed
zzyzy opened this issue Jul 9, 2024 · 6 comments
Closed

Add .NET 8.0 TFM and use new AesGcm constructor #248

zzyzy opened this issue Jul 9, 2024 · 6 comments

Comments

@zzyzy
Copy link
Contributor

zzyzy commented Jul 9, 2024

A penetration testing reported indicated that decrypting JWE with truncated authentication tag still works without throwing exception.

After researching further, found that the issue is due to how .NET AesGcm class works (from System.Security.Cryptography namespace) prior to .NET 8.0. (see dotnet/runtime#71366).

To remediate the findings:

  1. Add .NET 8.0 TFM
  2. Update AesGcmNetCore.cs to use new System.Security.Cryptography.AesGcm constructor by specifying the tag size
  3. Add unit test to validate the new changes

Example JWE: eyJhbGciOiJFQ0RILUVTK0EyNTZLVyIsImVwayI6eyJrdHkiOiJFQyIsIngiOiJ4ZUNycEg3MS1RbnBpT0htVVVEaWh1bGRyN3BqSGtPVVRuUXZTUzRpUEc4IiwieSI6InYtbHVhNldrS3ZFYThzQm4xRTFHNjdfRUZEaTRHVkZNWE13YjZZdXl4LWMiLCJjcnYiOiJQLTI1NiJ9LCJlbmMiOiJBMjU2R0NNIn0.V1Fv0OIeukGSMYIwFwfdnqllTzW-e-KgXTj0w0MYmbr14PLx8NhSvg.4YK1emgVFKcdsS55.2ol-hLJuZNSSgyb3JuyFaGKAjJfHw4fGit8gkqFVQCVM1T8EhsEwezH9MtL6BwKUJCbrEglNeloMG2ScYT_GeTUI_-8mh_s6rdv8gioSRoBpe-PGkXax0FaMskGasMWR3tFWJ9rZ4KzZ_Wi5BvpVsIe5fEoWUluW3QbGn5IudNb26iaCXestMURCo_nxLs52quKqN_Xz_U5PDRMGF1Zcjmpmk-uIRBILan11oNC39rDzqxwZ9OBB16KuXXjRgDYzfczg1I6B1-FwNwdeLOViQWSH2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pyvkCvcERVkdhiS4f0fwMIRPE32kC7GXo2xc38SPHyDeAd4RCfOvqBJ1WLM0kwb17rODJUV4Ycb5TkAYcb3NGJmwGFQo_XpzKhHCwYPnBWXInyIl4MjiCZ062brYRho20EuTDzaBKQPhsuXavOsRSxrBCS9qOMvO9E.dyLFkX5Rb-cGg3STAC-7 (removed Bg)

Both of the above JWE will be decrypted successfully. The second JWE should throw exception.

@dvsekhvalnov
Copy link
Owner

Hi @zzyzy ,

thanks for reporting, interesting one. Give me sometime to to review PR and vulnerability in general.

@dvsekhvalnov
Copy link
Owner

I see there is wrapper proposed in a thread you linked: https://github.com/sdrapkin/SecurityDriven.AesGcmStrict that just checks byte length of tag.

Sounds like can be better solution to replicate it in code for all supported .net versions then having fix for .net 8+ and leave others open to potential vulnerability?

@zzyzy
Copy link
Contributor Author

zzyzy commented Sep 30, 2024

I see there is wrapper proposed in a thread you linked: https://github.com/sdrapkin/SecurityDriven.AesGcmStrict that just checks byte length of tag.

Sounds like can be better solution to replicate it in code for all supported .net versions then having fix for .net 8+ and leave others open to potential vulnerability?

Good point. I've made the change. Thank you.

@dvsekhvalnov
Copy link
Owner

Hey @zzyzy, will take when back from PTO. Thank you.

@dvsekhvalnov
Copy link
Owner

@zzyzy i copied your fix to #255 as it was slightly easier from code management standpoint. Will go to the next release soonish.

Thanks for contribution.

@dvsekhvalnov
Copy link
Owner

v5.1.0 released to nuget.

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

Successfully merging a pull request may close this issue.

2 participants