Many Node.js applications run behind corporate proxies, cloud network gateways, or security appliances. These proxies control outbound traffic and may require authentication before allowing an application to connect to external services. Developers usually configure the proxy through environment variables such as HTTP_PROXY and HTTPS_PROXY, keeping the settings outside the application code.
There is, however, a security detail that is easy to overlook: proxy credentials can become part of an error message when Node.js encounters an invalid proxy configuration. If the application writes that error to the console, the credentials may end up in container logs, monitoring platforms, centralized logging systems, or crash reports.
This is particularly concerning because developers often assume that an error generated by the Node.js runtime is safe to log. They may capture the complete error object, including its message and stack trace, without realizing that the message itself can contain sensitive configuration information.
Node.js has addressed a specific instance of this problem through a security fix. Understanding how the exposure happens, why ordinary error logging can make it worse, and how to handle proxy configuration safely helps prevent credentials from spreading beyond the environment where they are supposed to be used.
How Proxy Authentication Works in Node.js
An HTTP proxy acts as an intermediary between an application and an external service. Instead of connecting directly to the destination server, the application sends its request through the configured proxy.
In an enterprise environment, the proxy may require a username and password. One common way to provide these credentials is through the proxy URL itself:
HTTP_PROXY=http://proxy-user:[email protected]:8080
HTTPS_PROXY=http://proxy-user:[email protected]:8080
The URL contains four important parts: the protocol, username, password, and proxy server address. Node.js or the HTTP client uses this configuration to establish a connection and provide the required proxy authentication.
For an authenticated HTTP proxy, the client may send a Proxy-Authorization header. With Basic authentication, the credentials are Base64-encoded before being included in the header.
It is important to understand that Base64 is an encoding format, not encryption. Anyone who obtains the encoded value can decode it and recover the original username and password.
This means that a proxy URL containing credentials should be treated as a secret. It should not appear in application logs, debugging output, exception messages, or configuration reports.
The problem becomes more serious when the application runs in a container or cloud environment. Environment variables may be injected by the deployment platform, while application output is automatically collected by a logging agent. A single poorly handled exception can therefore move a credential from a restricted configuration environment into a much broader logging system.
How an Invalid Proxy Configuration Can Reveal Credentials
The security issue is not limited to developers accidentally printing environment variables. A runtime can expose sensitive information through an error message generated while validating configuration.
Consider an application configured with an authenticated proxy URL:
HTTPS_PROXY=http://service-user:[email protected]:8080
Suppose the proxy configuration is invalid. This could happen because of an incorrectly formatted URL, an unsupported configuration value, or another validation problem during proxy initialization.
The application may encounter an error such as ERR_PROXY_INVALID_CONFIG.
If the error message includes the original proxy URL without removing its authentication details, the output can reveal the username and password.
The issue is an example of CWE-209, which describes the generation of error messages containing sensitive information. The application or runtime is attempting to explain a configuration failure, but the diagnostic information includes data that should never be exposed.
This is not the same as an attacker directly reading the application's environment variables. The credentials are exposed through an output channel that may have a much wider audience than the original configuration.
For example, consider a typical production logging flow:
Node.js application
|
v
Proxy configuration error
|
v
Application error handler
|
v
Container standard error
|
v
Centralized logging platform
|
v
Monitoring and support teams
The application may have restricted access to its proxy configuration, but several other systems can retain the error output. Anyone with access to those logs may then be able to retrieve the exposed credentials.
A Real Node.js Security Issue: CVE-2026-123871
Node.js addressed a proxy credential disclosure vulnerability identified as CVE-2026-123871.
The issue involved error paths that generated ERR_PROXY_INVALID_CONFIG messages using the original proxy URL, including its embedded authentication details. An earlier security fix had already introduced redaction for proxy credentials in ProxyConfig.href, but that protection did not cover all error paths in the same subsystem.
As a result, some invalid proxy configurations could still produce error messages containing the original credentials.
The vulnerability affected the active Node.js 22.x, 24.x, and 26.x release lines before their respective security fixes.
The patched releases are:
Node.js release line | Patched version |
|---|
22.x | 22.23.5 |
24.x | 24.22.3 |
26.x | 26.13.1 |
These versions address the reported vulnerability in their respective release lines. Teams should use the latest supported security release rather than treating the listed minimum versions as a permanent upgrade target.
The important lesson is that redacting a value in one part of a runtime does not guarantee that every error path handles it safely. Developers should not assume that built-in error messages are always suitable for unrestricted logging.
Why Logging the Complete Error Object Is Risky
Node.js applications commonly use structured logging libraries such as Pino or Winston. These libraries make it convenient to record exceptions along with timestamps, request identifiers, stack traces, and additional context.
The problem arises when developers log everything without deciding which information is safe to retain.
Consider this error-handling code:
async function callExternalService() {
try {
const response = await fetch(
'https://api.example.com/orders'
);
return await response.json();
} catch (error) {
console.error('External service request failed:', error);
throw error;
}
}
At first glance, this looks like reasonable error handling. The developer records the error and rethrows it so that the calling code can handle the failure.
However, logging the complete error object can expose information contained in its message, nested causes, or associated configuration. If an underlying runtime error contains a sensitive proxy URL, the logging statement may reproduce it in the application's output.
The same problem can occur with structured logging:
logger.error({
error,
proxy: process.env.HTTPS_PROXY
}, 'External request failed');
This example is particularly unsafe because it explicitly records the proxy environment variable.
The better approach is to log the information needed to diagnose the failure without copying the underlying secret into the log.
For example:
async function callExternalService() {
try {
const response = await fetch(
'https://api.example.com/orders'
);
if (!response.ok) {
throw new Error(
`External service returned HTTP ${response.status}`
);
}
return await response.json();
} catch (error) {
logger.error({
errorCode: error?.code ?? 'UNKNOWN_ERROR',
errorName: error?.name ?? 'Error'
}, 'External service request failed');
throw new Error(
'Unable to communicate with the external service.'
);
}
}
This example records the error name and code rather than the complete message. It also prevents the original low-level error from being returned directly to the caller.
In a real application, the original error can be retained in a restricted diagnostic system if necessary, but only after applying appropriate sanitization. Avoid assuming that an error code or stack trace is automatically safe; custom errors and library-specific diagnostics may contain sensitive values too.
Store Proxy Credentials Outside Application Code
Proxy configuration should be managed separately from application source code.
Avoid placing authenticated proxy URLs directly in JavaScript files, package scripts, Dockerfiles, or committed configuration files. Instead, inject the values through the deployment environment or an approved secret-management service.
For example, an application might receive its proxy configuration from the environment:
const proxyUrl = process.env.HTTPS_PROXY;
if (!proxyUrl) {
throw new Error(
'HTTPS proxy configuration is missing.'
);
}
Notice that the application checks whether the configuration exists without printing its value.
In production, a secret-management system can provide the proxy credentials when the application starts. This reduces the need to store credentials in source control or deployment configuration files.
It is also important to restrict access to the environment itself. Moving a password from a JavaScript file into an environment variable does not automatically make it secure. Deployment administrators, process inspection tools, debugging facilities, and privileged users may still be able to access it.
Use the platform's supported secret-injection mechanism, limit access to deployment settings, and rotate credentials when exposure is suspected.
Use Node.js Proxy Configuration Carefully
Node.js supports proxy configuration through environment variables and, in supported releases, built-in proxy handling.
For example, proxy support can be enabled through the command line:
node --use-env-proxy app.js
Alternatively, the NODE_USE_ENV_PROXY environment variable can enable the behavior:
NODE_USE_ENV_PROXY=1 node app.js
The application can then use the configured HTTP_PROXY, HTTPS_PROXY, and NO_PROXY values according to the runtime's supported proxy behavior.
When using Undici directly, the ProxyAgent provides another way to configure proxy connections.
import { ProxyAgent, setGlobalDispatcher } from 'undici';
const proxyUrl = process.env.HTTPS_PROXY;
if (!proxyUrl) {
throw new Error('HTTPS proxy is not configured.');
}
const proxyAgent = new ProxyAgent(proxyUrl);
setGlobalDispatcher(proxyAgent);
This example keeps the proxy URL outside the source code. However, the value still contains credentials if authentication is embedded in the URL, so it must not be printed or included in diagnostic messages.
Undici also supports providing proxy authentication separately through its ProxyAgent options. For example, a token option can supply a preformatted Proxy-Authorization value. This can help keep credentials separate from the proxy address, although the token itself must still be protected as a secret.
Do not create a proxy agent for every individual request unless there is a specific reason. Reusing a configured dispatcher is generally easier to manage and avoids unnecessary connection-management overhead.
Also, use only proxies authorized by your organization. A proxy can observe connection metadata, and depending on the protocol and TLS configuration, it may be able to inspect request contents. Proxy authentication does not make an untrusted proxy safe.
Protect Logs From Sensitive Configuration
Even after updating Node.js and correcting error handling, logging systems should be configured to reduce the risk of accidental credential exposure.
Start by reviewing application logs, container output, reverse-proxy logs, and crash-reporting integrations. Check whether any of them capture environment variables, complete request headers, proxy URLs, or unrestricted error objects.
For structured logging, define fields that are safe to record. An outbound request failure might need the destination hostname, HTTP method, error code, duration, and correlation ID. It generally does not need the proxy password or complete authorization headers.
For example, a useful diagnostic record might look like this:
{
"level": "error",
"message": "Outbound request failed",
"service": "orders-api",
"destination": "api.example.com",
"method": "GET",
"errorCode": "ERR_PROXY_INVALID_CONFIG",
"requestId": "req-12345"
}
This provides useful troubleshooting context without including the authenticated proxy URL.
If a credential has already appeared in logs, treat it as exposed. Remove or restrict access to affected log records where possible, rotate the proxy password, and investigate whether the logs were exported to external monitoring or support systems.
Deleting a log entry does not invalidate the credential. Rotation is necessary because anyone who obtained the original value may still be able to use it.
Practical Checklist for Node.js Applications
Before deploying an application that uses an authenticated proxy, review the following areas:
Upgrade Node.js to a release containing the relevant security fix.
Store proxy credentials in an approved secret-management system.
Avoid printing HTTP_PROXY or HTTPS_PROXY values.
Do not log complete error objects without reviewing their contents.
Sanitize error messages before forwarding them to external logging services.
Restrict access to container logs and crash reports.
Avoid logging authorization headers and request configuration objects.
Use only trusted and authorized proxy servers.
Rotate credentials if they have appeared in logs.
Test invalid proxy configurations in a controlled environment.
These checks are useful even when the application is running on a patched Node.js release. Runtime updates address known defects, but they do not prevent application code from accidentally exposing credentials through its own logging logic.
Summary
Proxy configuration is often treated as infrastructure setup, but it can introduce application-level security risks when credentials are included in URLs and error messages. Node.js demonstrated this risk through CVE-2026-123871, where certain invalid proxy configurations could produce ERR_PROXY_INVALID_CONFIG messages containing embedded authentication details.
The exposure becomes more serious when applications log complete exceptions and send their output to container platforms, centralized logging systems, or crash-reporting services.
Developers should use patched Node.js releases, keep proxy credentials outside source code, avoid logging complete configuration values, and sanitize errors before sending them to external systems. They should also treat previously exposed credentials as compromised and rotate them rather than relying only on deleting the affected log entries.
A useful error log should help developers understand what failed and where to investigate. It should never reveal the credentials that an application uses to communicate with its infrastructure.
Join the conversation! Your thoughts help the community grow.