🔒 Add ScramAuthenticator#max_iterations (backports #654)#656
Merged
nevans merged 4 commits intov0.5-stablefrom Apr 22, 2026
Merged
🔒 Add ScramAuthenticator#max_iterations (backports #654)#656nevans merged 4 commits intov0.5-stablefrom
ScramAuthenticator#max_iterations (backports #654)#656nevans merged 4 commits intov0.5-stablefrom
Conversation
`SASL::ScramAlgorithm` and `SASL::ScramAuthenticator` use `salted_password` _at least_ twice: once to compute `client_key` and once to compute `server_key`. It is actually used more than that, since `client_key` and `server_key` are also used multiple times each. Computing `salted_password` is _intentionally_ computationally expensive, so it should be cached. Although `client_key` and `server_key` are far less computationally expensive, they _are_ used multiple times, so they are memoized too. Ultimately, we _could_ memoize most of the methods in `ScramAlgorithm`, but I've decided to keep it simple by only memoizing these three.
`max_iterations` enforces a maximum allowed iteration count. A higher number iterations will raise an error. As noted in RFC5802 §9: >>> A hostile server can perform a computational denial-of-service attack on clients by sending a big iteration count value. Note that `OpenSSL::KDF.pbkdf2_hmac` is implemented by a blocking C function, and cannot be interrupted by +Timeout+ or `Thread.raise`. And (as of v4.0 of the +openssl+ gem) it keeps the Global VM lock, so other ruby threads will not be able to run either. The default value is `2³¹ - 1`, the maximum signed 32-bit integer. This is large enough for the computation to take several minutes, and insufficient protection against hostile servers. _To prevent a denial of service attack,_ this must be set to a safe value, based on user's hardware and version of OpenSSL. _It is the user's responsibility_ to enforce minimum and maximum iteration counts that are appropriate for their security context.
ScramAuthenticator#max_iterationsScramAuthenticator#max_iterations (backports #654)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This backports #654 to
v0.5-stable.