Skip to content

fix(ecdh): validate browser deriveBits lengths - #367

Open
harrshita123 wants to merge 1 commit into
google:masterfrom
harrshita123:fix/ecdh-derive-bits-length-validation
Open

fix(ecdh): validate browser deriveBits lengths#367
harrshita123 wants to merge 1 commit into
google:masterfrom
harrshita123:fix/ecdh-derive-bits-length-validation

Conversation

@harrshita123

@harrshita123 harrshita123 commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Summary

  • retain the selected ECDH curve limit in the browser private-key wrapper
  • reject negative and curve-oversized lengths before byte rounding and Web IDL conversion
  • add shared regression coverage for every supported curve and 32-bit wrap boundaries

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 + 1 cases 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, and 0x100000001), which #249 does not cover and which require the implementation change in this PR.

Rationale

The browser implementation rounded length to bytes before calling SubtleCrypto.deriveBits. Invalid Dart integers could therefore wrap during Web IDL conversion and produce an empty or incorrectly sized secret, or surface an unrelated StateError, 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)

@harrshita123
harrshita123 marked this pull request as ready for review August 14, 2026 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: browser ECDH deriveBits wraps invalid lengths at the WebIDL boundary

1 participant