mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[ML] Improving empty object creation in ML packages (#191901)
Replacing instances of empty object creation with Object.create(null) to remove any risk of prototype pollution. Related to https://github.com/elastic/kibana/pull/191518
This commit is contained in:
parent
bac95ead5b
commit
e204184a2a
8 changed files with 12 additions and 9 deletions
|
@ -16,7 +16,7 @@ export function getFieldValuePairCounts(cpgs: SignificantItemGroup[]): FieldValu
|
|||
return cpgs.reduce<FieldValuePairCounts>((p, { group }) => {
|
||||
group.forEach(({ fieldName, fieldValue }) => {
|
||||
if (p[fieldName] === undefined) {
|
||||
p[fieldName] = {};
|
||||
p[fieldName] = Object.create(null);
|
||||
}
|
||||
p[fieldName][fieldValue] = p[fieldName][fieldValue] ? p[fieldName][fieldValue] + 1 : 1;
|
||||
});
|
||||
|
|
|
@ -45,4 +45,8 @@ describe('isPopulatedObject', () => {
|
|||
])
|
||||
).toBe(false);
|
||||
});
|
||||
it('does not allow an object with a required attribute in the prototype ', () => {
|
||||
const testObject = { attribute: 'value', __proto__: { otherAttribute: 'value' } };
|
||||
expect(isPopulatedObject(testObject, ['otherAttribute'])).toBe(false);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -30,7 +30,6 @@ export const isPopulatedObject = <U extends string = string, T extends unknown =
|
|||
typeof arg === 'object' &&
|
||||
arg !== null &&
|
||||
Object.keys(arg).length > 0 &&
|
||||
(requiredAttributes.length === 0 ||
|
||||
requiredAttributes.every((d) => ({}.hasOwnProperty.call(arg, d))))
|
||||
(requiredAttributes.length === 0 || requiredAttributes.every((d) => Object.hasOwn(arg, d)))
|
||||
);
|
||||
};
|
||||
|
|
|
@ -68,7 +68,7 @@ export class JsonSchemaService {
|
|||
};
|
||||
}
|
||||
|
||||
private allComponents: Record<string, object> = {};
|
||||
private allComponents: Record<string, object> = Object.create(null);
|
||||
private componentsDict = new Set<string>();
|
||||
|
||||
/**
|
||||
|
|
|
@ -12,7 +12,7 @@ export const setNestedProperty = (obj: Record<string, any>, accessor: string, va
|
|||
for (let i = 0; i < len - 1; i++) {
|
||||
const attribute = accessors[i];
|
||||
if (typeof ref[attribute] !== 'object') {
|
||||
ref[attribute] = {};
|
||||
ref[attribute] = Object.create(null);
|
||||
}
|
||||
|
||||
ref = ref[attribute];
|
||||
|
|
|
@ -158,7 +158,7 @@ export class RandomSampler {
|
|||
const mode = this.getMode();
|
||||
const probability = this.getProbability();
|
||||
|
||||
let prob = {};
|
||||
let prob = Object.create(null);
|
||||
if (mode === RANDOM_SAMPLER_OPTION.ON_MANUAL) {
|
||||
prob = { probability };
|
||||
} else if (mode === RANDOM_SAMPLER_OPTION.OFF) {
|
||||
|
|
|
@ -18,7 +18,7 @@ export function getCombinedRuntimeMappings(
|
|||
dataView: DataView | undefined,
|
||||
runtimeMappings?: RuntimeMappings
|
||||
): RuntimeMappings | undefined {
|
||||
let combinedRuntimeMappings = {};
|
||||
let combinedRuntimeMappings = Object.create(null);
|
||||
|
||||
// Add runtime field mappings defined by index pattern
|
||||
if (dataView) {
|
||||
|
|
|
@ -67,7 +67,7 @@ export function isRisonSerializationRequired(queryParam: string): boolean {
|
|||
}
|
||||
|
||||
export function parseUrlState(search: string): Dictionary<any> {
|
||||
const urlState: Dictionary<any> = {};
|
||||
const urlState: Dictionary<any> = Object.create(null);
|
||||
const parsedQueryString = parse(search, { sort: false });
|
||||
|
||||
try {
|
||||
|
@ -125,7 +125,7 @@ export const UrlStateProvider: FC<PropsWithChildren<unknown>> = ({ children }) =
|
|||
const parsedQueryString = parse(prevSearchString, { sort: false });
|
||||
|
||||
if (!Object.hasOwn(urlState, accessor)) {
|
||||
urlState[accessor] = {};
|
||||
urlState[accessor] = Object.create(null);
|
||||
}
|
||||
|
||||
if (typeof attribute === 'string') {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue