From 67e520cfd6eee8b02f20b271af9aa4e762097c1a Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Thu, 30 Nov 2023 16:43:28 -0300 Subject: [PATCH] fix(shareModal): import removeFileNameFromComponents function to fix compilation error feat(shareModal): add logic to remove file names from flows before sharing to improve privacy and security feat(reactflowUtils): add removeFileNameFromComponents function to recursively remove file names from flow components --- src/frontend/src/modals/shareModal/index.tsx | 7 ++++++- src/frontend/src/utils/reactflowUtils.ts | 13 +++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/frontend/src/modals/shareModal/index.tsx b/src/frontend/src/modals/shareModal/index.tsx index d09d03122..1ac076596 100644 --- a/src/frontend/src/modals/shareModal/index.tsx +++ b/src/frontend/src/modals/shareModal/index.tsx @@ -13,7 +13,10 @@ import { saveFlowStore, } from "../../controllers/API"; import { FlowType } from "../../types/flow"; -import { removeApiKeys } from "../../utils/reactflowUtils"; +import { + removeApiKeys, + removeFileNameFromComponents, +} from "../../utils/reactflowUtils"; import { getTagsIds } from "../../utils/storeUtils"; import BaseModal from "../baseModal"; @@ -81,6 +84,8 @@ export default function ShareModal({ }, [component, open, internalOpen]); const handleShareComponent = () => { + //remove file names from flows before sharing + removeFileNameFromComponents(component); const flow: FlowType = checked ? { id: component!.id, diff --git a/src/frontend/src/utils/reactflowUtils.ts b/src/frontend/src/utils/reactflowUtils.ts index 6dbb70651..6c8e8627a 100644 --- a/src/frontend/src/utils/reactflowUtils.ts +++ b/src/frontend/src/utils/reactflowUtils.ts @@ -1096,3 +1096,16 @@ export function updateComponentNameAndType( data: any, component: NodeDataType ) {} + +export function removeFileNameFromComponents(flow: FlowType) { + flow.data!.nodes.forEach((node: NodeType) => { + Object.keys(node.data.node!.template).forEach((field) => { + if (node.data.node?.template[field].type === "file") { + node.data.node!.template[field].value = ""; + } + }); + if (node.data.node?.flow) { + removeFileNameFromComponents(node.data.node.flow); + } + }); +}