fix(HTTP Request Node): Fix prototype pollution vulnerability (#15463)

This commit is contained in:
Elias Meire
2025-05-20 15:39:33 +02:00
committed by GitHub
parent 8d1170e3dd
commit 1ffc33dcc6
6 changed files with 65 additions and 9 deletions

View File

@@ -7,7 +7,7 @@ import type {
IHttpRequestMethods,
IRequestOptions,
} from 'n8n-workflow';
import { NodeApiError } from 'n8n-workflow';
import { isSafeObjectProperty, NodeApiError } from 'n8n-workflow';
import { getGoogleAccessToken } from '../../GenericFunctions';
@@ -82,8 +82,6 @@ export async function googleApiRequestAllItems(
const isValidDate = (str: string) =>
moment(str, ['YYYY-MM-DD HH:mm:ss Z', moment.ISO_8601], true).isValid();
const protoKeys = ['__proto__', 'prototype', 'constructor'];
// Both functions below were taken from Stack Overflow jsonToDocument was fixed as it was unable to handle null values correctly
// https://stackoverflow.com/questions/62246410/how-to-convert-a-firestore-document-to-plain-json-and-vice-versa
// Great thanks to https://stackoverflow.com/users/3915246/mahindar
@@ -108,7 +106,7 @@ export function jsonToDocument(value: string | number | IDataObject | IDataObjec
} else if (typeof value === 'object') {
const obj: IDataObject = {};
for (const key of Object.keys(value)) {
if (value.hasOwnProperty(key) && !protoKeys.includes(key)) {
if (value.hasOwnProperty(key) && isSafeObjectProperty(key)) {
obj[key] = jsonToDocument((value as IDataObject)[key] as IDataObject);
}
}

View File

@@ -4,6 +4,7 @@ import isPlainObject from 'lodash/isPlainObject';
import set from 'lodash/set';
import {
deepCopy,
setSafeObjectProperty,
type ICredentialDataDecryptedObject,
type IDataObject,
type INodeExecutionData,
@@ -48,7 +49,7 @@ function redact<T = unknown>(obj: T, secrets: string[]): T {
return obj.map((item) => redact(item, secrets)) as T;
} else if (isObject(obj)) {
for (const [key, value] of Object.entries(obj)) {
(obj as IDataObject)[key] = redact(value, secrets);
setSafeObjectProperty(obj, key, redact(value, secrets));
}
}