Skip to content
Open
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
4 changes: 4 additions & 0 deletions src/process_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ class ProcessWrap : public HandleWrap {
if (!stdios->Get(context, i).ToLocal(&val)) {
return Nothing<void>();
}
if (!val->IsObject()) {
THROW_ERR_INVALID_ARG_TYPE(env, "options.stdio elements must be objects");
return Nothing<void>();
}
Local<Object> stdio = val.As<Object>();
Local<Value> type;
if (!stdio->Get(context, env->type_string()).ToLocal(&type)) {
Expand Down
19 changes: 19 additions & 0 deletions test/parallel/test-child-process-array-prototype-pollution.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';
require('../common');
const assert = require('assert');
const { exec } = require('child_process');

Object.defineProperty(Array.prototype, '2', { set: function () {} });

Check failure on line 6 in test/parallel/test-child-process-array-prototype-pollution.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Unexpected space before function parentheses

Check failure on line 6 in test/parallel/test-child-process-array-prototype-pollution.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Getter is not present in property descriptor

// child_process.exec() used to crash due to missing Array properties from prototype pollution.
// It should now throw a TypeError from C++ ProcessWrap::ParseStdioOptions instead of a fatal error.
assert.throws(
() => {
exec('echo 1');
},
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: /options\.stdio elements must be objects/
}
);
Loading