fix(ecdh): validate browser deriveBits lengths - #367
Open
harrshita123 wants to merge 1 commit into
Open
Conversation
harrshita123
marked this pull request as ready for review
August 14, 2026 14:36
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.
Summary
Relationship to #249
PR #249 adds coverage for the documented maximum length and the first invalid bit length on each supported curve. This PR is a follow-up that addresses a separate browser implementation bug: negative and large Dart integers can be rounded and then wrapped during Web IDL conversion before the browser validates them.
The
maximum + 1cases overlap with #249's boundary coverage. The new regression cases exercise negative input and values around the 32-bit Web IDL boundary (0xfffffff9,0xffffffff,0x100000000, and0x100000001), which #249 does not cover and which require the implementation change in this PR.Rationale
The browser implementation rounded
lengthto bytes before callingSubtleCrypto.deriveBits. Invalid Dart integers could therefore wrap during Web IDL conversion and produce an empty or incorrectly sized secret, or surface an unrelatedStateError, instead of matching the native implementation's validation.The checks are performed before conversion and preserve existing behavior for zero and valid non-byte-aligned lengths.
Fixes #366.
Validation
dart format --output none --set-exit-if-changed .dart analyze --fatal-warnings .dart test test/webcrypto_test.dart -p vm(1,447 tests)dart test test/webcrypto_test.dart -p chrome -c dart2js(1,443 tests)dart test test/webcrypto_test.dart -p chrome -c dart2wasm(1,443 tests)