Skip to content

Commit 939225e

Browse files
committed
fix prototype pollution
1 parent 9df411e commit 939225e

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

tools/cds-lint/components/PlaygroundBadge.vue

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,12 @@ export default [
3333
3434
const defaultPackageJson = JSON.parse(data['package.json']);
3535
36-
function mergeJSONs(target: any, add: any) {
37-
const isObject = (obj: unknown) => typeof obj === 'object';
38-
Object.entries(add).forEach(([key, addVal]) => {
39-
const targetVal = target[key];
40-
if (targetVal && isObject(targetVal) && isObject(addVal)) {
41-
if ((Array.isArray(targetVal) && Array.isArray(addVal))) {
42-
targetVal.push(...addVal);
43-
return;
44-
}
45-
mergeJSONs(targetVal, addVal);
46-
} else {
47-
target[key] = addVal;
48-
}
49-
});
50-
return target;
36+
const is_object = x => typeof x === 'object' && x !== null && !Array.isArray(x)
37+
function merge (o:any,...xs:any) {
38+
let v:any; for (let x of xs) for (let k in x)
39+
if (k === '__proto__' || k === 'constructor') continue //> avoid prototype pollution
40+
else o[k] = is_object(v=x[k]) ? merge(o[k]??={},v) : v
41+
return o
5142
}
5243
5344
function link(name: Props['name'] = "", kind: Props['kind'], rules?: Props['rules'], files?: Props['files'], packages?: Props['packages'] ): string {
@@ -66,7 +57,7 @@ function link(name: Props['name'] = "", kind: Props['kind'], rules?: Props['rule
6657
sources[configFileName] = defaultConfig;
6758
}
6859
if (packages) {
69-
json = mergeJSONs(defaultPackageJson, packages);
60+
json = merge(defaultPackageJson, packages);
7061
} else {
7162
json = defaultPackageJson;
7263
}

0 commit comments

Comments
 (0)