Skip to content

Commit a385004

Browse files
committed
Remove usage of webcrypto from node:crypto in Node 18
The original code was intended to shim in support for the webcrypto interface in Node 18, which was included indirectly as `webcrypto` in the "node:crypto" module or globally via the `--no-experimental-global-webcrypto` flag. This change has caused many issues with bundlers and static analyzers which do not like the obfuscated call to `require()`. Node 18 will no longer receive security support as of 30 April 2025[1] and as such it feels like we can now drop this workaround in favor of documenting alternative approaches. [1]: https://endoflife.date/nodejs
1 parent 0b7c8eb commit a385004

File tree

1 file changed

+0
-18
lines changed

1 file changed

+0
-18
lines changed

lib/util.js

-18
Original file line numberDiff line numberDiff line change
@@ -97,24 +97,6 @@ async function validateWebhook(requestData, secret) {
9797
*/
9898
async function createHMACSHA256(secret, data) {
9999
const encoder = new TextEncoder();
100-
let crypto = globalThis.crypto;
101-
102-
// In Node 18 the `crypto` global is behind a --no-experimental-global-webcrypto flag
103-
if (typeof crypto === "undefined" && typeof require === "function") {
104-
// NOTE: Webpack (primarily as it's used by Next.js) and perhaps some
105-
// other bundlers do not currently support the `node` protocol and will
106-
// error if it's found in the source. Other platforms like CloudFlare
107-
// will only support requires when using the node protocol.
108-
//
109-
// As this line is purely to support Node 18.x we make an indirect request
110-
// to the require function which fools Webpack...
111-
//
112-
// We may be able to remove this in future as it looks like Webpack is getting
113-
// support for requiring using the `node:` protocol.
114-
// See: https://github.com/webpack/webpack/issues/18277
115-
crypto = require.call(null, "node:crypto").webcrypto;
116-
}
117-
118100
const key = await crypto.subtle.importKey(
119101
"raw",
120102
base64ToBytes(secret),

0 commit comments

Comments
 (0)