Skip to content

src: honor NODE_EXTRA_CA_CERTS set in an env file - #66638

Open
marcopiraccini wants to merge 2 commits into
nodejs:mainfrom
marcopiraccini:env-file-extra-ca-certs
Open

marcopiraccini wants to merge 2 commits into
nodejs:mainfrom
marcopiraccini:env-file-extra-ca-certs

Conversation

@marcopiraccini

@marcopiraccini marcopiraccini commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

NODE_EXTRA_CA_CERTS set through --env-file appeared in process.env, but its certificates were not loaded because the startup lookup ran before the env files were applied.

Read the value from the parsed env files when it is absent from the process environment. This supports both --env-file and --env-file-if-exists, preserves environment precedence, and uses case-insensitive lookup on Windows.

Both lookups share the existing SafeGetenv() privilege check, so the env-file fallback cannot bypass it. Runtime changes, including process.loadEnvFile(), still do not reload certificates; the documentation now states this explicitly.

This revisits #51497, where review raised the concern that reading from env files could bypass SafeGetenv()'s privilege checks. Both lookups now share that check, addressing the concern.

Regression tests cover both flags, environment precedence, lowercase variable names on Windows, and a TLS connection that requires the extra CA.

Fixes: #51426
Refs: #51497

NODE_EXTRA_CA_CERTS is read once at startup, before the files passed
with --env-file are applied to the environment. A value set in an env
file showed up in process.env but the certificates were never loaded.

Look the variable up in the parsed env files when it is not in the
environment. The environment keeps precedence, and the env files are
ignored under the same conditions as the environment: when node runs
setuid, setgid or with Linux file capabilities.

Fixes: nodejs#51426
Refs: nodejs#51497
Signed-off-by: marcopiraccini <marco.piraccini@gmail.com>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/config
  • @nodejs/startup

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs involving general changes in the lib/ or src/ directories. needs-ci PRs that need a full CI run. labels Oct 10, 2026
@marcopiraccini
marcopiraccini marked this pull request as ready for review October 10, 2026 08:15
Comment thread doc/api/cli.md Outdated
added: v7.3.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/00000

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: replace this. But not blocking.

Signed-off-by: marcopiraccini <marco.piraccini@gmail.com>
@codecov

codecov Bot commented Oct 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.47619% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.43%. Comparing base (ae5a0f4) to head (4f1d36e).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
src/node_credentials.cc 84.61% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #66638      +/-   ##
==========================================
- Coverage   92.78%   90.43%   -2.36%     
==========================================
  Files         422      791     +369     
  Lines      193692   276612   +82920     
  Branches    29881    53121   +23240     
==========================================
+ Hits       179718   250154   +70436     
- Misses      13645    16858    +3213     
- Partials      329     9600    +9271     
Files with missing lines Coverage Δ
src/node.cc 79.29% <100.00%> (ø)
src/node_dotenv.cc 85.11% <100.00%> (ø)
src/node_dotenv.h 100.00% <ø> (ø)
src/node_internals.h 80.35% <ø> (ø)
src/node_credentials.cc 68.60% <84.61%> (ø)

... and 496 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@marcopiraccini

Copy link
Copy Markdown
Contributor Author

Note on coverage: The two partials are the elevated-privilege branch of HasElevatedPrivileges(), which cannot run in CI (it needs a setuid or capability-flagged binary). The same check was already a partial in SafeGetenv() on main; the PR only moves it into a shared helper.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs involving general changes in the lib/ or src/ directories. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NODE_EXTRA_CA_CERTS does not work when set in env file

3 participants