Skip to content

Commit f48f8d3

Browse files
vuusaledurran
andauthored
feat(NODE-6225): add property ownership check before referencing mongocryptdSpawnPath and mongocryptdSpawnArgs (#4151)
Co-authored-by: Durran Jordan <[email protected]>
1 parent d85f827 commit f48f8d3

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

src/client-side-encryption/mongocryptd_manager.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ export class MongocryptdManager {
1212

1313
uri: string;
1414
bypassSpawn: boolean;
15-
spawnPath: string;
16-
spawnArgs: Array<string>;
15+
spawnPath = '';
16+
spawnArgs: Array<string> = [];
1717
_child?: ChildProcess;
1818

1919
constructor(extraOptions: AutoEncryptionExtraOptions = {}) {
@@ -24,9 +24,13 @@ export class MongocryptdManager {
2424

2525
this.bypassSpawn = !!extraOptions.mongocryptdBypassSpawn;
2626

27-
this.spawnPath = extraOptions.mongocryptdSpawnPath || '';
28-
this.spawnArgs = [];
29-
if (Array.isArray(extraOptions.mongocryptdSpawnArgs)) {
27+
if (Object.hasOwn(extraOptions, 'mongocryptdSpawnPath') && extraOptions.mongocryptdSpawnPath) {
28+
this.spawnPath = extraOptions.mongocryptdSpawnPath;
29+
}
30+
if (
31+
Object.hasOwn(extraOptions, 'mongocryptdSpawnArgs') &&
32+
Array.isArray(extraOptions.mongocryptdSpawnArgs)
33+
) {
3034
this.spawnArgs = this.spawnArgs.concat(extraOptions.mongocryptdSpawnArgs);
3135
}
3236
if (

test/unit/client-side-encryption/mongocryptd_manager.test.ts

+10
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ describe('MongocryptdManager', function () {
2222
expect(mcdm.spawnArgs).to.deep.equal(['--idleShutdownTimeoutSecs', '12']);
2323
});
2424

25+
it('does not allow prototype pollution on spawn path', function () {
26+
const mcdm = new MongocryptdManager({ __proto__: { mongocryptdSpawnPath: 'test' } });
27+
expect(mcdm.spawnPath).to.equal('');
28+
});
29+
30+
it('does not allow prototype pollution on spawn args', function () {
31+
const mcdm = new MongocryptdManager({ __proto__: { mongocryptdSpawnArgs: ['test'] } });
32+
expect(mcdm.spawnArgs).to.deep.equal(['--idleShutdownTimeoutSecs', '60']);
33+
});
34+
2535
it('should not override `idleShutdownTimeoutSecs` if the user sets it using `key=value` form', function () {
2636
const mcdm = new MongocryptdManager({
2737
mongocryptdSpawnArgs: ['--idleShutdownTimeoutSecs=12']

tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"skipLibCheck": true,
1111
"lib": [
1212
"es2021",
13-
"ES2022.Error"
13+
"ES2022.Error",
14+
"ES2022.Object"
1415
],
1516
// We don't make use of tslib helpers, all syntax used is supported by target engine
1617
"importHelpers": false,

0 commit comments

Comments
 (0)