Skip to content

fix(splicer): only stub preview1 random_get when random is disabled - #367

Open
cadivus wants to merge 1 commit into
bytecodealliance:mainfrom
cadivus:fix/preview1-random-get-external
Open

cadivus wants to merge 1 commit into
bytecodealliance:mainfrom
cadivus:fix/preview1-random-get-external

Conversation

@cadivus

@cadivus cadivus commented Nov 29, 2026

Copy link
Copy Markdown

stub_preview1 unconditionally replaced wasi_snapshot_preview1.random_get with unreachable. StarlingMonkey's OpenSSL gets entropy through it (arc4random_buf), so RSA/EC public key import (EVP_PKEY_public_check during crypto.subtle.importKey) traps the instance. With random enabled, the preview1 adapter already maps random_get to wasi:random/random.get-random-bytes. This change moves the stub under !features.contains(&Feature::Random), next to stub_random.

Adds test/builtins/crypto-import-key.js (RSA-2048 and P-256 JWK import + verify). It fails with RuntimeError: unreachable before and passes after. Full suite: 80 passed, 1 skipped.

Reproducer: https://github.com/cadivus/ComponentizeJS-reproducer/tree/webcrypto-rsa-importkey-trap

Fixes #334

The preview1 random_get import was always replaced with an unreachable
stub, so OpenSSL entropy (RSA/EC public key validation during
crypto.subtle.importKey) trapped the instance. Leave it to the preview1
adapter, which maps it to wasi:random, unless 'random' is disabled.

Fixes bytecodealliance#334
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.

Possible regression in native crypto paths in componentize-js 0.20.0 due to preview1 random_get stubbing

1 participant