mirror of
https://github.com/tenrok/axios.git
synced 2026-06-20 20:00:40 +03:00
fix(security): fixed formToJSON prototype pollution vulnerability; (#6167)
This commit is contained in:
@@ -49,6 +49,9 @@ function arrayToObject(arr) {
|
|||||||
function formDataToJSON(formData) {
|
function formDataToJSON(formData) {
|
||||||
function buildPath(path, value, target, index) {
|
function buildPath(path, value, target, index) {
|
||||||
let name = path[index++];
|
let name = path[index++];
|
||||||
|
|
||||||
|
if (name === '__proto__') return true;
|
||||||
|
|
||||||
const isNumericKey = Number.isFinite(+name);
|
const isNumericKey = Number.isFinite(+name);
|
||||||
const isLast = index >= path.length;
|
const isLast = index >= path.length;
|
||||||
name = !name && utils.isArray(target) ? target.length : name;
|
name = !name && utils.isArray(target) ? target.length : name;
|
||||||
|
|||||||
@@ -47,4 +47,25 @@ describe('formDataToJSON', function () {
|
|||||||
foo: ['1', '2']
|
foo: ['1', '2']
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should resist prototype pollution CVE', () => {
|
||||||
|
const formData = new FormData();
|
||||||
|
|
||||||
|
formData.append('foo[0]', '1');
|
||||||
|
formData.append('foo[1]', '2');
|
||||||
|
formData.append('__proto__.x', 'hack');
|
||||||
|
formData.append('constructor.prototype.y', 'value');
|
||||||
|
|
||||||
|
expect(formDataToJSON(formData)).toEqual({
|
||||||
|
foo: ['1', '2'],
|
||||||
|
constructor: {
|
||||||
|
prototype: {
|
||||||
|
y: 'value'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expect({}.x).toEqual(undefined);
|
||||||
|
expect({}.y).toEqual(undefined);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user