mirror of
https://github.com/nodejs/node.git
synced 2026-10-28 10:15:07 +08:00
Necessarily semver-major. When `--permission` is on, every env var not matched by `--allow-env` is removed at startup. It takes names, prefix patterns (`PREFIX_*`), or `*`, repeatable or comma-sep'd. There are a range of env vars that Node.js itself uses, and a default range that are generally known to be safe in common usage. These are never scrubbed. These include things like `NODE_OPTIONS`, `NODE_EXTRA_CA_CERTS`, `PATH`, `HOME`, etc. `NODE_ENV` is not in the defaults and must be allowed explicitly. Proxy vars (`HTTP_PROXY`, `HTTPS_PROXY`, `NO_PROXY`) are also not in the defaults since they can carry credentials. When `--use-env-proxy` or `NODE_USE_ENV_PROXY` is set and any of them were removed, a single warning naming them is emitted. Env vars can be dropped at runtime after reading using `permission.drop()`. This is a stronger protection than using `process.env.FOO = undefined` because it will scrub the env var also from the environment block. On Linux, the removed entries are overwritten in the initial environment block. fs reads of any other process's /proc/<pid>/environ, ancestors included, are denied regardless of `--allow-fs-read`. A process's own is readable only with `--allow-env=*`. Symlinks are resolved before the check so paths like /dev/fd/../../<ppid>/environ are caught. The check only canonicalizes paths that statfs() reports are on procfs. On Windows, removal also clears the C runtime's copy of the environ using _wputenv_s. Reading a removed name returns undefined, warns once per name, and publishes to a diagnostics channel. Env file keys are allowed. If the user had reason to pass in an env file the assumption is they meant to allow them. File-source config (node.config.json and NODE_OPTIONS from a .env file) can only narrow the allow list. Embedders must call ScrubProcessEnvironment() themselves on startup. This is left up to the embedder to determine the exact timing but needs to be called before startup actually happens. Child processes are started with `--allow-env=*`. Those either receive the explicit env they were started with or only the env they inherit from the parent. Since the parent process is scrubbed, and the child cannot read any other process's /proc/<pid>/environ, it should never see more than the parent can. Main part of the impl was done by hand. Docs, tests, verification pass, and cleanup nits were automated. Signed-off-by: James M Snell <jasnell@gmail.com> Assisted-by: Opencode PR-URL: https://github.com/nodejs/node/pull/66132 Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Node.js documentation style guide
This guide provides clear and concise instructions to help you create well-organized and readable documentation for the Node.js community. It covers organization, spelling, formatting, and more to ensure consistency and professionalism across all documents.
Table of contents
- General Guidelines
- Writing Style
- Punctuation
- Document Structure
- API Documentation
- Code Blocks
- Formatting
- Product and Project Naming
General guidelines
File naming
- Markdown Files: Use
lowercase-with-dashes.md.- Use underscores only if they are part of the topic name (e.g.,
child_process). - Some files, like top-level Markdown files, may be exceptions.
- Use underscores only if they are part of the topic name (e.g.,
Text wrapping
- Wrap documents at 120 characters per line to enhance readability and version control.
Editor configuration
- Follow the formatting rules specified in
.editorconfig.- A plugin is available for some editors to enforce these rules.
Testing documentation
- Validate documentation changes using
make test-doc -jorvcbuild test-doc.
Writing style
Spelling and grammar
- Spelling: Use US spelling.
- Grammar: Use clear, concise language. Avoid unnecessary jargon.
Commas
- Serial Commas: Use serial commas for clarity.
- Example: apples, oranges, and bananas
Pronouns
- Avoid first-person pronouns (I, we).
- Exception: Use we recommend foo instead of foo is recommended.
Gender-neutral language
- Use gender-neutral pronouns and plural nouns.
- OK: they, their, them, folks, people, developers
- NOT OK: his, hers, him, her, guys, dudes
Terminology
- Use precise technical terms and avoid colloquialisms.
- Define any specialized terms or acronyms at first use.
Punctuation
Terminal punctuation
- Place inside parentheses or quotes if the content is a complete clause.
- Place outside if the content is a fragment of a clause.
Quotation marks
- Use double quotation marks for direct quotes.
- Use single quotation marks for quotes within quotes.
Colons and semicolons
- Use colons to introduce lists or explanations.
- Use semicolons to link closely related independent clauses.
Document structure
Headings
- Start documents with a level-one heading (
#). - Use subsequent headings (
##,###, etc.) to organize content hierarchically.
Links
- Prefer reference-style links (
[a link][]) over inline links ([a link](http://example.com)).
Lists
- Use bullet points for unordered lists and numbers for ordered lists.
- Keep list items parallel in structure.
Tables
- Use tables to present structured information clearly. Ensure they are readable in plain text.
API documentation
YAML comments
- Update the YAML comments associated with the API, especially when introducing or deprecating an API.
Usage examples
- Provide a usage example or a link to an example for every function.
Parameter descriptions
- Clearly describe parameters and return values, including types and defaults.
- Example:
* `byteOffset` {integer} Index of first byte to expose. **Default:** `0`.
- Example:
Code blocks
Language-aware fences
-
Use language-aware fences (e.g.,
```js) for code blocks.-
Info String: Use the appropriate info string from the following list:
Language Info String Bash bashC cCommonJS cjsCoffeeScript coffeeTerminal Session consoleC++ cppDiff diffHTTP httpJavaScript jsJSON jsonMarkdown markdownEcmaScript mjsPowershell powershellR rPlaintext textTypeScript typescript -
Use
textfor languages not listed until their grammar is added toremark-preset-lint-node.
-
Code comments
- Use comments to explain complex logic within code examples.
- Follow the standard commenting style of the respective language.
Formatting
Escaping characters
- Use backslash-escaping for underscores, asterisks, and backticks:
\_,\*,\`.
Naming conventions
- Constructors: Use PascalCase.
- Instances: Use camelCase.
- Methods: Indicate methods with parentheses:
socket.end()instead ofsocket.end.
Function arguments and returns
- Arguments:
Example:
* `name` {type|type2} Optional description. **Default:** `value`.* `byteOffset` {integer} Index of first byte to expose. **Default:** `0`. - Returns:
Example:
* Returns: {type|type2} Optional description.* Returns: {AsyncHook} A reference to `asyncHook`.
Product and project naming
Official styling
- Use official capitalization for products and projects.
- OK: JavaScript, Google's V8
- NOT OK: Javascript, Google's v8
Node.js references
- Use Node.js instead of Node, NodeJS, or similar variants.
- For the executable,
nodeis acceptable.
- For the executable,
Version references
- Use Node.js and the version number in prose. Do not prefix the version number with v.
- OK: Node.js 14.x, Node.js 14.3.1
- NOT OK: Node.js v14
For topics not addressed here, please consult the Microsoft Writing Style Guide.