From c4159f3af40322a144c1dff0d13a925538f9e371 Mon Sep 17 00:00:00 2001 From: Gabriel Almeida Date: Sun, 28 May 2023 11:55:00 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(utilities.py):=20use=20ast.l?= =?UTF-8?q?iteral=5Feval=20instead=20of=20eval=20to=20improve=20security?= =?UTF-8?q?=20=F0=9F=90=9B=20fix(GenericNode):=20add=20semicolon=20to=20co?= =?UTF-8?q?nsole.log=20statement=20The=20use=20of=20eval=20in=20the=20code?= =?UTF-8?q?=20can=20be=20a=20security=20risk=20as=20it=20can=20execute=20a?= =?UTF-8?q?rbitrary=20code.=20Using=20ast.literal=5Feval=20instead=20of=20?= =?UTF-8?q?eval=20is=20a=20safer=20alternative=20as=20it=20only=20evaluate?= =?UTF-8?q?s=20a=20subset=20of=20Python=20expressions.=20The=20semicolon?= =?UTF-8?q?=20was=20added=20to=20the=20console.log=20statement=20to=20impr?= =?UTF-8?q?ove=20code=20consistency.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/template/frontend_node/utilities.py | 3 ++- src/frontend/src/CustomNodes/GenericNode/index.tsx | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/backend/langflow/template/frontend_node/utilities.py b/src/backend/langflow/template/frontend_node/utilities.py index 77d01a23e..615d7d12f 100644 --- a/src/backend/langflow/template/frontend_node/utilities.py +++ b/src/backend/langflow/template/frontend_node/utilities.py @@ -1,3 +1,4 @@ +import ast import json from typing import Optional @@ -12,7 +13,7 @@ class UtilitiesFrontendNode(FrontendNode): # field.field_type could be "Literal['news', 'search', 'places', 'images'] # we need to convert it to a list if "Literal" in field.field_type: - field.options = eval(field.field_type.replace("Literal", "")) + field.options = ast.literal_eval(field.field_type.replace("Literal", "")) field.is_list = True field.field_type = "str" diff --git a/src/frontend/src/CustomNodes/GenericNode/index.tsx b/src/frontend/src/CustomNodes/GenericNode/index.tsx index 3409f8d9e..1427d1a76 100644 --- a/src/frontend/src/CustomNodes/GenericNode/index.tsx +++ b/src/frontend/src/CustomNodes/GenericNode/index.tsx @@ -85,7 +85,7 @@ export default function GenericNode({ deleteNode(data.id); return; } - console.log(data) + console.log(data); return (