Skip to content

[OSS26] 追踪方法上游调用链 trace_call_chain_upstream_by_method_name #141

@ponyha

Description

@ponyha

接口介绍

从一个目标方法出发,反向追溯所有可能到达它的调用链(多层、多分支),直到遇到入口方法(如 Spring Controller)或达到深度上限;返回链路上每一跳的方法、行号、入口标识。

工具名

trace_call_chain_upstream_by_method_name

背景与目标

单层 caller 查找只看一层。在安全审计中,我们经常需要从一个 sink 一路反推到 HTTP 入口:

  • Statement.execute(sql)UserDao.searchUserService.findUserController.search(用户可达)
  • 这条链揭示了"用户输入 → 危险操作"的完整路径

这是 YASA 跨仓审计的核心入口。本任务先做单仓库版,跨仓由后续工具补足。

输入参数

参数 类型 必填 说明
method_full_name string 目标方法(链的终点 / sink)全限定名
parameter_types string[] 形参类型重载消歧
repository_path string 仓库本地绝对路径
max_depth int 默认 5,最大 10。链深度限制
max_chains int 默认 50。返回的不同调用链上限
stop_at_entry_kind enum(any, controller, public_api, none) 默认 controller。遇到 Controller 类或带 @RequestMapping 等入口注解的方法即停
include_test_code bool 默认 false

输出结构

{
  "target_method": "com.example.dao.UserDao.executeRawSql",
  "total_chains": 3,
  "max_depth_reached": 4,
  "chains": [
    {
      "chain_id": 1,
      "depth": 4,
      "entry_point": {
        "method_full_name": "com.example.controller.SearchController.search",
        "entry_kind": "controller",
        "http_route": "GET /search"
      },
      "path": [
        {"method_full_name": "com.example.controller.SearchController.search", "line": 32, "calls_next_at_line": 36},
        {"method_full_name": "com.example.service.SearchService.run", "line": 18, "calls_next_at_line": 24},
        {"method_full_name": "com.example.dao.UserDao.search", "line": 55, "calls_next_at_line": 58},
        {"method_full_name": "com.example.dao.UserDao.executeRawSql", "line": 102, "calls_next_at_line": null}
      ]
    }
  ],
  "truncated": false
}

验收标准

  • 正确反向遍历调用图直到 entry 类(Controller 等)或达到 max_depth
  • 同一方法在不同链中按不同 path 返回,链与链独立去重(但不丢失分支)
  • entry_kind 至少识别 Spring @Controller/@RestController/@RequestMapping(可扩展)
  • 检测循环调用并标记 truncated_reason: "cycle"
  • 单元测试覆盖:多链分支、循环、超出 max_depth、未找到上游
  • 中等仓库响应 < 20s

预估工作量

10-14 人日(团队协作:调用图持久化 + 反向 BFS + entry 识别)

Metadata

Metadata

Assignees

No one assigned

    Labels

    OSS26-TeamOSS26 需要团队协作的复杂任务

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions