Skip to content

Commit 28c7215

Browse files
authored
fix: Denial of Service via __proto__ Key in mergeConfig (#7369)
* fix: sec issue as per advisory * chore: expand and add tests
1 parent 04cf019 commit 28c7215

3 files changed

Lines changed: 459 additions & 155 deletions

File tree

lib/core/mergeConfig.js

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
'use strict';
1+
"use strict";
22

3-
import utils from '../utils.js';
3+
import utils from "../utils.js";
44
import AxiosHeaders from "./AxiosHeaders.js";
55

6-
const headersToObject = (thing) => thing instanceof AxiosHeaders ? { ...thing } : thing;
6+
const headersToObject = (thing) =>
7+
thing instanceof AxiosHeaders ? { ...thing } : thing;
78

89
/**
910
* Config-specific merge-function which creates a new config-object
@@ -92,14 +93,27 @@ export default function mergeConfig(config1, config2) {
9293
socketPath: defaultToConfig2,
9394
responseEncoding: defaultToConfig2,
9495
validateStatus: mergeDirectKeys,
95-
headers: (a, b, prop) => mergeDeepProperties(headersToObject(a), headersToObject(b), prop, true)
96+
headers: (a, b, prop) =>
97+
mergeDeepProperties(headersToObject(a), headersToObject(b), prop, true),
9698
};
9799

98-
utils.forEach(Object.keys({ ...config1, ...config2 }), function computeConfigValue(prop) {
99-
const merge = mergeMap[prop] || mergeDeepProperties;
100-
const configValue = merge(config1[prop], config2[prop], prop);
101-
(utils.isUndefined(configValue) && merge !== mergeDirectKeys) || (config[prop] = configValue);
102-
});
100+
utils.forEach(
101+
Object.keys({ ...config1, ...config2 }),
102+
function computeConfigValue(prop) {
103+
if (
104+
prop === "__proto__" ||
105+
prop === "constructor" ||
106+
prop === "prototype"
107+
)
108+
return;
109+
const merge = utils.hasOwnProp(mergeMap, prop)
110+
? mergeMap[prop]
111+
: mergeDeepProperties;
112+
const configValue = merge(config1[prop], config2[prop], prop);
113+
(utils.isUndefined(configValue) && merge !== mergeDirectKeys) ||
114+
(config[prop] = configValue);
115+
},
116+
);
103117

104118
return config;
105119
}

0 commit comments

Comments
 (0)