Skip to content

Commit 435bb2a

Browse files
authored
fix(api): 使用 ast.literal_eval 代替 eval,取消不正确的计算属性值返回。 (#688)
* fix(api): 使用 ast.literal_eval 代替 eval,取消不正确的计算属性值返回。 * fix(api): 修复属性值计算逻辑,直接返回渲染结果。
1 parent 5ceb8ff commit 435bb2a

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

cmdb-api/api/lib/cmdb/value.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,15 @@ def write_change2(changed, record_id=None, ticket_id=None):
180180

181181
@staticmethod
182182
def _compute_attr_value_from_expr(expr, ci_dict):
183-
t = jinja2.Template(expr).render(ci_dict)
184-
185183
try:
186-
return eval(t)
184+
result = jinja2.Template(expr).render(ci_dict)
185+
return result
187186
except Exception as e:
188-
current_app.logger.warning(str(e))
189-
return t
190-
187+
current_app.logger.warning(
188+
f"Expression evaluation error - Expression: '{expr}'"
189+
f"Input parameters: {ci_dict}, Error type: {type(e).__name__}, Error message: {str(e)}"
190+
)
191+
return None
191192
@staticmethod
192193
def _compute_attr_value_from_script(script, ci_dict):
193194
script = jinja2.Template(script).render(ci_dict)

0 commit comments

Comments
 (0)