-
Notifications
You must be signed in to change notification settings - Fork 375
Avoid using the same digest across calls #697
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
Conversation
JWT appears to reuse these JWA instances across threads, which can lead to them stepping on each other via the shared OpenSSL::Digest instance. This causes decoding to fail verification, likely because the digest contains an amalgam of data from the different threads. This patch creates a new OpenSSL::Digest for each use, avoiding the threading issue. Note that the HMAC JWA already calls OpenSSL::HMAC.digest, avoiding the shared state, and the others do not use digest. The original code does not fail on CRuby most likely because only one thread at a time can be calculating a digest against a given OpenSSL::Digest instance, due to the VM lock. Fixes jwt#696 Addresses the issue reported in jruby/jruby#8504 by @mohamedhafez
|
Some variation of the script provided in #696 could probably be adapted as a test for the ECDSA part of the fix. I am not familiar enough with the libraries involved to know how to modify that script to test the RSA part of the fix. |
|
I've adapted the #696 example for an ECDSA test. |
|
Looks solid @headius and thanks for the fix. If you would address the issues raised by the robot we are good to go. |
|
Re-enabled the Truffleruby CI step in #698. I can confirm that the provided spec is indeed failing for that. |
|
I will fix the Rubocop issues and ping you when that's ready. I am curious... why no JRuby in the test matrix before? I'll add it, but it is troubling that it wasn't there to begin with. |
|
Well, I guess I answered my own question... there are just a few failures running on JRuby, and something that appears to hang. I will look into those separately from this PR (at some point). I've made the Rubocop changes and this should now be ready to go. |
|
Thanks for the fix @headius. The fix is included in the latest patch release. Cannot remember if there has been any specific reason there is no jruby in the CI matrix. If it's possible to get it there i'm all for it. |
* Avoid using the same digest across calls JWT appears to reuse these JWA instances across threads, which can lead to them stepping on each other via the shared OpenSSL::Digest instance. This causes decoding to fail verification, likely because the digest contains an amalgam of data from the different threads. This patch creates a new OpenSSL::Digest for each use, avoiding the threading issue. Note that the HMAC JWA already calls OpenSSL::HMAC.digest, avoiding the shared state, and the others do not use digest. The original code does not fail on CRuby most likely because only one thread at a time can be calculating a digest against a given OpenSSL::Digest instance, due to the VM lock. Fixes jwt#696 Addresses the issue reported in jruby/jruby#8504 by @mohamedhafez * Add jwt#697 to changelog * Modify Rsa digest name test for new structure The @digest instance variable now contains the name to the digest to be used. See jwt#697 * Add test for concurrent encode/decode using ECDSA This is adapted from the script in jwt#696 and provides a test for the ECDSA part of the fix in jwt#697. * Fixes for Rubocop
* Avoid using the same digest across calls JWT appears to reuse these JWA instances across threads, which can lead to them stepping on each other via the shared OpenSSL::Digest instance. This causes decoding to fail verification, likely because the digest contains an amalgam of data from the different threads. This patch creates a new OpenSSL::Digest for each use, avoiding the threading issue. Note that the HMAC JWA already calls OpenSSL::HMAC.digest, avoiding the shared state, and the others do not use digest. The original code does not fail on CRuby most likely because only one thread at a time can be calculating a digest against a given OpenSSL::Digest instance, due to the VM lock. Fixes jwt#696 Addresses the issue reported in jruby/jruby#8504 by @mohamedhafez * Add jwt#697 to changelog * Modify Rsa digest name test for new structure The @digest instance variable now contains the name to the digest to be used. See jwt#697 * Add test for concurrent encode/decode using ECDSA This is adapted from the script in jwt#696 and provides a test for the ECDSA part of the fix in jwt#697. * Fixes for Rubocop
* Avoid using the same digest across calls JWT appears to reuse these JWA instances across threads, which can lead to them stepping on each other via the shared OpenSSL::Digest instance. This causes decoding to fail verification, likely because the digest contains an amalgam of data from the different threads. This patch creates a new OpenSSL::Digest for each use, avoiding the threading issue. Note that the HMAC JWA already calls OpenSSL::HMAC.digest, avoiding the shared state, and the others do not use digest. The original code does not fail on CRuby most likely because only one thread at a time can be calculating a digest against a given OpenSSL::Digest instance, due to the VM lock. Fixes jwt#696 Addresses the issue reported in jruby/jruby#8504 by @mohamedhafez * Add jwt#697 to changelog * Modify Rsa digest name test for new structure The @digest instance variable now contains the name to the digest to be used. See jwt#697 * Add test for concurrent encode/decode using ECDSA This is adapted from the script in jwt#696 and provides a test for the ECDSA part of the fix in jwt#697. * Fixes for Rubocop
* Avoid using the same digest across calls JWT appears to reuse these JWA instances across threads, which can lead to them stepping on each other via the shared OpenSSL::Digest instance. This causes decoding to fail verification, likely because the digest contains an amalgam of data from the different threads. This patch creates a new OpenSSL::Digest for each use, avoiding the threading issue. Note that the HMAC JWA already calls OpenSSL::HMAC.digest, avoiding the shared state, and the others do not use digest. The original code does not fail on CRuby most likely because only one thread at a time can be calculating a digest against a given OpenSSL::Digest instance, due to the VM lock. Fixes jwt#696 Addresses the issue reported in jruby/jruby#8504 by @mohamedhafez * Add jwt#697 to changelog * Modify Rsa digest name test for new structure The @digest instance variable now contains the name to the digest to be used. See jwt#697 * Add test for concurrent encode/decode using ECDSA This is adapted from the script in jwt#696 and provides a test for the ECDSA part of the fix in jwt#697. * Fixes for Rubocop
* Avoid using the same digest across calls JWT appears to reuse these JWA instances across threads, which can lead to them stepping on each other via the shared OpenSSL::Digest instance. This causes decoding to fail verification, likely because the digest contains an amalgam of data from the different threads. This patch creates a new OpenSSL::Digest for each use, avoiding the threading issue. Note that the HMAC JWA already calls OpenSSL::HMAC.digest, avoiding the shared state, and the others do not use digest. The original code does not fail on CRuby most likely because only one thread at a time can be calculating a digest against a given OpenSSL::Digest instance, due to the VM lock. Fixes jwt#696 Addresses the issue reported in jruby/jruby#8504 by @mohamedhafez * Add jwt#697 to changelog * Modify Rsa digest name test for new structure The @digest instance variable now contains the name to the digest to be used. See jwt#697 * Add test for concurrent encode/decode using ECDSA This is adapted from the script in jwt#696 and provides a test for the ECDSA part of the fix in jwt#697. * Fixes for Rubocop
* Avoid using the same digest across calls JWT appears to reuse these JWA instances across threads, which can lead to them stepping on each other via the shared OpenSSL::Digest instance. This causes decoding to fail verification, likely because the digest contains an amalgam of data from the different threads. This patch creates a new OpenSSL::Digest for each use, avoiding the threading issue. Note that the HMAC JWA already calls OpenSSL::HMAC.digest, avoiding the shared state, and the others do not use digest. The original code does not fail on CRuby most likely because only one thread at a time can be calculating a digest against a given OpenSSL::Digest instance, due to the VM lock. Fixes jwt#696 Addresses the issue reported in jruby/jruby#8504 by @mohamedhafez * Add jwt#697 to changelog * Modify Rsa digest name test for new structure The @digest instance variable now contains the name to the digest to be used. See jwt#697 * Add test for concurrent encode/decode using ECDSA This is adapted from the script in jwt#696 and provides a test for the ECDSA part of the fix in jwt#697. * Fixes for Rubocop
Avoid using the same digest across calls (#697) * Avoid using the same digest across calls JWT appears to reuse these JWA instances across threads, which can lead to them stepping on each other via the shared OpenSSL::Digest instance. This causes decoding to fail verification, likely because the digest contains an amalgam of data from the different threads. This patch creates a new OpenSSL::Digest for each use, avoiding the threading issue. Note that the HMAC JWA already calls OpenSSL::HMAC.digest, avoiding the shared state, and the others do not use digest. The original code does not fail on CRuby most likely because only one thread at a time can be calculating a digest against a given OpenSSL::Digest instance, due to the VM lock. Fixes #696 Addresses the issue reported in jruby/jruby#8504 by @mohamedhafez * Add #697 to changelog * Modify Rsa digest name test for new structure The @digest instance variable now contains the name to the digest to be used. See #697 * Add test for concurrent encode/decode using ECDSA This is adapted from the script in #696 and provides a test for the ECDSA part of the fix in #697. * Fixes for Rubocop Co-authored-by: Charles Oliver Nutter <[email protected]>
Description
JWT appears to reuse these JWA instances across threads, which can lead to them stepping on each other via the shared OpenSSL::Digest instance. This causes decoding to fail verification, likely because the digest contains an amalgam of data from the different threads.
This patch creates a new OpenSSL::Digest for each use, avoiding the threading issue.
Note that the HMAC JWA already calls OpenSSL::HMAC.digest, avoiding the shared state, and the others do not use digest.
The original code does not fail on CRuby most likely because only one thread at a time can be calculating a digest against a given OpenSSL::Digest instance, due to the VM lock.
Fixes #696
Addresses the issue reported in jruby/jruby#8504 by @mohamedhafez
Checklist
Before the PR can be merged be sure the following are checked: