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

[ML] Various fixes for possible prototype pollution vulnerabilities #194529

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,9 @@ describe('object_utils', () => {

const test11 = setNestedProperty(getFalseyObject(), 'the.other_nested.value', 'update');
expect(test11.the.other_nested.value).toBe('update');

const test12 = setNestedProperty(getTestObj(), 'the.__proto__', 'update');
expect(test12.the).toBe('update');
expect(test12.the.__proto__.update).toBe(undefined);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

export const setNestedProperty = (obj: Record<string, any>, accessor: string, value: any) => {
let ref = obj;
const accessors = accessor.split('.');
const accessors = accessor.split('.').filter((a) => a !== '__proto__');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we consider constructor too? I'm unsure if we should silently ignore like now or do the check in the for loop and throw, what do you think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in 734ae86

const len = accessors.length;
for (let i = 0; i < len - 1; i++) {
const attribute = accessors[i];
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/ml/server/saved_objects/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ export function mlSavedObjectServiceFactory(
if (id.match('\\*') === null) {
return jobIds.includes(id);
}
const regex = new RegExp(id.replace('*', '.*'));
const regex = new RegExp(id.replaceAll('*', '.*'));
return jobIds.some((jId) => typeof jId === 'string' && regex.exec(jId));
});
}
Expand Down Expand Up @@ -640,7 +640,7 @@ export function mlSavedObjectServiceFactory(
if (id.match('\\*') === null) {
return modelIds.includes(id);
}
const regex = new RegExp(id.replace('*', '.*'));
const regex = new RegExp(id.replaceAll('*', '.*'));
return modelIds.some((jId) => typeof jId === 'string' && regex.exec(jId));
});
}
Expand Down