From 55c2b61921348733691b8381bdd52d4182b37578 Mon Sep 17 00:00:00 2001 From: -LAN- Date: Thu, 25 Jul 2024 11:30:52 +0800 Subject: [PATCH] fix(api/fields/workflow_fields.py): Add check in environment variables (#6621) --- api/fields/workflow_fields.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/api/fields/workflow_fields.py b/api/fields/workflow_fields.py index c98c33202..ff33a97ff 100644 --- a/api/fields/workflow_fields.py +++ b/api/fields/workflow_fields.py @@ -1,10 +1,12 @@ from flask_restful import fields -from core.app.segments import SecretVariable, Variable +from core.app.segments import SecretVariable, SegmentType, Variable from core.helper import encrypter from fields.member_fields import simple_account_fields from libs.helper import TimestampField +ENVIRONMENT_VARIABLE_SUPPORTED_TYPES = (SegmentType.STRING, SegmentType.NUMBER, SegmentType.SECRET) + class EnvironmentVariableField(fields.Raw): def format(self, value): @@ -16,14 +18,18 @@ class EnvironmentVariableField(fields.Raw): 'value': encrypter.obfuscated_token(value.value), 'value_type': value.value_type.value, } - elif isinstance(value, Variable): + if isinstance(value, Variable): return { 'id': value.id, 'name': value.name, 'value': value.value, 'value_type': value.value_type.value, } - return value + if isinstance(value, dict): + value_type = value.get('value_type') + if value_type not in ENVIRONMENT_VARIABLE_SUPPORTED_TYPES: + raise ValueError(f'Unsupported environment variable value type: {value_type}') + return value environment_variable_fields = {