Skip to content

Commit a30ae50

Browse files
authored
cli: remove --no-experimental-global-webcrypto flag
PR-URL: nodejs#52564 Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io> Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent d3eb1cb commit a30ae50

11 files changed

+48
-102
lines changed

doc/api/cli.md

-10
Original file line numberDiff line numberDiff line change
@@ -1388,14 +1388,6 @@ added: v21.2.0
13881388
13891389
Disable exposition of [Navigator API][] on the global scope.
13901390

1391-
### `--no-experimental-global-webcrypto`
1392-
1393-
<!-- YAML
1394-
added: v19.0.0
1395-
-->
1396-
1397-
Disable exposition of [Web Crypto API][] on the global scope.
1398-
13991391
### `--no-experimental-repl-await`
14001392

14011393
<!-- YAML
@@ -2699,7 +2691,6 @@ one is included in the list below.
26992691
* `--no-experimental-fetch`
27002692
* `--no-experimental-global-customevent`
27012693
* `--no-experimental-global-navigator`
2702-
* `--no-experimental-global-webcrypto`
27032694
* `--no-experimental-repl-await`
27042695
* `--no-experimental-websocket`
27052696
* `--no-extra-info-on-fatal-exception`
@@ -3190,7 +3181,6 @@ node --stack-trace-limit=12 -p -e "Error.stackTraceLimit" # prints 12
31903181
[Subresource Integrity]: https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity
31913182
[V8 JavaScript code coverage]: https://v8project.blogspot.com/2017/12/javascript-code-coverage.html
31923183
[V8 code cache]: https://v8.dev/blog/code-caching-for-devs
3193-
[Web Crypto API]: webcrypto.md
31943184
[`"type"`]: packages.md#type
31953185
[`--allow-child-process`]: #--allow-child-process
31963186
[`--allow-fs-read`]: #--allow-fs-read

doc/api/globals.md

+13-9
Original file line numberDiff line numberDiff line change
@@ -361,13 +361,15 @@ added:
361361
- v17.6.0
362362
- v16.15.0
363363
changes:
364+
- version: REPLACEME
365+
pr-url: https://github.com/nodejs/node/pull/52564
366+
description: No longer experimental.
364367
- version: v19.0.0
365368
pr-url: https://github.com/nodejs/node/pull/42083
366369
description: No longer behind `--experimental-global-webcrypto` CLI flag.
367370
-->
368371

369-
> Stability: 1 - Experimental. Disable this API with the
370-
> [`--no-experimental-global-webcrypto`][] CLI flag.
372+
> Stability: 2 - Stable.
371373
372374
A browser-compatible implementation of {Crypto}. This global is available
373375
only if the Node.js binary was compiled with including support for the
@@ -380,13 +382,15 @@ added:
380382
- v17.6.0
381383
- v16.15.0
382384
changes:
385+
- version: REPLACEME
386+
pr-url: https://github.com/nodejs/node/pull/52564
387+
description: No longer experimental.
383388
- version: v19.0.0
384389
pr-url: https://github.com/nodejs/node/pull/42083
385390
description: No longer behind `--experimental-global-webcrypto` CLI flag.
386391
-->
387392

388-
> Stability: 1 - Experimental. Disable this API with the
389-
> [`--no-experimental-global-webcrypto`][] CLI flag.
393+
> Stability: 2 - Stable.
390394
391395
A browser-compatible implementation of the [Web Crypto API][].
392396

@@ -397,13 +401,15 @@ added:
397401
- v17.6.0
398402
- v16.15.0
399403
changes:
404+
- version: REPLACEME
405+
pr-url: https://github.com/nodejs/node/pull/52564
406+
description: No longer experimental.
400407
- version: v19.0.0
401408
pr-url: https://github.com/nodejs/node/pull/42083
402409
description: No longer behind `--experimental-global-webcrypto` CLI flag.
403410
-->
404411

405-
> Stability: 1 - Experimental. Disable this API with the
406-
> [`--no-experimental-global-webcrypto`][] CLI flag.
412+
> Stability: 2 - Stable.
407413
408414
A browser-compatible implementation of {CryptoKey}. This global is available
409415
only if the Node.js binary was compiled with including support for the
@@ -981,8 +987,7 @@ changes:
981987
description: No longer behind `--experimental-global-webcrypto` CLI flag.
982988
-->
983989

984-
> Stability: 1 - Experimental. Disable this API with the
985-
> [`--no-experimental-global-webcrypto`][] CLI flag.
990+
> Stability: 2 - Stable.
986991
987992
A browser-compatible implementation of {SubtleCrypto}. This global is available
988993
only if the Node.js binary was compiled with including support for the
@@ -1147,7 +1152,6 @@ A browser-compatible implementation of [`WritableStreamDefaultWriter`][].
11471152
[Web Crypto API]: webcrypto.md
11481153
[`--no-experimental-global-customevent`]: cli.md#--no-experimental-global-customevent
11491154
[`--no-experimental-global-navigator`]: cli.md#--no-experimental-global-navigator
1150-
[`--no-experimental-global-webcrypto`]: cli.md#--no-experimental-global-webcrypto
11511155
[`--no-experimental-websocket`]: cli.md#--no-experimental-websocket
11521156
[`AbortController`]: https://developer.mozilla.org/en-US/docs/Web/API/AbortController
11531157
[`ByteLengthQueuingStrategy`]: webstreams.md#class-bytelengthqueuingstrategy

doc/node.1

-3
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,6 @@ Disable experimental support for the WebSocket API.
192192
.It Fl -no-experimental-global-customevent
193193
Disable exposition of the CustomEvent on the global scope.
194194
.
195-
.It Fl -no-experimental-global-webcrypto
196-
Disable exposition of the Web Crypto API on the global scope.
197-
.
198195
.It Fl -no-experimental-repl-await
199196
Disable top-level await keyword support in REPL.
200197
.

lib/internal/bootstrap/web/exposed-window-or-worker.js

+32
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
const {
1212
globalThis,
1313
ObjectDefineProperty,
14+
ObjectGetOwnPropertyDescriptor,
1415
} = primordials;
1516

1617
const {
@@ -20,6 +21,11 @@ const {
2021
exposeLazyInterfaces,
2122
} = require('internal/util');
2223

24+
const {
25+
ERR_INVALID_THIS,
26+
ERR_NO_CRYPTO,
27+
} = require('internal/errors').codes;
28+
2329
// https://html.spec.whatwg.org/multipage/webappapis.html#windoworworkerglobalscope
2430
const timers = require('timers');
2531
defineOperation(globalThis, 'clearInterval', timers.clearInterval);
@@ -89,3 +95,29 @@ exposeLazyInterfaces(globalThis, 'internal/deps/undici/undici', ['WebSocket']);
8995
internalBinding('wasm_web_api').setImplementation((streamState, source) => {
9096
require('internal/wasm_web_api').wasmStreamingCallback(streamState, source);
9197
});
98+
99+
// WebCryptoAPI
100+
if (internalBinding('config').hasOpenSSL) {
101+
defineReplaceableLazyAttribute(
102+
globalThis,
103+
'internal/crypto/webcrypto',
104+
['crypto'],
105+
false,
106+
function cryptoThisCheck() {
107+
if (this !== globalThis && this != null)
108+
throw new ERR_INVALID_THIS(
109+
'nullish or must be the global object');
110+
},
111+
);
112+
exposeLazyInterfaces(
113+
globalThis, 'internal/crypto/webcrypto',
114+
['Crypto', 'CryptoKey', 'SubtleCrypto'],
115+
);
116+
} else {
117+
ObjectDefineProperty(globalThis, 'crypto',
118+
{ __proto__: null, ...ObjectGetOwnPropertyDescriptor({
119+
get crypto() {
120+
throw new ERR_NO_CRYPTO();
121+
},
122+
}, 'crypto') });
123+
}

lib/internal/crypto/webcrypto.js

-17
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const {
55
JSONParse,
66
JSONStringify,
77
ObjectDefineProperties,
8-
ObjectDefineProperty,
98
ReflectApply,
109
ReflectConstruct,
1110
SafeSet,
@@ -21,10 +20,6 @@ const {
2120
kWebCryptoCipherDecrypt,
2221
} = internalBinding('crypto');
2322

24-
const {
25-
getOptionValue,
26-
} = require('internal/options');
27-
2823
const { TextDecoder, TextEncoder } = require('internal/encoding');
2924

3025
const {
@@ -1025,18 +1020,6 @@ ObjectDefineProperties(
10251020
},
10261021
});
10271022

1028-
if (getOptionValue('--no-experimental-global-webcrypto')) {
1029-
// For backward compatibility, keep exposing CryptoKey in the Crypto prototype
1030-
// when using the flag.
1031-
ObjectDefineProperty(Crypto.prototype, 'CryptoKey', {
1032-
__proto__: null,
1033-
enumerable: true,
1034-
configurable: true,
1035-
writable: true,
1036-
value: CryptoKey,
1037-
});
1038-
}
1039-
10401023
ObjectDefineProperties(
10411024
SubtleCrypto.prototype, {
10421025
[SymbolToStringTag]: {

lib/internal/main/eval_string.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ if (getOptionValue('--input-type') === 'module' ||
3131
} else {
3232
// For backward compatibility, we want the identifier crypto to be the
3333
// `node:crypto` module rather than WebCrypto.
34-
const isUsingCryptoIdentifier =
35-
getOptionValue('--experimental-global-webcrypto') &&
36-
RegExpPrototypeExec(/\bcrypto\b/, source) !== null;
34+
const isUsingCryptoIdentifier = RegExpPrototypeExec(/\bcrypto\b/, source) !== null;
3735
const shouldDefineCrypto = isUsingCryptoIdentifier && internalBinding('config').hasOpenSSL;
3836

3937
if (isUsingCryptoIdentifier && !shouldDefineCrypto) {

lib/internal/process/pre_execution.js

-39
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ const {
1212
NumberParseInt,
1313
ObjectDefineProperty,
1414
ObjectFreeze,
15-
ObjectGetOwnPropertyDescriptor,
1615
SafeMap,
1716
String,
1817
StringPrototypeStartsWith,
@@ -36,9 +35,7 @@ const {
3635
} = require('internal/util');
3736

3837
const {
39-
ERR_INVALID_THIS,
4038
ERR_MANIFEST_ASSERT_INTEGRITY,
41-
ERR_NO_CRYPTO,
4239
ERR_MISSING_OPTION,
4340
ERR_ACCESS_DENIED,
4441
} = require('internal/errors').codes;
@@ -107,7 +104,6 @@ function prepareExecution(options) {
107104
setupNavigator();
108105
setupWarningHandler();
109106
setupUndici();
110-
setupWebCrypto();
111107
setupCustomEvent();
112108
setupCodeCoverage();
113109
setupDebugEnv();
@@ -341,41 +337,6 @@ function setupNavigator() {
341337
defineReplaceableLazyAttribute(globalThis, 'internal/navigator', ['navigator'], false);
342338
}
343339

344-
// TODO(aduh95): move this to internal/bootstrap/web/* when the CLI flag is
345-
// removed.
346-
function setupWebCrypto() {
347-
if (getEmbedderOptions().noBrowserGlobals ||
348-
getOptionValue('--no-experimental-global-webcrypto')) {
349-
return;
350-
}
351-
352-
if (internalBinding('config').hasOpenSSL) {
353-
defineReplaceableLazyAttribute(
354-
globalThis,
355-
'internal/crypto/webcrypto',
356-
['crypto'],
357-
false,
358-
function cryptoThisCheck() {
359-
if (this !== globalThis && this != null)
360-
throw new ERR_INVALID_THIS(
361-
'nullish or must be the global object');
362-
},
363-
);
364-
exposeLazyInterfaces(
365-
globalThis, 'internal/crypto/webcrypto',
366-
['Crypto', 'CryptoKey', 'SubtleCrypto'],
367-
);
368-
} else {
369-
ObjectDefineProperty(globalThis, 'crypto',
370-
{ __proto__: null, ...ObjectGetOwnPropertyDescriptor({
371-
get crypto() {
372-
throw new ERR_NO_CRYPTO();
373-
},
374-
}, 'crypto') });
375-
376-
}
377-
}
378-
379340
function setupCodeCoverage() {
380341
// Resolve the coverage directory to an absolute path, and
381342
// overwrite process.env so that the original path gets passed

src/node_options.cc

+1-5
Original file line numberDiff line numberDiff line change
@@ -416,11 +416,7 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
416416
&EnvironmentOptions::experimental_global_navigator,
417417
kAllowedInEnvvar,
418418
true);
419-
AddOption("--experimental-global-webcrypto",
420-
"expose experimental Web Crypto API on the global scope",
421-
&EnvironmentOptions::experimental_global_web_crypto,
422-
kAllowedInEnvvar,
423-
true);
419+
AddOption("--experimental-global-webcrypto", "", NoOp{}, kAllowedInEnvvar);
424420
AddOption("--experimental-json-modules", "", NoOp{}, kAllowedInEnvvar);
425421
AddOption("--experimental-loader",
426422
"use the specified module as a custom loader",

test/parallel/test-cli-eval.js

-6
Original file line numberDiff line numberDiff line change
@@ -348,12 +348,6 @@ child.exec(
348348
common.mustSucceed((stdout) => {
349349
assert.match(stdout, /^number/);
350350
}));
351-
child.exec(
352-
`${nodejs} --no-experimental-global-webcrypto ` +
353-
'-p "var crypto = {randomBytes:1};typeof crypto.randomBytes"',
354-
common.mustSucceed((stdout) => {
355-
assert.match(stdout, /^number/);
356-
}));
357351

358352
// Regression test for https://github.com/nodejs/node/issues/45336
359353
child.execFile(process.execPath,

test/parallel/test-global-webcrypto-disbled.js

-10
This file was deleted.

test/parallel/test-process-env-allowed-flags-are-documented.js

+1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ const undocumented = difference(process.allowedNodeEnvironmentFlags,
9999
assert(undocumented.delete('--debug-arraybuffer-allocations'));
100100
assert(undocumented.delete('--no-debug-arraybuffer-allocations'));
101101
assert(undocumented.delete('--es-module-specifier-resolution'));
102+
assert(undocumented.delete('--experimental-global-webcrypto'));
102103
assert(undocumented.delete('--experimental-report'));
103104
assert(undocumented.delete('--experimental-worker'));
104105
assert(undocumented.delete('--node-snapshot'));

0 commit comments

Comments
 (0)