Skip to content

fix(kdf): validate deriveBits output length - #390

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

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

Conversation

@harrshita123

@harrshita123 harrshita123 commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Fixes #389.

Summary

  • validate HKDF and PBKDF2 deriveBits lengths before backend dispatch
  • reject values outside the Web IDL unsigned long range
  • add shared regression coverage for negative and greater-than-32-bit values

Root cause

The browser backend forwarded arbitrary Dart integers to SubtleCrypto.deriveBits. Web IDL converted those values to unsigned long, so inputs such as -0xfffffff8 wrapped to 8 and produced a one-byte result instead of failing.

The shared validation also prevents oversized PBKDF2 output lengths from reaching the native allocation path.

Validation

  • dart analyze --fatal-warnings .
  • focused regression on VM
  • focused regression on Chrome with dart2js
  • focused regression on Chrome with dart2wasm
  • broader HKDF/PBKDF2 shared suite on VM
  • broader HKDF/PBKDF2 shared suite on Chrome with dart2js
  • broader HKDF/PBKDF2 shared suite on Chrome with dart2wasm
  • git diff --check

This branch has not been deployed

No deployments
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 HKDF and PBKDF2 deriveBits wrap out-of-range lengths

1 participant