Repository navigation
Do not write reserved names from Hyphen ENV to process.env - #7
Merged
Merged
Conversation
`Env.load` wrote each remote name to `process.env`. Some names control the Node.js runtime, OpenSSL, the dynamic loader, and the command shell. A person with write access to the ENV data could use these names to change the behavior of the application and of its child processes. `Env.load` does not write these names now. It sends one `warn` event that lists the names and not the values. The returned object contains all the remote values, as before. Co-authored-by: Jared Wray <me@jaredwray.com>
The ENV section lists the names that `Env.load` does not add to `process.env`. It also tells the user about the `warn` event and the limit of the list. Co-authored-by: Jared Wray <me@jaredwray.com>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 14 14
Lines 824 837 +13
Branches 194 199 +5
=========================================
+ Hits 824 837 +13 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Please check if the PR fulfills these requirements
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
Bug fix in
@hyphen/sdk.Problem
Env.loadwrote each remote name toprocess.env. The only check was for a NUL character. Some names control the Node.js runtime, OpenSSL, the dynamic loader, and the command shell. A person with write access to the ENV data could use these names to change the behavior of the application and of its child processes.Change
Env.loaddoes not write a reserved name toprocess.env. The comparison ignores the case of the name, because Windows ignores it.These names are reserved:
NODE_OPTIONS,NODE_PATH,NODE_REPL_EXTERNAL_MODULE, andNODE_COMPILE_CACHENODE_EXTRA_CA_CERTSandNODE_TLS_REJECT_UNAUTHORIZEDOPENSSL_CONF,OPENSSL_ENGINES,OPENSSL_MODULES,SSL_CERT_DIR, andSSL_CERT_FILEPATH,PATHEXT,COMSPEC, andBASH_ENVLD_orDYLD_HYPHEN_API_KEYThe service sends one
warnevent that lists the names that it did not write. The event does not contain the values. The returned object contains all the remote values, as before. A caller can read a reserved value from the returned object.The README of the Node.js SDK describes the reserved names.
Decisions
hxCLI uses the same ENV data and sets the variables before the process starts. A name such asNODE_OPTIONSis correct there.NODE_prefix. Applications use names such asNODE_ENVandNODE_CONFIGfor their own settings.ENVis not reserved. Only an interactive shell reads it, and an application can use this name.Compatibility
An application that used
loadto set a reserved name must now set that name from the returned object.Verification
pnpm buildpassed.pnpm lintpassed. Biome applied no fixes.vitest run test/env-service.test.ts --coveragepassed with 78 tests. The coverage ofsrc/env-service.tsis 100% for statements, branches, functions, and lines.NODE_OPTIONSvalue ran a preload file in a child process. After the fix, the preload file did not run, andNODE_ENVandDATABASE_URLwere written.pnpm testdid not pass in the local environment. 52 tests of@hyphen/sdkand 5 tests of@hyphen/browser-sdkneed theHYPHEN_*secrets, which the local environment does not have. The same tests fail onmain. CI has the secrets.Test audit gate
All tests are in
packages/nodejs-sdk/test/env-service.test.ts. They use the publicloadmethod, the publicwarnevent, and the publiclogproperty.does not write the reserved name %s to process.env(21 rows). It protects the contract thatloaddoes not write a reserved name, with the default options and withoverride: false. Each row failed on the code before the fix, becauseprocess.envcontained the remote value. No test examined a reserved name before.reports each skipped name and no value. It protects the contract that the service reports the skipped names and does not put a value in the report. It failed on the code before the fix, because the service sent nowarnevent.writes the name %s, which is not reserved(4 rows). It protects the namesNODE_ENV,NODE_CONFIG,LDAP_URL, andPATHNAME. A change to a wider prefix rule makes it fail. It also fails if the service sends awarnevent when it skipped no name. It is not a regression test for the defect, thus it passed before the fix.