📦 Axum Code Review — Axum代码审查
v1.0.1针对 Rust Axum Web 框架的专项代码审查工具,自动检查路由、提取器、中间件、状态管理及错误处理,适配 Rust 2024 新语法与最佳实践。
0· 121·1 当前·1 累计
安全扫描
OpenClaw
安全
high confidenceThis is an instruction-only Axum/Rust code-review helper whose files, checklist, and declared requirements are consistent with the stated purpose and do not request external credentials or installs.
评估建议
This skill appears coherent and low-risk: it contains only review guidance and reference docs for Axum/Rust and does not request secrets or installs. Two practical checks before using it: (1) The SKILL.md asks you to "Load and follow beagle-rust:review-verification-protocol" but doesn't say where that protocol lives — verify what that protocol is and whether following it will require the agent to fetch anything from the network or to send your findings elsewhere. (2) Decide what code you allow t...详细分析 ▾
✓ 用途与能力
Name, description, and included reference files (routing, middleware, extractors) align with a Rust Axum code-review skill. The checklist and severity calibration match expected reviewer tasks. The skill does not declare unrelated binaries, env vars, or configs.
ℹ 指令范围
Runtime instructions are limited to reviewing Cargo.toml, routing, extractors, state, middleware, and error handling — all within the declared domain. One instruction says: "Load and follow beagle-rust:review-verification-protocol before reporting any issue." That is ambiguous (unspecified how/where to load it) and could imply fetching an external protocol or internal policy; the SKILL.md does not provide details. Otherwise there are no instructions to read unrelated system files, env vars, or to transmit data to external endpoints.
✓ 安装机制
No install spec and no code files that would be written to disk. This is instruction-only, which is the lowest install risk.
✓ 凭证需求
The skill declares no required environment variables, credentials, or config paths. The review guidance references common Rust/aXum crates but does not request secrets or unrelated credentials.
✓ 持久化与权限
always:false (not force-included) and no claims to modify other skills or system-wide configuration. The skill does not request persistent presence or elevated privileges.
安全有层次,运行前请审查代码。
运行时依赖
无特殊依赖
版本
latestv1.0.12026/3/27
- Added Rust 2024 edition-specific guidance for axum reviews, covering native async trait impls and lifetime capture. - Expanded checklist for extractors, state, error handling, and middleware to highlight Rust 2024 edition patterns (e.g., LazyLock, use of native async fn, lifetime capture changes). - Updated major and minor severity categories with new issues relevant to Rust 2024 migration (e.g., continued use of async-trait, legacy Lazy usage). - Refreshed Valid Patterns section to include new Rust 1.75+ and 1.80+ idioms. - Minor clarifications in workflow and output formatting.
● 无害
安装命令
点击复制官方npx clawhub@latest install axum-code-review
镜像加速npx clawhub@latest install axum-code-review --registry https://cn.longxiaskill.com
技能文档
审查流程
- 检查 Cargo.toml —— 注意 axum 版本(0.6 与 0.7+ 模式不同)、Rust edition(2021 与 2024)、tower、tower-http 特性。Edition 2024 改变了 handler 返回类型中 RPIT 的生命周期捕获规则,并移除了自定义 extractor 对
async-trait的需求。 - 检查路由 —— 路由组织、方法路由、嵌套路由器
- 检查 extractor —— 顺序很重要(body extractor 必须最后)、类型正确
- 检查 state —— 通过
State共享状态,而非全局可变状态 - 检查错误处理 ——
IntoResponse实现、错误类型
输出格式
以如下格式报告发现:
[FILE:LINE] ISSUE_TITLE
Severity: Critical | Major | Minor | Informational
Description of the issue and why it matters.
速查表
| Issue Type | Reference |
|---|---|
| 路由定义、嵌套、方法路由 | references/routing.md |
| State、Path、Query、Json、body extractor | references/extractors.md |
| Tower 中间件、层、错误处理 | references/middleware.md |
审查清单
路由
- [ ] 按领域组织路由(为
/api/users、/api/orders使用嵌套路由器) - [ ] 为 404 定义了回退 handler
- [ ] 方法路由显式(使用
.get()、.post(),而非.route()手动匹配方法) - [ ] 无路由冲突(路径重叠但 extractor 不同)
Extractor
- [ ] 消耗 body 的 extractor(
Json、Form、Bytes)是最后一个参数 - [ ]
State要求T: Clone—— 通常是Arc或直接Clone派生 - [ ]
Path参数类型与路由定义匹配 - [ ]
Query字段对可选查询参数使用Option并加#[serde(default)] - [ ] 自定义 extractor 实现
FromRequestParts(非 body)或FromRequest(body) - [ ] Edition 2024:自定义 extractor 在 trait 实现中使用原生
async fn(FromRequest/FromRequestParts不再需要#[async_trait])
状态管理
- [ ] 应用状态通过
State共享,而非全局可变静态变量 - [ ] 数据库连接池放在 state 中(而非每次请求新建)
- [ ] state 仅包含共享资源(连接池、配置、通道),不含请求特定数据
- [ ] state 类型已派生
Clone或手动实现 - [ ] Edition 2024:共享静态状态使用 std 的
LazyLock(而非once_cell::sync::Lazy或lazy_static!)
错误处理
- [ ] handler 错误实现
IntoResponse以返回正确 HTTP 错误码 - [ ] 内部错误不泄露给客户端(500 响应中不含原始错误信息)
- [ ] 错误响应使用统一格式(JSON 错误体含 code/message)
- [ ] handler 使用
Result模式 - [ ] Edition 2024:handler 返回类型
-> impl IntoResponse默认捕获所有作用域生命周期;返回 owned 数据时可用+ use<>选择不捕获请求生命周期
中间件
- [ ] Tower 层按正确顺序应用(外层在请求时先执行,响应时最后执行)
- [ ] 使用
tower-http处理常见需求(CORS、压缩、tracing、超时) - [ ] 请求作用域数据通过 extension 传递,而非全局状态
- [ ] 中间件错误不 panic —— 而是返回错误响应
- [ ] Edition 2024:使用
#[async_trait]的中间件可迁移到 trait 实现中的原生async fn
严重级别校准
Critical
- body extractor 不在 handler 参数最后(静默消耗 body,后续 extractor 失败)
- 通过路径/查询参数直接拼接导致 SQL 注入
- 内部错误细节泄露给客户端(堆栈、数据库错误)
- 受保护路由缺少认证中间件
Major
- 使用全局可变状态而非
State(竞态条件) - 缺少错误类型转换(直接向客户端返回原始
sqlx::Error) - 缺少请求超时(handler 可能无限挂起)
- 路由冲突导致意外 405
- Edition 2024:
FromRequest/FromRequestParts仍使用async-trait,而原生 async fn 已可用
Minor
- 手动路由方法匹配而非
.get()、.post() - 缺少回退 handler(默认 404 为纯文本而非 JSON)
- 中间件按路由单独应用,而本应全局(或反之)
- 缺少
tower-http::trace记录请求日志 - Edition 2024:在可用
std::sync::LazyLock的地方仍使用once_cell::sync::Lazy或lazy_static!
Informational
- 建议使用
tower-http层处理常见需求 - 路由器组织改进
- 建议通过
utoipa或aide添加 OpenAPI 文档
有效模式(勿标记)
#[axum::debug_handler]作用于 handler —— 调试辅助,改善编译错误信息Extension用于中间件注入数据 —— 请求作用域值的合法模式- 从 handler 返回
impl IntoResponse—— 比具体类型更灵活 - 每模块使用
Router::new(),在主函数合并 —— 标准组织模式 ServiceBuilder用于层组合 —— Tower 模式,非过度设计axum::serve搭配TcpListener—— axum 0.7+ 标准服务器启动方式- 在
FromRequest/FromRequestParts实现中使用原生async fn—— 不再需要async-traitcrate(Rust 1.75 起稳定) - handler 返回类型使用
+ use<'a>—— Edition 2024 对 RPIT 的精确捕获语法 - 使用
std::sync::LazyLock做共享静态状态 —— 替代once_cell/lazy_static(Rust 1.80 起稳定)
提交发现前
加载并遵循 beagle-rust:review-verification-protocol 后再报告任何问题。