mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-19 02:51:14 +00:00
fix(editor): Prevent node renaming to restricted JS method names (#16270)
This commit is contained in:
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user