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