@@ -601,6 +601,71 @@ spawn(execPath, [
601601});
602602` ` `
603603
604+ ## HTTPS and HTTP imports
605+
606+ > Stability: 1 - Experimental
607+
608+ Importing network based modules using ` https: ` and ` http: ` is supported under
609+ the ` -- experimental- network- imports` flag. This allows web browser-like imports
610+ to work in Node.js with a few differences due to application stability and
611+ security concerns that are different when running in a privileged environment
612+ instead of a browser sandbox.
613+
614+ ### Imports are limited to HTTP/1
615+
616+ Automatic protocol negotiation for HTTP/2 and HTTP/3 is not yet supported.
617+
618+ ### HTTP is limited to loopback addresses
619+
620+ ` http: ` is vulnerable to man-in-the-middle attacks and is not allowed to be
621+ used for addresses outside of the IPv4 address ` 127.0 .0 .0 / 8 ` (` 127.0 .0 .1 ` to
622+ ` 127.255 .255 .255 ` ) and the IPv6 address ` :: 1 ` . Support for ` http: ` is intended
623+ to be used for local development.
624+
625+ ### Authentication is never sent to the destination server.
626+
627+ ` Authorization` , ` Cookie` , and ` Proxy - Authorization` headers are not sent to the
628+ server. Avoid including user info in parts of imported URLs. A security model
629+ for safely using these on the server is being worked on.
630+
631+ ### CORS is never checked on the destination server
632+
633+ CORS is designed to allow a server to limit the consumers of an API to a
634+ specific set of hosts. This is not supported as it does not make sense for a
635+ server-based implementation.
636+
637+ ### Cannot load non-network dependencies
638+
639+ These modules cannot access other modules that are not over ` http: ` or ` https: ` .
640+ To still access local modules while avoiding the security concern, pass in
641+ references to the local dependencies:
642+
643+ ` ` ` mjs
644+ // file.mjs
645+ import worker_threads from ' worker_threads' ;
646+ import { configure , resize } from ' https://example.com/imagelib.mjs' ;
647+ configure ({ worker_threads });
648+ ` ` `
649+
650+ ` ` ` mjs
651+ // https://example.com/imagelib.mjs
652+ let worker_threads;
653+ export function configure (opts ) {
654+ worker_threads = opts .worker_threads ;
655+ }
656+ export function resize (img , size ) {
657+ // Perform resizing in worker_thread to avoid main thread blocking
658+ }
659+ ` ` `
660+
661+ ### Network-based loading is not enabled by default
662+
663+ For now, the ` -- experimental- network- imports` flag is required to enable loading
664+ resources over ` http: ` or ` https: ` . In the future, a different mechanism will be
665+ used to enforce this. Opt-in is required to prevent transitive dependencies
666+ inadvertently using potentially mutable state that could affect reliability
667+ of Node.js applications.
668+
604669<i id="esm_experimental_loaders"></i>
605670
606671## Loaders
0 commit comments