Skip to content

Conversation

@guohelu
Copy link
Collaborator

@guohelu guohelu commented Nov 12, 2025

Reviewed, transaction id: 64092

@dengyh dengyh closed this Nov 12, 2025
@dengyh dengyh reopened this Nov 12, 2025
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

代码审查总结

已审查 PR #443 的权限校验改进,发现以下需要关注的问题:

🚨 高优先级问题

1. 运行时安全 (bkflow/permission/models.py:174)

if not getattr(cls, map_func)(db_token, resource_id):

getattr(cls, map_func) 缺少异常处理。如果 map_funcNone 或方法不存在会抛出 AttributeError。

建议if map_func and hasattr(cls, map_func) and not getattr(cls, map_func)(db_token, resource_id): ...

⚡ 性能风险

2. N+1 查询问题 (bkflow/permission/models.py:205)

template_reference = TemplateReference.objects.filter(subprocess_template_id=current_template_id)

每次递归都执行数据库查询,深层嵌套时可能触发大量查询,影响性能。

建议:考虑使用 CTE、缓存或添加递归深度限制(如最大10层)

⚠️ 逻辑完整性

3. 循环引用风险 (bkflow/permission/models.py:211-217)
如果模板引用存在循环依赖(A→B→A),递归会导致无限循环或栈溢出。

建议:添加访问路径跟踪集合 visited_ids = set() 或最大递归深度检查


整体改进合理,建议重点处理第1项的运行时安全问题。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants