Learning center

Remove the environment from a Node.js report before you share it

A Node.js diagnostic report includes every environment variable by default, so generate it with --report-exclude-env or delete that section first. A report attached to an issue can otherwise carry database passwords and tokens.

Verify it on your version#

mkdir rep rep2
DB_PASSWORD=hunter2 node --report-directory=rep -e 'process.report.writeReport()'
DB_PASSWORD=hunter2 node --report-exclude-env --report-directory=rep2 -e 'process.report.writeReport()'
grep -c hunter2 rep/*.json rep2/*.json

Writing the report from the script avoids racing a signal against startup. With Node 24.22 the counts are 1 and 0. The first report's environmentVariables.DB_PASSWORD is hunter2, and with --report-exclude-env the key environmentVariables is absent. A report triggered by a signal behaved the same. The CLI reference lists the option from versions 23.3.0 and 22.13.0. On older versions, remove the section afterwards:

jq 'del(.environmentVariables)' report.json > report-share.json

Other fields to read#

Excluding the environment is one field of several. The same report had these top-level keys: header, javascriptStack, javascriptHeap, nativeStack, resourceUsage, uvthreadResourceUsage, libuv, workers, environmentVariables, userLimits and sharedObjects.

FieldMay hold
header.commandLineA token passed as an argument
header.cwd, header.hostUsernames, internal host names
header.networkInterfacesInternal addresses. --report-exclude-network drops them
libuvAddresses of connected peers, file paths
javascriptStackAn error message, which can contain a value from the failing request
sharedObjectsLibrary paths and versions

Search for the values you know, and remember that a search only finds those:

jq -r '[paths(scalars) as $p | {p: ($p|map(tostring)|join(".")), v: (getpath($p)|tostring)}]
       | .[] | select(.v | test("token|secret|password|://[^/]*@"; "i")) | .p' report-share.json

It prints the paths of suspicious values and not the values. A random token that has none of those words in it passes unnoticed, so read commandLine and the stack's message yourself.

Decide what the receiver needs#

QuestionKeepDrop
Where is it stuck?Stacks, libuv handle typesEnvironment, network, addresses
Why did the heap grow?javascriptHeap, resourceUsageEnvironment, libuv
Which native module crashed?nativeStack, sharedObjects, versionsEnvironment

If a variable's presence matters, hand over its name and whether it was set. Do not send a hash of a secret in place of the value: a short or guessable one can be found by trying candidates. In a small test, every seven-digit number up to the target was hashed with SHA-256 and the right one found in 4 seconds, in one Python process.

If a report was already shared#

Treat every secret in it as exposed, and rotate it. Deleting an attachment does not recall the copies in notifications and backups. List the variable names from the original with jq -r '.environmentVariables | keys[]', so that the owners know which ones.

Worked example#

This example is fictional. Ana attaches a report to a public issue in a native module's repository. Ben notices environmentVariables in the file. The module's maintainers needed the native stack and the shared objects. The team rotates four credentials, attaches a version without the environment, the command line and the addresses, and adds --report-exclude-env to the service's start command.

To get the report in the first place, see capturing a hung process. Return to handing over evidence.

One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. Eligibility and fair-use terms.

Start free with GitHub

Related reading