Skip to content

Commit 15a94e6

Browse files
committed
lib,src: drop --experimental-network-imports
PR-URL: #53822 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Geoffrey Booth <[email protected]> Reviewed-By: Marco Ippolito <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Stephen Belanger <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
1 parent 063f46d commit 15a94e6

17 files changed

+10
-623
lines changed

doc/api/cli.md

-13
Original file line numberDiff line numberDiff line change
@@ -988,18 +988,6 @@ changes:
988988
Specify the `module` containing exported [module customization hooks][].
989989
`module` may be any string accepted as an [`import` specifier][].
990990

991-
### `--experimental-network-imports`
992-
993-
<!-- YAML
994-
added:
995-
- v17.6.0
996-
- v16.15.0
997-
-->
998-
999-
> Stability: 1 - Experimental
1000-
1001-
Enable experimental support for the `https:` protocol in `import` specifiers.
1002-
1003991
### `--experimental-network-inspection`
1004992

1005993
<!-- YAML
@@ -2961,7 +2949,6 @@ one is included in the list below.
29612949
* `--experimental-json-modules`
29622950
* `--experimental-loader`
29632951
* `--experimental-modules`
2964-
* `--experimental-network-imports`
29652952
* `--experimental-permission`
29662953
* `--experimental-print-required-tla`
29672954
* `--experimental-require-module`

doc/api/errors.md

-17
Original file line numberDiff line numberDiff line change
@@ -3567,23 +3567,6 @@ removed: v10.0.0
35673567

35683568
Used by the `Node-API` when `Constructor.prototype` is not an object.
35693569

3570-
<a id="ERR_NETWORK_IMPORT_BAD_RESPONSE"></a>
3571-
3572-
### `ERR_NETWORK_IMPORT_BAD_RESPONSE`
3573-
3574-
> Stability: 1 - Experimental
3575-
3576-
Response was received but was invalid when importing a module over the network.
3577-
3578-
<a id="ERR_NETWORK_IMPORT_DISALLOWED"></a>
3579-
3580-
### `ERR_NETWORK_IMPORT_DISALLOWED`
3581-
3582-
> Stability: 1 - Experimental
3583-
3584-
A network module attempted to load another module that it is not allowed to
3585-
load. Likely this restriction is for security reasons.
3586-
35873570
<a id="ERR_NO_LONGER_SUPPORTED"></a>
35883571

35893572
### `ERR_NO_LONGER_SUPPORTED`

doc/api/esm.md

+1-67
Original file line numberDiff line numberDiff line change
@@ -697,71 +697,6 @@ spawn(execPath, [
697697
});
698698
```
699699
700-
## HTTPS and HTTP imports
701-
702-
> Stability: 1 - Experimental
703-
704-
Importing network based modules using `https:` and `http:` is supported under
705-
the `--experimental-network-imports` flag. This allows web browser-like imports
706-
to work in Node.js with a few differences due to application stability and
707-
security concerns that are different when running in a privileged environment
708-
instead of a browser sandbox.
709-
710-
### Imports are limited to HTTP/1
711-
712-
Automatic protocol negotiation for HTTP/2 and HTTP/3 is not yet supported.
713-
714-
### HTTP is limited to loopback addresses
715-
716-
`http:` is vulnerable to man-in-the-middle attacks and is not allowed to be
717-
used for addresses outside of the IPv4 address `127.0.0.0/8` (`127.0.0.1` to
718-
`127.255.255.255`) and the IPv6 address `::1`. Support for `http:` is intended
719-
to be used for local development.
720-
721-
### Authentication is never sent to the destination server.
722-
723-
`Authorization`, `Cookie`, and `Proxy-Authorization` headers are not sent to the
724-
server. Avoid including user info in parts of imported URLs. A security model
725-
for safely using these on the server is being worked on.
726-
727-
### CORS is never checked on the destination server
728-
729-
CORS is designed to allow a server to limit the consumers of an API to a
730-
specific set of hosts. This is not supported as it does not make sense for a
731-
server-based implementation.
732-
733-
### Cannot load non-network dependencies
734-
735-
These modules cannot access other modules that are not over `http:` or `https:`.
736-
To still access local modules while avoiding the security concern, pass in
737-
references to the local dependencies:
738-
739-
```mjs
740-
// file.mjs
741-
import worker_threads from 'node:worker_threads';
742-
import { configure, resize } from 'https://example.com/imagelib.mjs';
743-
configure({ worker_threads });
744-
```
745-
746-
```mjs
747-
// https://example.com/imagelib.mjs
748-
let worker_threads;
749-
export function configure(opts) {
750-
worker_threads = opts.worker_threads;
751-
}
752-
export function resize(img, size) {
753-
// Perform resizing in worker_thread to avoid main thread blocking
754-
}
755-
```
756-
757-
### Network-based loading is not enabled by default
758-
759-
For now, the `--experimental-network-imports` flag is required to enable loading
760-
resources over `http:` or `https:`. In the future, a different mechanism will be
761-
used to enforce this. Opt-in is required to prevent transitive dependencies
762-
inadvertently using potentially mutable state that could affect reliability
763-
of Node.js applications.
764-
765700
<i id="esm_experimental_loaders"></i>
766701
767702
## Loaders
@@ -804,8 +739,7 @@ does not determine whether the resolved URL protocol can be loaded,
804739
or whether the file extensions are permitted, instead these validations
805740
are applied by Node.js during the load phase
806741
(for example, if it was asked to load a URL that has a protocol that is
807-
not `file:`, `data:`, `node:`, or if `--experimental-network-imports`
808-
is enabled, `https:`).
742+
not `file:`, `data:` or `node:`.
809743
810744
The algorithm also tries to determine the format of the file based
811745
on the extension (see `ESM_FILE_FORMAT` algorithm below). If it does

doc/api/module.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ behaviors.
717717
#### Import from HTTPS
718718
719719
In current Node.js, specifiers starting with `https://` are experimental (see
720-
[HTTPS and HTTP imports][]).
720+
\[HTTPS and HTTP imports]\[]).
721721

722722
The hook below registers hooks to enable rudimentary support for such
723723
specifiers. While this may seem like a significant improvement to Node.js core
@@ -1054,7 +1054,6 @@ returned object contains the following keys:
10541054
[Conditional exports]: packages.md#conditional-exports
10551055
[Customization hooks]: #customization-hooks
10561056
[ES Modules]: esm.md
1057-
[HTTPS and HTTP imports]: esm.md#https-and-http-imports
10581057
[Source map v3 format]: https://sourcemaps.info/spec.html#h.mofvlxcwqzej
10591058
[`"exports"`]: packages.md#exports
10601059
[`--enable-source-maps`]: cli.md#--enable-source-maps

doc/node.1

-3
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,6 @@ Specify the
173173
.Ar module
174174
to use as a custom module loader.
175175
.
176-
.It Fl -experimental-network-imports
177-
Enable experimental support for loading modules using `import` over `https:`.
178-
.
179176
.It Fl -experimental-permission
180177
Enable the experimental permission model.
181178
.

lib/internal/errors.js

-4
Original file line numberDiff line numberDiff line change
@@ -1595,10 +1595,6 @@ E('ERR_NAPI_INVALID_TYPEDARRAY_ALIGNMENT',
15951595
'start offset of %s should be a multiple of %s', RangeError);
15961596
E('ERR_NAPI_INVALID_TYPEDARRAY_LENGTH',
15971597
'Invalid typed array length', RangeError);
1598-
E('ERR_NETWORK_IMPORT_BAD_RESPONSE',
1599-
"import '%s' received a bad response: %s", Error);
1600-
E('ERR_NETWORK_IMPORT_DISALLOWED',
1601-
"import of '%s' by %s is not supported: %s", Error);
16021598
E('ERR_NOT_BUILDING_SNAPSHOT',
16031599
'Operation cannot be invoked when not building startup snapshot', Error);
16041600
E('ERR_NOT_IN_SINGLE_EXECUTABLE_APPLICATION',

lib/internal/modules/esm/get_format.js

-23
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
const {
44
ObjectPrototypeHasOwnProperty,
5-
PromisePrototypeThen,
6-
PromiseResolve,
75
RegExpPrototypeExec,
86
SafeSet,
97
StringPrototypeCharCodeAt,
@@ -18,8 +16,6 @@ const {
1816
} = require('internal/modules/esm/formats');
1917

2018
const detectModule = getOptionValue('--experimental-detect-module');
21-
const experimentalNetworkImports =
22-
getOptionValue('--experimental-network-imports');
2319
const { containsModuleSyntax } = internalBinding('contextify');
2420
const { getPackageScopeConfig, getPackageType } = require('internal/modules/package_json_reader');
2521
const { fileURLToPath } = require('internal/url');
@@ -29,8 +25,6 @@ const protocolHandlers = {
2925
'__proto__': null,
3026
'data:': getDataProtocolModuleFormat,
3127
'file:': getFileProtocolModuleFormat,
32-
'http:': getHttpProtocolModuleFormat,
33-
'https:': getHttpProtocolModuleFormat,
3428
'node:'() { return 'builtin'; },
3529
};
3630

@@ -219,23 +213,6 @@ function getFileProtocolModuleFormat(url, context = { __proto__: null }, ignoreE
219213
throw new ERR_UNKNOWN_FILE_EXTENSION(ext, filepath);
220214
}
221215

222-
/**
223-
* @param {URL} url
224-
* @param {{parentURL: string}} context
225-
* @returns {Promise<string> | undefined} only works when enabled
226-
*/
227-
function getHttpProtocolModuleFormat(url, context) {
228-
if (experimentalNetworkImports) {
229-
const { fetchModule } = require('internal/modules/esm/fetch_module');
230-
return PromisePrototypeThen(
231-
PromiseResolve(fetchModule(url, context)),
232-
(entry) => {
233-
return mimeToFormat(entry.headers['content-type']);
234-
},
235-
);
236-
}
237-
}
238-
239216
/**
240217
* @param {URL} url
241218
* @param {{parentURL: string}} context

lib/internal/modules/esm/load.js

+5-26
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22

33
const {
4-
ArrayPrototypePush,
54
RegExpPrototypeExec,
65
decodeURIComponent,
76
} = primordials;
@@ -12,8 +11,6 @@ const { validateAttributes, emitImportAssertionWarning } = require('internal/mod
1211
const { getOptionValue } = require('internal/options');
1312
const { readFileSync } = require('fs');
1413

15-
const experimentalNetworkImports =
16-
getOptionValue('--experimental-network-imports');
1714
const defaultType =
1815
getOptionValue('--experimental-default-type');
1916

@@ -39,7 +36,7 @@ const DATA_URL_PATTERN = /^[^/]+\/[^,;]+(?:[^,]*?)(;base64)?,([\s\S]*)$/;
3936
*/
4037
async function getSource(url, context) {
4138
const { protocol, href } = url;
42-
let responseURL = href;
39+
const responseURL = href;
4340
let source;
4441
if (protocol === 'file:') {
4542
const { readFile: readFileAsync } = require('internal/fs/promises').exports;
@@ -51,19 +48,8 @@ async function getSource(url, context) {
5148
}
5249
const { 1: base64, 2: body } = match;
5350
source = BufferFrom(decodeURIComponent(body), base64 ? 'base64' : 'utf8');
54-
} else if (experimentalNetworkImports && (
55-
protocol === 'https:' ||
56-
protocol === 'http:'
57-
)) {
58-
const { fetchModule } = require('internal/modules/esm/fetch_module');
59-
const res = await fetchModule(url, context);
60-
source = await res.body;
61-
responseURL = res.resolvedHREF;
6251
} else {
6352
const supportedSchemes = ['file', 'data'];
64-
if (experimentalNetworkImports) {
65-
ArrayPrototypePush(supportedSchemes, 'http', 'https');
66-
}
6753
throw new ERR_UNSUPPORTED_ESM_URL_SCHEME(url, supportedSchemes);
6854
}
6955
return { __proto__: null, responseURL, source };
@@ -121,7 +107,7 @@ async function defaultLoad(url, context = kEmptyObject) {
121107

122108
const urlInstance = new URL(url);
123109

124-
throwIfUnsupportedURLScheme(urlInstance, experimentalNetworkImports);
110+
throwIfUnsupportedURLScheme(urlInstance);
125111

126112
if (urlInstance.protocol === 'node:') {
127113
source = null;
@@ -224,9 +210,8 @@ function defaultLoadSync(url, context = kEmptyObject) {
224210
* throws an error if the protocol is not one of the protocols
225211
* that can be loaded in the default loader
226212
* @param {URL} parsed
227-
* @param {boolean} experimentalNetworkImports
228213
*/
229-
function throwIfUnsupportedURLScheme(parsed, experimentalNetworkImports) {
214+
function throwIfUnsupportedURLScheme(parsed) {
230215
// Avoid accessing the `protocol` property due to the lazy getters.
231216
const protocol = parsed?.protocol;
232217
if (
@@ -235,17 +220,11 @@ function throwIfUnsupportedURLScheme(parsed, experimentalNetworkImports) {
235220
protocol !== 'data:' &&
236221
protocol !== 'node:' &&
237222
(
238-
!experimentalNetworkImports ||
239-
(
240-
protocol !== 'https:' &&
241-
protocol !== 'http:'
242-
)
223+
protocol !== 'https:' &&
224+
protocol !== 'http:'
243225
)
244226
) {
245227
const schemes = ['file', 'data', 'node'];
246-
if (experimentalNetworkImports) {
247-
ArrayPrototypePush(schemes, 'https', 'http');
248-
}
249228
throw new ERR_UNSUPPORTED_ESM_URL_SCHEME(parsed, schemes);
250229
}
251230
}

lib/internal/modules/esm/loader.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const {
3030
} = require('internal/errors').codes;
3131
const { getOptionValue } = require('internal/options');
3232
const { isURL, pathToFileURL, URLParse } = require('internal/url');
33-
const { emitExperimentalWarning, kEmptyObject } = require('internal/util');
33+
const { kEmptyObject } = require('internal/util');
3434
const {
3535
compileSourceTextModule,
3636
getDefaultConditions,
@@ -145,9 +145,6 @@ class ModuleLoader {
145145
#customizations;
146146

147147
constructor(customizations) {
148-
if (getOptionValue('--experimental-network-imports')) {
149-
emitExperimentalWarning('Network Imports');
150-
}
151148
this.setCustomizations(customizations);
152149
}
153150

0 commit comments

Comments
 (0)