Skip to content

fix(crypto): Copy HMAC bytes into a new std::vector, to avoid a use-after-free - #342

Merged
andreiltd merged 2 commits into
bytecodealliance:mainfrom
VirtualTim:hmac-key-ownership
Oct 22, 2026
Merged

andreiltd merged 2 commits into
bytecodealliance:mainfrom
VirtualTim:hmac-key-ownership

Conversation

@VirtualTim

Copy link
Copy Markdown
Contributor

Fixes #341.

@VirtualTim

This comment was marked as resolved.

@andreiltd andreiltd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! One note here: the JS class is storing the key in the slot but it looks like it never release it, so vector is leaking memory.

JS::SetReservedSlot(instance, std::to_underlying(Slots::KeyData), JS::PrivateValue(data.release()->data()));

The class should use finalizable policy and drop the vector in finalize method:

class CryptoKey : public BuiltinImpl<CryptoKey, FinalizableClassPolicy>

@andreiltd

Copy link
Copy Markdown
Member

Tracked here: #343

@andreiltd
andreiltd merged commit d3d8125 into bytecodealliance:main Oct 22, 2026
7 checks passed
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.

Use-after-free when importing HMAC JWTs

2 participants