Skip to content

src: support for reading NODE_EXTRA_CA_CERTS from env file - #51497

Closed
xsbchen wants to merge 1 commit into
nodejs:mainfrom
xsbchen:env-file
Closed

xsbchen wants to merge 1 commit into
nodejs:mainfrom
xsbchen:env-file

Conversation

@xsbchen

@xsbchen xsbchen commented Jan 17, 2024

Copy link
Copy Markdown
Contributor

Fixes: #51426

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/startup

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels Jan 17, 2024
@joyeecheung

Copy link
Copy Markdown
Member

It doesn't seem right to override this with the dot env files without checking privileges which was what SafeGetEnv was for. Maybe @bnoordhuis knows better whether this violates what it tried to guard against.

@anonrig
anonrig self-requested a review January 17, 2024 15:55
Comment thread src/node_dotenv.cc Outdated
@@ -108,10 +108,14 @@ bool Dotenv::ParsePath(const std::string_view path) {
}

void Dotenv::AssignNodeOptionsIfAvailable(std::string* node_options) {
auto match = store_.find("NODE_OPTIONS");
AssignValueIfAvailable("NODE_OPTIONS", node_options);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We don't need this function anymore. Ref: AssignNodeOptionsIfAvailable

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

got it, fixed

Comment thread src/node_dotenv.cc Outdated
AssignValueIfAvailable("NODE_OPTIONS", node_options);
}

void Dotenv::AssignValueIfAvailable(const char* key, std::string* value) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
void Dotenv::AssignValueIfAvailable(const char* key, std::string* value) {
void Dotenv::AssignValueIfAvailable(const std::string& key, std::string* value) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

Comment thread src/node.cc
@xsbchen

xsbchen commented Jan 18, 2024 •

Copy link
Copy Markdown
Contributor Author

It doesn't seem right to override this with the dot env files without checking privileges which was what SafeGetEnv was for. Maybe @bnoordhuis knows better whether this violates what it tried to guard against.

Thanks @joyeecheung, I'm not sure whether this change is reliable. @bnoordhuis If you are free, please help to review it.

Update: I check the comment on SafeGetEnv, it says Look up the environment variable and allow the lookup if the current process only has the capability CAP_NET_BIND_SERVICE set. If the current process does not have any capabilities set and the process is running as setuid root then lookup will not be allowed.. It seems that only want we need to get environment variables from the system (by uv_os_getenv) need to consider this capability.

@xsbchen
xsbchen force-pushed the env-file branch 2 times, most recently from 5f4f97a to b012fa7 Compare January 18, 2024 07:47
@xsbchen
xsbchen requested a review from anonrig January 22, 2024 09:04
@xsbchen

xsbchen commented Feb 5, 2024

Copy link
Copy Markdown
Contributor Author

any update?

@joyeecheung

Copy link
Copy Markdown
Member

I think we need someone like @bnoorhuis or someone from @nodejs/security to review it and confirm that this is not introducing a attack vector

@lirantal

Copy link
Copy Markdown
Member

Just briefly looked at it so I hope I don't miss anything important. Here's my observation:

  • If someone already controls the --env-file, they could just as well use other command-line flags that are more problematic like loaders, etc.
  • However, what if someone doesn't control --env-file but they do control the actual environment config file (the .env)? Like for example, they could exploit a path traversal or arbitrary file writes to change the contents of .env with their own.

@joyeecheung

Copy link
Copy Markdown
Member

I think the original intent of SafeGetEnv is to guard against e.g. improper permission escalation when the binary gets the setuid bit set. Not sure what the threat model is. It might also make sense to completely ignore the .env file when the binary gets modified like that.

@xsbchen

xsbchen commented Feb 19, 2024 •

Copy link
Copy Markdown
Contributor Author

so need to do the same check like SafeGetEnv before getting value from .env file right? @joyeecheung @lirantal

@joyeecheung

Copy link
Copy Markdown
Member

That would be what I'd do - just ignoring the .env too when the permission check fails - but I don't think I am familiar enough with the original threat model to make a call.

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been marked as stale due to 90 days of inactivity.
It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.

@github-actions github-actions Bot added the stale Issues and PRs marked stale due to inactivity and scheduled for automatic closure. label Jul 28, 2026
@avivkeller avivkeller closed this Aug 9, 2026
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++. needs-ci PRs that need a full CI run. stale Issues and PRs marked stale due to inactivity and scheduled for automatic closure.

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

6 participants