diff --git a/lib/internal/child_process.js b/lib/internal/child_process.js index be90d23f2a3203..d6121c70ef9943 100644 --- a/lib/internal/child_process.js +++ b/lib/internal/child_process.js @@ -665,6 +665,18 @@ function setupChannel(target, channel) { if (message === undefined) throw new ERR_MISSING_ARGS('message'); + // Non-serializable messages should not reach the remote + // end point; as any failure in the stringification there + // will result in error message that is weakly consumable. + // So perform a sanity check on message prior to sending. + if (typeof message !== 'string' && + typeof message !== 'object' && + typeof message !== 'number' && + typeof message !== 'boolean') { + throw new ERR_INVALID_ARG_TYPE( + 'message', ['string', 'object', 'number', 'boolean'], message); + } + // Support legacy function signature if (typeof options === 'boolean') { options = { swallowErrors: options }; diff --git a/test/parallel/test-child-process-fork.js b/test/parallel/test-child-process-fork.js index 6cfeeefb51952d..5fee2892f3b774 100644 --- a/test/parallel/test-child-process-fork.js +++ b/test/parallel/test-child-process-fork.js @@ -49,6 +49,12 @@ assert.throws(() => n.send(), { code: 'ERR_MISSING_ARGS' }); +assert.throws(() => n.send(Symbol()), { + name: 'TypeError [ERR_INVALID_ARG_TYPE]', + message: 'The "message" argument must be one of type string,' + + ' object, number, or boolean. Received type symbol', + code: 'ERR_INVALID_ARG_TYPE' +}); n.send({ hello: 'world' }); n.on('exit', common.mustCall((c) => {