NODE_EXTRA_CA_CERTS vs strict-ssl=false for corporate proxy certificate errors
0 reputation · 23 May 2021, 11:04 UTC
0 reputation · 23 May 2021, 11:04 UTC
When encountering SSL certificate validation failures while connecting to a private npm registry through a corporate intercepting proxy, two primary configuration paths exist to restore connectivity.
One approach involves setting strict-ssl=false in the .npmrc file to bypass certificate validation entirely. An alternative approach is to maintain strict validation but provide the proxy's root certificate via the NODE_EXTRA_CA_CERTS environment variable, allowing Node.js to trust the specific intercepting authority.
The primary constraint is balancing deployment speed against security posture in a production CI/CD pipeline where man-in-the-middle risks must be mitigated.
NODE_EXTRA_CA_CERTS fully resolve validation issues for all npm registry interactions, or are there specific registry configurations where strict-ssl=false remains the only viable bypass?34775 reputation · 23 May 2021, 21:24 UTC
For a corporate intercepting proxy, the recommended way to restore trust while keeping SSL verification active is to set the NODE_EXTRA_CA_CERTS environment variable to the proxy’s root CA certificate (in PEM format). This tells Node.js to extend its built‑in trust store with that authority, so all TLS handshakes—including those made by the npm CLI—succeed without disabling verification.
/etc/ssl/certs/proxy-ca.pem.# Linux/macOS
export NODE_EXTRA_CA_CERTS=/etc/ssl/certs/proxy-ca.pem
# Windows (cmd)
set NODE_EXTRA_CA_CERTS=C:\path\to\proxy-ca.pem
# Windows (PowerShell)
$env:NODE_EXTRA_CA_CERTS='C:\path\to\proxy-ca.pem'
UNABLE_TO_VERIFY_LEAF_SIGNATURE (or similar) error disappears.Setting In most corporate environments where the proxy’s signing certificate is available, To be certain that npm config set strict-ssl false disables verification only for HTTPS requests made by the npm CLI. It does not
NODE_EXTRA_CA_CERTS fully resolves validation issues for all npm registry interactions, because npm relies on Node.js’s TLS stack. No additional bypass is needed.Missing diagnostic detail
NODE_EXTRA_CA_CERTS alone suffices, confirm whether the SSL error occurs only when running npm commands or also when your application makes outbound HTTPS requests (e.g., to internal APIs). If the error appears only for npm, the same proxy CA will still fix it; if it appears for other services, you may need to add additional CA certificates to the same variable.
Use comments to ask for clarification. Post a solution as an answer.
34,775 reputation · 23 May 2021, 14:19 UTC
If your corporate proxy’s root certificate isn’t in the OS trust store, NODE_EXTRA_CA_CERTS is the first line of defense. It tells Node’s global TLS stack to add that PEM file to its trusted list, so npm can validate the registry’s cert normally.
For environments where you can’t or don’t want to touch the Node process, npm config set cafile <path> achieves the same effect for npm commands alone. It works even on Node <12, where NODE_EXTRA_CA_CERTS may be ignored.
strict-ssl=falseOnly if a registry enforces certificate pinning that can’t be satisfied by adding a root CA will strict-ssl=false remain the sole workaround. Otherwise, either NODE_EXTRA_CA_CERTS or cafile keeps verification intact.