Skip to content

fix(hmac): reject empty imported keys - #364

Open
harrshita123 wants to merge 3 commits into
google:masterfrom
harrshita123:fix/hmac-empty-key-import
Open

harrshita123 wants to merge 3 commits into
google:masterfrom
harrshita123:fix/hmac-empty-key-import

Conversation

@harrshita123

Copy link
Copy Markdown
Contributor

Summary

Native HMAC imports currently accept empty key material, while browser implementations reject the same input. This creates inconsistent behavior depending on which backend an application uses.

This change validates the key data in the shared native HMAC import path and rejects empty keys before constructing the native key object. Because raw and JWK imports use the same path, the fix covers both formats without duplicating validation logic.

What changed

  • Reject empty native HMAC key material with a FormatException.
  • Add regression coverage for:
    • empty raw HMAC keys
    • JWK HMAC keys with an empty k value

Why this matters

An HMAC key must contain key material. Accepting an empty key can hide invalid input and cause code to behave differently between native and browser environments. Rejecting it during import makes the behavior predictable and fails early with a clear error.

Validation

  • dart format --output none --set-exit-if-changed .
  • dart analyze --fatal-warnings .
  • Full VM test suite
  • Full Chrome test suite using Dart2JS
  • Full Chrome test suite using Dart2Wasm

Fixes #363

Comment thread lib/src/testing/regression/hmac_empty_key.dart
Comment thread test/hmac_empty_key_test.dart Outdated

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: native HMAC imports accept zero-length key material

2 participants