Skip to content

fix: export alg in AES, DES and HMAC JWKs again - #101

Merged
donskov merged 1 commit into
masterfrom
donskov/webcrypto-fix-jwk-alg
Oct 27, 2026
Merged

donskov merged 1 commit into
masterfrom
donskov/webcrypto-fix-jwk-alg

Conversation

@donskov

@donskov donskov commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

Since 1.6.0, exportKey("jwk", key) returns alg: "" for AES, DES and HMAC keys. 1.4.6 and 1.5.0 exported A256GCM, HS256 and so on. Nobody has reported it.

Key 1.5.0 1.6.0 – 1.7.1 This PR Node.js WebCrypto
AES-GCM 256 A256GCM "" A256GCM A256GCM
HMAC SHA-256 HS256 "" HS256 HS256

Cause: the build targets ES2022, which defines class fields on the instance. The protected alg = "" field in the base CryptoKey (src/keys/key.ts) therefore became an own property that hid the alg getters of AesCryptoKey, DesCryptoKey and HmacCryptoKey.

Fix: the base alg is now an accessor (still decorated with @JsonProp), so the subclass getters apply again. The // @ts-ignore above those getters is replaced with override. RSA, EC and Ed keys build their own JWK and are unaffected. Key import is unchanged: the JWK alg is still not checked against the requested algorithm (#38).

Tests: src/keys/key.spec.ts covers AES-CBC/CTR/GCM/KW/ECB/CMAC, HMAC SHA-1/256/512 and 3DES. It checks generate → export → import → export, and compares against Node.js WebCrypto. All 12 cases fail on master and pass here. I also checked the built build/webcrypto.js and build/webcrypto.es.js directly.

Release: this goes in before the v2 stack, so it ships on the 1.x build. The release-please dry run finds v1.7.1 and proposes chore(release): v1.7.2 with this fix. #97 and the rest of the stack get rebased on top afterwards, so the fix is also in 2.0.0.

Since 1.6.0, exportKey("jwk") returned alg "" for AES, DES and HMAC
keys (1.5.0 returned A256GCM, HS256, ...). The ES2022 build defines
class fields on the instance, so the `alg = ""` field in the base
CryptoKey hid the alg getters of AesCryptoKey, DesCryptoKey and
HmacCryptoKey. The base alg is now an accessor, so the subclass
getters apply again and the @ts-ignore comments are gone.

AES and HMAC values match Node.js WebCrypto (A128CBC, A256GCM, A256KW,
HS256, ...). Key import is unchanged: the JWK alg is still not checked.
@donskov donskov self-assigned this Oct 27, 2026
@donskov
donskov merged commit b529e55 into master Oct 27, 2026
2 checks passed
@donskov
donskov deleted the donskov/webcrypto-fix-jwk-alg branch October 27, 2026 10:47
@github-actions github-actions Bot mentioned this pull request Oct 27, 2026
@donskov donskov mentioned this pull request Oct 27, 2026
2 tasks
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.

1 participant