From 3f6a0c31a60ed1257d3f7ac0b766f361117fbf6d Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Thu, 9 May 2024 14:34:48 +0200 Subject: [PATCH] fix(node): Ensure `execArgv` are not sent to worker threads --- .../local-variables-instrument.js | 8 +++++ .../local-variables-no-sentry.js | 31 +++++++++++++++++++ .../suites/public-api/LocalVariables/test.ts | 10 ++++++ packages/node/src/integrations/anr/index.ts | 2 ++ .../local-variables/local-variables-async.ts | 2 ++ 5 files changed, 53 insertions(+) create mode 100644 dev-packages/node-integration-tests/suites/public-api/LocalVariables/local-variables-instrument.js create mode 100644 dev-packages/node-integration-tests/suites/public-api/LocalVariables/local-variables-no-sentry.js diff --git a/dev-packages/node-integration-tests/suites/public-api/LocalVariables/local-variables-instrument.js b/dev-packages/node-integration-tests/suites/public-api/LocalVariables/local-variables-instrument.js new file mode 100644 index 000000000000..0b39efcfd8db --- /dev/null +++ b/dev-packages/node-integration-tests/suites/public-api/LocalVariables/local-variables-instrument.js @@ -0,0 +1,8 @@ +const Sentry = require('@sentry/node'); +const { loggingTransport } = require('@sentry-internal/node-integration-tests'); + +Sentry.init({ + dsn: 'https://public@dsn.ingest.sentry.io/1337', + includeLocalVariables: true, + transport: loggingTransport, +}); diff --git a/dev-packages/node-integration-tests/suites/public-api/LocalVariables/local-variables-no-sentry.js b/dev-packages/node-integration-tests/suites/public-api/LocalVariables/local-variables-no-sentry.js new file mode 100644 index 000000000000..08636175fa7b --- /dev/null +++ b/dev-packages/node-integration-tests/suites/public-api/LocalVariables/local-variables-no-sentry.js @@ -0,0 +1,31 @@ +/* eslint-disable no-unused-vars */ +process.on('uncaughtException', () => { + // do nothing - this will prevent the Error below from closing this process +}); + +class Some { + two(name) { + throw new Error('Enough!'); + } +} + +function one(name) { + const arr = [1, '2', null]; + const obj = { + name, + num: 5, + }; + const bool = false; + const num = 0; + const str = ''; + const something = undefined; + const somethingElse = null; + + const ty = new Some(); + + ty.two(name); +} + +setTimeout(() => { + one('some name'); +}, 1000); diff --git a/dev-packages/node-integration-tests/suites/public-api/LocalVariables/test.ts b/dev-packages/node-integration-tests/suites/public-api/LocalVariables/test.ts index e2aa6c405773..61b9fc3064a4 100644 --- a/dev-packages/node-integration-tests/suites/public-api/LocalVariables/test.ts +++ b/dev-packages/node-integration-tests/suites/public-api/LocalVariables/test.ts @@ -59,6 +59,16 @@ conditionalTest({ min: 18 })('LocalVariables integration', () => { .start(done); }); + test('Should include local variables when instrumenting via --require', done => { + const requirePath = path.resolve(__dirname, 'local-variables-instrument.js'); + + createRunner(__dirname, 'local-variables-no-sentry.js') + .withFlags(`--require=${requirePath}`) + .ignore('session') + .expect({ event: EXPECTED_LOCAL_VARIABLES_EVENT }) + .start(done); + }); + test('Should include local variables with ESM', done => { createRunner(__dirname, 'local-variables-caught.mjs') .ignore('session') diff --git a/packages/node/src/integrations/anr/index.ts b/packages/node/src/integrations/anr/index.ts index 2cf32289f082..9d6382de45da 100644 --- a/packages/node/src/integrations/anr/index.ts +++ b/packages/node/src/integrations/anr/index.ts @@ -156,6 +156,8 @@ async function _startWorker( const worker = new Worker(new URL(`data:application/javascript;base64,${base64WorkerScript}`), { workerData: options, + // We don't want any Node args to be passed to the worker + execArgv: [], }); process.on('exit', () => { diff --git a/packages/node/src/integrations/local-variables/local-variables-async.ts b/packages/node/src/integrations/local-variables/local-variables-async.ts index b8e827909ea8..24667b3a57e3 100644 --- a/packages/node/src/integrations/local-variables/local-variables-async.ts +++ b/packages/node/src/integrations/local-variables/local-variables-async.ts @@ -84,6 +84,8 @@ export const localVariablesAsyncIntegration = defineIntegration((( function startWorker(options: LocalVariablesWorkerArgs): void { const worker = new Worker(new URL(`data:application/javascript;base64,${base64WorkerScript}`), { workerData: options, + // We don't want any Node args to be passed to the worker + execArgv: [], }); process.on('exit', () => {