Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

child_process: ensure message sanity at send source #24787

Merged
merged 1 commit into from
Mar 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/internal/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down
6 changes: 6 additions & 0 deletions test/parallel/test-child-process-fork.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down