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

feat(NODE-6225): add property ownership check before referencing mongocryptdSpawnPath and mongocryptdSpawnArgs #4151

Merged
merged 4 commits into from
Jul 1, 2024
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
14 changes: 9 additions & 5 deletions src/client-side-encryption/mongocryptd_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export class MongocryptdManager {

uri: string;
bypassSpawn: boolean;
spawnPath: string;
spawnArgs: Array<string>;
spawnPath = '';
spawnArgs: Array<string> = [];
_child?: ChildProcess;

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

this.bypassSpawn = !!extraOptions.mongocryptdBypassSpawn;

this.spawnPath = extraOptions.mongocryptdSpawnPath || '';
this.spawnArgs = [];
if (Array.isArray(extraOptions.mongocryptdSpawnArgs)) {
if (Object.hasOwn(extraOptions, 'mongocryptdSpawnPath') && extraOptions.mongocryptdSpawnPath) {
this.spawnPath = extraOptions.mongocryptdSpawnPath;
}
if (
Object.hasOwn(extraOptions, 'mongocryptdSpawnArgs') &&
Array.isArray(extraOptions.mongocryptdSpawnArgs)
) {
this.spawnArgs = this.spawnArgs.concat(extraOptions.mongocryptdSpawnArgs);
}
if (
Expand Down
10 changes: 10 additions & 0 deletions test/unit/client-side-encryption/mongocryptd_manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ describe('MongocryptdManager', function () {
expect(mcdm.spawnArgs).to.deep.equal(['--idleShutdownTimeoutSecs', '12']);
});

it('does not allow prototype pollution on spawn path', function () {
const mcdm = new MongocryptdManager({ __proto__: { mongocryptdSpawnPath: 'test' } });
expect(mcdm.spawnPath).to.equal('');
});

it('does not allow prototype pollution on spawn args', function () {
const mcdm = new MongocryptdManager({ __proto__: { mongocryptdSpawnArgs: ['test'] } });
expect(mcdm.spawnArgs).to.deep.equal(['--idleShutdownTimeoutSecs', '60']);
});

it('should not override `idleShutdownTimeoutSecs` if the user sets it using `key=value` form', function () {
const mcdm = new MongocryptdManager({
mongocryptdSpawnArgs: ['--idleShutdownTimeoutSecs=12']
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"skipLibCheck": true,
"lib": [
"es2021",
"ES2022.Error"
"ES2022.Error",
"ES2022.Object"
],
// We don't make use of tslib helpers, all syntax used is supported by target engine
"importHelpers": false,
Expand Down