Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
This gem provides a simple, fast way to do string comparisons that resist timing attacks.
It also provides an easy way to (marginally) speed up your existing web apps that use Rails or Rack's secure_compare functions (for example, any app that uses Rails built in sessions) by monkey patching the fast C function over the slow pure Ruby one.
A timing attack is an attack on a system that determines secret information based on how long an operation takes.
Timing attacks are particularly prevalent (and dangerous) in cryptographic operations, but they can also sneak into other types of operation.
In particular, any time you are comparing user specified input with a secret, you should consider whether or not you are exposing yourself to a timing attack.
The attack is probably best described by Nate Lawson:
The attack is very simple. You repeatedly send guesses about a secret value to the server, which rejects them as incorrect. However, if your first byte of the guess is correct, it takes a very slightly longer time to return the error. With many measurements and some filtering, you can distinguish this difference.
Therefore, it's important that the amount of time these operations take depends only on the length of the user's input, and not on any characteristic of the secret data.
This gem provides a secure comparison function that is:
Furthermore, unlike some other secure comparison fuctions, the code does not require that the strings are the same length, and should not leak the length of the string if the string lengths do not match.
The gem also provides monkeypatches for rack and rails, to make it easier to deploy.
That depends on your use case:
require 'fast_secure_compare'
FastSecureCompare.compare(my_secret, user_input)
To make all uses of ActiveSupport::MessageVerifier
(including every time a user's session is verifed!) faster, you need to require 'fast_secure_compare/rails'
somehow.
In, e.g. Redmine, this is as simple as adding the following line to Gemfile.local
:
gem 'fast_secure_compare', :require => "fast_secure_compare/rails"
Don't forget to run bundle install
.
Apps using Rack and calling Rack::Utils.secure_compare
can be sped up with require 'fast_secure_compare/rack'
.
Note that this is not well tested and I'd appreciate feedback.
Well, that depends on how you measure it.
If you do a synthetic microbenchmark (see demo/timings.rb
), you'll see something like this when comparing two 40 byte strings (like SHA1 hashes), 1000 times over.
The 'early fail' one differs at the first character, while the 'late fail' one differs at the last character.
user system total real
==, early fail 0.000000 0.000000 0.000000 ( 0.000191)
==, late fail 0.000000 0.000000 0.000000 ( 0.000219)
Pure Ruby secure_compare, 'early' 0.020000 0.000000 0.020000 ( 0.019503)
Pure Ruby secure_compare, 'late' 0.020000 0.000000 0.020000 ( 0.019279)
C-based FastSecureCompare, 'early' 0.000000 0.000000 0.000000 ( 0.000588)
C-based FastSecureCompare, 'late' 0.000000 0.000000 0.000000 ( 0.000582)
Interpreting the results, the C based one executes 2 orders of magnitude faster than the pure Ruby, and the same order of magnitude as ==
.
However, if you benchmark an actual application, things will obviously differ. If you look at the difference per call, on my hardware you'd see about a ((0.02-0.0005)/1000) = 20 microsecond difference, which is probably too small to measure.
However, if you are comparing strings that are greater than 40 characters in length, the differences become significantly more pronounced. (This was the original motivation for this gem.)
The gem is not foolproof. In particular, it can't protect you against anything designed to exploit cache misses or any other more elaborate form of timing attack. However, none of the existing pure Ruby secure_compare functions do either.
Putting the argmuents around the wrong way may leak the length of your secret.
Don't use a secret of length 0.
FAQs
Unknown package
We found that fast_secure_compare demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.