mirror of
https://github.com/hoppscotch/hoppscotch.git
synced 2026-04-25 16:55:59 +03:00
[PR #5791] [MERGED] feat(js-sandbox): add extensive Web Crypto API support #5351
Labels
No labels
CodeDay
a11y
browser limited
bug
bug fix
cli
core
critical
design
desktop
discussion
docker
documentation
duplicate
enterprise
feature
feature
fosshack
future
good first issue
hacktoberfest
help wanted
i18n
invalid
major
minor
need information
need testing
not applicable to hoppscotch
not reproducible
pull-request
question
refactor
resolved
sandbox
self-host
spam
stale
testmu
wip
wont fix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/hoppscotch#5351
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/hoppscotch/hoppscotch/pull/5791
Author: @jamesgeorge007
Created: 1/20/2026
Status: ✅ Merged
Merged: 1/22/2026
Merged by: @jamesgeorge007
Base:
next← Head:feat/js-sandbox-web-crypto-api-support📝 Commits (1)
8c0dc5afeat(js-sandbox): add extensive Web Crypto API support📊 Changes
13 files changed (+3223 additions, -199 deletions)
View changed files
📝
packages/hoppscotch-cli/src/__tests__/e2e/fixtures/collections/scripting-revamp-coll.json(+195 -137)➕
packages/hoppscotch-js-sandbox/src/__tests__/cage-modules/crypto/encrypt-decrypt.spec.ts(+261 -0)➕
packages/hoppscotch-js-sandbox/src/__tests__/cage-modules/crypto/key-operations.spec.ts(+829 -0)➕
packages/hoppscotch-js-sandbox/src/__tests__/cage-modules/crypto/random-values.spec.ts(+243 -0)➕
packages/hoppscotch-js-sandbox/src/__tests__/cage-modules/crypto/sign-verify.spec.ts(+207 -0)➕
packages/hoppscotch-js-sandbox/src/__tests__/cage-modules/crypto/subtle-digest.spec.ts(+207 -0)📝
packages/hoppscotch-js-sandbox/src/__tests__/pm-namespace/serialization-edge-cases.spec.ts(+0 -1)📝
packages/hoppscotch-js-sandbox/src/__tests__/pw-namespace/expect/toBeLevelxxx.spec.ts(+0 -3)➕
packages/hoppscotch-js-sandbox/src/cage-modules/crypto.ts(+1031 -0)📝
packages/hoppscotch-js-sandbox/src/cage-modules/default.ts(+2 -2)📝
packages/hoppscotch-js-sandbox/src/cage-modules/fetch.ts(+5 -56)📝
packages/hoppscotch-js-sandbox/src/cage-modules/index.ts(+2 -0)➕
packages/hoppscotch-js-sandbox/src/cage-modules/utils/vm-marshal.ts(+241 -0)📄 Description
Relates to #2015, #5523, #3353, https://github.com/AndrewBastin/faraday-cage/issues/1.
Closes FE-1104.
This PR brings comprehensive Web Crypto API support to Hoppscotch's experimental scripting sandbox, enabling users to perform real cryptographic operations in their pre-request and test scripts.
A custom in-house implementation of the cage module is maintained to enable faster iteration and project-specific behaviour. The relevant upstream issue is linked for visibility, following the same approach used for the custom fetch cage module.
What's changed
New files:
cage-modules/crypto.ts— Custom crypto module implementing the fullcrypto.subtleAPI (~1,100 lines). Replaces faraday-cage's built-in crypto, which lacked propercrypto.subtlesupport across the VM boundary.cage-modules/utils/vm-marshal.ts— Shared utilities for marshalling values between QuickJS VM and host:vmArrayToUint8Array(),uint8ArrayToVmArray(),CryptoKeyRegistryfor storing CryptoKey objects, andmarshalValue()for generic object serialisation.Modified files:
cage-modules/default.ts— Swapped faraday-cage'scryptoforcustomCryptoModulein the default module setcage-modules/fetch.ts— Refactored to use sharedvm-marshal.tsutilities instead of duplicating marshalling logiccage-modules/index.ts— Export the new crypto module and its config typeTest files:
serialization-edge-cases.spec.ts.toBeLevelxxx.spec.ts.Crypto operations now available
crypto.getRandomValues(),crypto.randomUUID()Note to reviewers
Try out the following snippet:
The main challenge was safely transferring cryptographic values across the QuickJS VM boundary. Since QuickJS doesn't natively support
Uint8ArrayorCryptoKeyobjects, custom marshalling is used to convert between VM arrays and host types. CryptoKey objects are stored in a host-side registry (with 5-minute TTL) and referenced by ID from the VM.All operations delegate to the host's native
WebCrypto; no cryptographic primitives are implemented here. Async operations are tracked to prevent "use after free" errors when the VM is disposed of while crypto work is pending.Tests perform real cryptographic round-trips (encrypt→decrypt, sign→verify) rather than just checking function existence.
No breaking changes to the public API.
Summary by cubic
Adds full Web Crypto API support to the Hoppscotch JavaScript sandbox, enabling real hashing, encryption, signing, key management, and random utilities in pre-request and test scripts. Implements a custom crypto module that safely bridges the QuickJS VM to the host WebCrypto.
New Features
Refactors
Written for commit
8c0dc5a12e. Summary will update on new commits.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.