Skip to content

Potential fix for code scanning alert no. 254: Code injection#55

Merged
brokermr810 merged 2 commits into
mainfrom
alert-autofix-254
Apr 22, 2026
Merged

Potential fix for code scanning alert no. 254: Code injection#55
brokermr810 merged 2 commits into
mainfrom
alert-autofix-254

Conversation

@brokermr810

Copy link
Copy Markdown
Collaborator

Potential fix for https://github.com/brokermr810/QuantDinger/security/code-scanning/254

通用修复思路:对所有来自 HTTP 的脚本代码,在进入 service 执行链前进行显式安全校验;未通过即返回 400,阻断 tainted 数据到 exec。保留 safe_exec_with_validation 内部校验作为第二道防线。

本次最佳单一修复方案(不改变既有功能):

  1. backend_api_python/app/routes/backtest.py 中增加对 indicator_code 的执行前校验(调用 app.utils.safe_exec.validate_code_safety)。
  2. 在提取 indicator_code 后、调用 backtest_service.run/run_multi_timeframe 前,若校验失败直接返回统一错误响应。
  3. 该改动不影响合法脚本执行流程,仅提前拒绝危险脚本,且可同时缓解同一 sink 的多变体告警。

需要的实现要点:

  • 新增 import:from app.utils.safe_exec import validate_code_safety
  • 新增校验逻辑与错误返回分支(位于 indicator_code 读取之后)

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Comment thread backend_api_python/app/routes/backtest.py Fixed
… through an exception'

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@brokermr810
brokermr810 marked this pull request as ready for review April 22, 2026 06:08
@brokermr810
brokermr810 merged commit 1c0bcef into main Apr 22, 2026
6 checks passed
@brokermr810
brokermr810 deleted the alert-autofix-254 branch April 22, 2026 06:12
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