fix(editor): Prevent node renaming to restricted JS method names (#16270)

This commit is contained in:
oleg
2025-06-12 16:11:36 +02:00
committed by GitHub
parent 739ad853cd
commit ecfb6674ef
4 changed files with 188 additions and 2 deletions

View File

@@ -7,6 +7,7 @@ import {
NODES_WITH_RENAMABLE_CONTENT,
STARTING_NODE_TYPES,
} from './constants';
import { UserError } from './errors';
import { ApplicationError } from './errors/application.error';
import { Expression } from './expression';
import { getGlobalState } from './global-state';
@@ -379,6 +380,29 @@ export class Workflow {
* @param {string} newName The new name
*/
renameNode(currentName: string, newName: string) {
// These keys are excluded to prevent accidental modification of inherited properties and
// to avoid any issues related to JavaScript's built-in methods that can cause unexpected behavior
const restrictedKeys = [
'hasOwnProperty',
'isPrototypeOf',
'propertyIsEnumerable',
'toLocaleString',
'toString',
'valueOf',
'constructor',
'prototype',
'__proto__',
'__defineGetter__',
'__defineSetter__',
'__lookupGetter__',
'__lookupSetter__',
];
if (restrictedKeys.map((k) => k.toLowerCase()).includes(newName.toLowerCase())) {
throw new UserError(`Node name "${newName}" is a restricted name.`, {
description: `Node names cannot be any of the following: ${restrictedKeys.join(', ')}`,
});
}
// Rename the node itself
if (this.nodes[currentName] !== undefined) {
this.nodes[newName] = this.nodes[currentName];