Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 36.4k
Https imports#36328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Https imports #36328
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -606,6 +606,71 @@ spawn(execPath, [ | ||
| }); | ||
| ``` | ||
| ## HTTPS and HTTP imports | ||
| > Stability: 1 - Experimental | ||
| Importing network based modules using `https:` and `http:` is supported under | ||
| the `--experimental-network-imports` flag. This allows web browser-like imports | ||
| to work in Node.js with a few differences due to application stability and | ||
| security concerns that are different when running in a privileged environment | ||
| instead of a browser sandbox. | ||
| ### Imports are limited to HTTP/1 | ||
| Automatic protocol negotiation for HTTP/2 and HTTP/3 is not yet supported. | ||
| ### HTTP is limited to loopback addresses | ||
| `http:` is vulnerable to man-in-the-middle attacks and is not allowed to be | ||
| used for addresses outside of the IPv4 address `127.0.0.0/8` (`127.0.0.1` to | ||
| `127.255.255.255`) and the IPv6 address `::1`. Support for `http:` is intended | ||
| to be used for local development. | ||
| ### Authentication is never sent to the destination server. | ||
| `Authorization`, `Cookie`, and `Proxy-Authorization` headers are not sent to the | ||
| server. Avoid including user info in parts of imported URLs. A security model | ||
| for safely using these on the server is being worked on. | ||
jasnell marked this conversation as resolved.
Outdated
Uh oh!There was an error while loading. Please reload this page. | ||
| ### CORS is never checked on the destination server | ||
| CORS is designed to allow a server to limit the consumers of an API to a | ||
| specific set of hosts. This is not supported as it does not make sense for a | ||
| server-based implementation. | ||
| ### Cannot load non-network dependencies | ||
| These modules cannot access other modules that are not over `http:` or `https:`. | ||
| To still access local modules while avoiding the security concern, pass in | ||
| references to the local dependencies: | ||
| ```mjs | ||
| // file.mjs | ||
| import worker_threads from 'worker_threads'; | ||
| import { configure, resize } from 'https://example.com/imagelib.mjs'; | ||
bmeck marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| configure({ worker_threads }); | ||
| ``` | ||
| ```mjs | ||
| // https://example.com/imagelib.mjs | ||
| let worker_threads; | ||
| export function configure(opts) { | ||
| worker_threads = opts.worker_threads; | ||
| } | ||
| export function resize(img, size) { | ||
| // Perform resizing in worker_thread to avoid main thread blocking | ||
| } | ||
| ``` | ||
| ### Network-based loading is not enabled by default | ||
| For now, the `--experimental-network-imports` flag is required to enable loading | ||
| resources over `http:` or `https:`. In the future, a different mechanism will be | ||
| used to enforce this. Opt-in is required to prevent transitive dependencies | ||
| inadvertently using potentially mutable state that could affect reliability | ||
| of Node.js applications. | ||
| <i id="esm_experimental_loaders"></i> | ||
| ## Loaders | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -45,16 +45,16 @@ if (process.argv[1] && process.argv[1] !== '-') { | ||
| }); | ||
| } | ||
| function checkSyntax(source, filename) { | ||
| async function checkSyntax(source, filename) { | ||
| const { getOptionValue } = require('internal/options'); | ||
| let isModule = false; | ||
| if (filename === '[stdin]' || filename === '[eval]') { | ||
| isModule = getOptionValue('--input-type') === 'module'; | ||
| } else { | ||
| const { defaultResolve } = require('internal/modules/esm/resolve'); | ||
| const { defaultGetFormat } = require('internal/modules/esm/get_format'); | ||
| const { url } = defaultResolve(pathToFileURL(filename).toString()); | ||
| const format = defaultGetFormat(url); | ||
| const { url } = await defaultResolve(pathToFileURL(filename).toString()); | ||
bmeck marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| const format = await defaultGetFormat(url); | ||
| isModule = format === 'module'; | ||
| } | ||
| if (isModule) { | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.