Repository navigation
feat: add maxIterations, a read-side cap on the PBKDF2 count - #30
Merged
Merged
Conversation
The iteration count is read from the envelope and used to derive the key before the authentication tag can be checked. Whoever can write to the store could raise it to the 5,000,000 ceiling and make a failing read cost about eight times the default. With maxIterations set, a version 2 envelope declaring more is refused with INVALID_ITERATIONS before any key derivation. The cap is opt-in so values written with a higher count than the configured one keep reading. Releases as 2.1.0.
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.
Why
Reported in a comment on the dev.to article: the iteration count in a version 2 header is authenticated, but it has to be used to derive the key before the tag can be checked. Raising it to 5,000,000 on a stored value makes the read fail only after about eight times the default work.
Reproduced on 2.0.0: a failing read goes from 73 ms to about 580 ms on this machine.
What
maxIterationsondecrypt(),rewrap()andAesGcmEncryptor(instance default, per-call override).INVALID_ITERATIONSbefore any key derivation. With the cap at 600,000 the same tampered value is refused in 11 ms (0 ms withallowLegacy: false).Checks
npm run verifypasses locally (coverage thresholds included).After merge, publishing is a
v2.1.0tag.