Skip to content

bug: FFI backend's JWK imports accept padded and standard Base64 values #328

Description

@mfazrinizar

Summary

The FFI backend accepts JWK properties that are not valid unpadded base64url.

For example, both of these are currently accepted:

  • AQ==, which contains padding
  • +w, which uses the standard Base64 + character

Browser WebCrypto rejects both values. JWK fields must use the URL-safe Base64 alphabet without trailing padding, as specified by RFC 7515.

Reproduction

await HmacSecretKey.importJsonWebKey({
  'kty': 'oct',
  'alg': 'HS256',
  'k': 'AQ==',
}, Hash.sha256);

await HmacSecretKey.importJsonWebKey({
  'kty': 'oct',
  'alg': 'HS256',
  'k': '+w',
}, Hash.sha256);

Expected Behavior

Both imports throw FormatException consistently across FFI and browser backends.

Actual Behavior

The FFI backend imports both keys, while the browser backend rejects them. The issue is in the shared FFI JWK decoder, so it can affect HMAC, AES, EC, and RSA JWK fields.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions