Repository navigation
feat: 支持 RSA2048 套件与 x-wop-request-id 透传头 - #39
Conversation
Co-authored-by: Cursor <[email protected]>
Co-authored-by: Cursor <[email protected]>
Co-authored-by: Cursor <[email protected]>
协议核心(wop-specs crypto-spec E1 扩展位 + sdk-spec 附录 I,对齐 wop-java-sdk feature_20260922_fix 基准): - suites.py:新增 WOP-RSA2048-SHA256 套件(RSA 2048 位、 RSA-2048-OAEP 包装),密钥算法表与包装算法表同步扩容 - client.py:build_request/execute 新增 request_id 请求级参数 (附录 I)——恒不入签(签名落盘后写入头)、构造即校验(trim 前 原值控制字符扫描防头注入、trim 后 UTF-8 字节 ≤128,trim 集 = G2 TrimAll 同集,不用 str.strip 的 Unicode 超集)、未传/空白 缺省生成 uuid4().hex(request_id_generator 模块级可替换)、 wop_sdk.outbound INFO 日志打印最终头值(日志义务) - interop 头集合哨兵剥离透传头(fixture sha256 钉死不变) - 确定性重放/BDD 两次构建场景注入固定生成器(附录 I3 CSPRNG 豁免) - API 快照随公共签名/docstring 变化刷新 测试:346 全绿(新增 requestId 8 项 + RSA2048 套件 2 项); equivalent-anchors 与 api-snapshot 门禁通过。 说明:覆盖率门禁(98%)在本仓分支为既有缺口(基线 89.37%, 本次改动后 89.59%,集中在 P0 config loader 发现序列用例, 与本次改动无关)
|
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
审查者指南本 PR 对齐最新 wop-specs:增加 RSA2048 套件支持,并在签名完成后实现经过严格构造期校验、缺省 UUID 生成和 INFO 日志记录的 x-wop-request-id 透传;同时引入配置加载/校验、默认客户端、传输发现及 execute 一站式调用,并相应调整互操作基线和测试。 使用 x-wop-request-id 进行请求签名的时序图sequenceDiagram
participant Caller
participant WopClient
participant Signer
participant OutboundLog
Caller->>WopClient: build_request(method, path, body, request_id)
WopClient->>WopClient: resolve_request_id(request_id)
WopClient->>Signer: build_canonical(headers, body)
Signer-->>WopClient: signature
WopClient->>WopClient: write x-wop-request-id after x-wop-sign
WopClient->>OutboundLog: info(x-wop-request-id, method, path)
WopClient-->>Caller: RequestDraft
已配置客户端执行流程的时序图sequenceDiagram
participant Caller
participant WopClient
participant Transport
participant Gateway
Caller->>WopClient: execute(method, path, body, request_id)
WopClient->>WopClient: validate_api_path(path)
WopClient->>WopClient: build_request(..., request_id)
WopClient->>Transport: send_draft(transport, server_root, draft)
Transport->>Gateway: HTTP request with x-wop-request-id
Gateway-->>Transport: HTTP response
alt response status is 2xx
Transport-->>WopClient: response
WopClient-->>Caller: verify_response(...)
else response status is non-2xx
Transport-->>WopClient: response
WopClient-->>Caller: WopGatewayResponseError
end
文件级变更
提示和命令与 Sourcery 交互
自定义使用体验访问你的控制面板以:
获取帮助Original review guide in EnglishReviewer's Guide本 PR 对齐最新 wop-specs:增加 RSA2048 套件支持,并在签名完成后实现经过严格构造期校验、缺省 UUID 生成和 INFO 日志记录的 x-wop-request-id 透传;同时引入配置加载/校验、默认客户端、传输发现及 execute 一站式调用,并相应调整互操作基线和测试。 Sequence diagram for request signing with x-wop-request-idsequenceDiagram
participant Caller
participant WopClient
participant Signer
participant OutboundLog
Caller->>WopClient: build_request(method, path, body, request_id)
WopClient->>WopClient: resolve_request_id(request_id)
WopClient->>Signer: build_canonical(headers, body)
Signer-->>WopClient: signature
WopClient->>WopClient: write x-wop-request-id after x-wop-sign
WopClient->>OutboundLog: info(x-wop-request-id, method, path)
WopClient-->>Caller: RequestDraft
Sequence diagram for configured client execute flowsequenceDiagram
participant Caller
participant WopClient
participant Transport
participant Gateway
Caller->>WopClient: execute(method, path, body, request_id)
WopClient->>WopClient: validate_api_path(path)
WopClient->>WopClient: build_request(..., request_id)
WopClient->>Transport: send_draft(transport, server_root, draft)
Transport->>Gateway: HTTP request with x-wop-request-id
Gateway-->>Transport: HTTP response
alt response status is 2xx
Transport-->>WopClient: response
WopClient-->>Caller: verify_response(...)
else response status is non-2xx
Transport-->>WopClient: response
WopClient-->>Caller: WopGatewayResponseError
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
你好——我发现了 2 个问题
面向 AI Agent 的提示
请处理此次代码审查中的评论:
## 单条评论
### 评论 1
<location path="src/wop_sdk/config/_loader.py" line_range="18-116" />
<code_context>
+PACKAGED_CONFIG = "config/wopSdkConfig.json"
</code_context>
<issue_to_address>
**issue (bug_risk):** 默认配置发现使用 `resources.files("wop_sdk.config").joinpath("wopSdkConfig.json")` 查找打包资源,但本次新增文件位于仓库根目录 `config/wopSdkConfigDefault.json`,名称和包内路径均不匹配;没有用户配置文件时 `load_default()` 必然抛出“未找到可读配置文件”。
**触发条件:** 当调用 `WopClient.default_client()` 且环境变量、当前目录和用户目录均没有配置文件。
**建议修复:** 将默认配置以 `wop_sdk/config/wopSdkConfig.json` 打包,或让 `PACKAGED_CONFIG` 与新增文件的实际资源路径和文件名一致。
</issue_to_address>
### 评论 2
<location path="src/wop_sdk/config/_validator.py" line_range="79" />
<code_context>
+ if not parsed.netloc:
+ raise ConfigurationError(f"{field_name} 不是合法 URL: {trimmed}")
+ host = parsed.hostname or ""
+ port = parsed.port
+ path = parsed.path or ""
+ normalized = "https://" + host.lower()
</code_context>
<issue_to_address>
**issue (bug_risk):** `parsed.port` 在 URL 端口不是合法整数或超出范围时直接抛出 `ValueError`,该异常未被转换为 `ConfigurationError`;配置加载因此泄漏底层异常,违反配置校验接口的统一错误契约。
**触发条件:** 当 `serverRoot` 或 `backupServerRoots` 包含非法端口,例如 `https://gw.example.com:abc`。
**建议修复:** 在读取 `parsed.port` 时捕获 `ValueError`,并重新抛出带字段名的 `ConfigurationError`。
```suggestion
try:
port = parsed.port
except ValueError as exc:
raise ConfigurationError(f"{field_name} 不是合法 URL: {trimmed}") from exc
```
</issue_to_address>Sourcery 评估
需要人工审查。 请先处理 2 个待解决的问题。此外,本次变更新增了 RSA-2048 签名/加密路径,以及由配置驱动的执行流程,该流程可以向配置的网关主机发送已签名或已加密的请求;加密实现或主机验证中的错误可能导致凭据或请求数据泄露,而回滚并不能撤回已经发送的流量或已经暴露的数据。
阻塞性问题:src/wop_sdk/config/_loader.py:116、src/wop_sdk/config/_validator.py:79
Original comment in English
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/wop_sdk/config/_loader.py" line_range="18-116" />
<code_context>
+PACKAGED_CONFIG = "config/wopSdkConfig.json"
</code_context>
<issue_to_address>
**issue (bug_risk):** 默认配置发现使用 `resources.files("wop_sdk.config").joinpath("wopSdkConfig.json")` 查找打包资源,但本次新增文件位于仓库根目录 `config/wopSdkConfigDefault.json`,名称和包内路径均不匹配;没有用户配置文件时 `load_default()` 必然抛出“未找到可读配置文件”。
**Triggers:** 当调用 `WopClient.default_client()` 且环境变量、当前目录和用户目录均没有配置文件。
**Suggested fix:** 将默认配置以 `wop_sdk/config/wopSdkConfig.json` 打包,或让 `PACKAGED_CONFIG` 与新增文件的实际资源路径和文件名一致。
</issue_to_address>
### Comment 2
<location path="src/wop_sdk/config/_validator.py" line_range="79" />
<code_context>
+ if not parsed.netloc:
+ raise ConfigurationError(f"{field_name} 不是合法 URL: {trimmed}")
+ host = parsed.hostname or ""
+ port = parsed.port
+ path = parsed.path or ""
+ normalized = "https://" + host.lower()
</code_context>
<issue_to_address>
**issue (bug_risk):** `parsed.port` 在 URL 端口不是合法整数或超出范围时直接抛出 `ValueError`,该异常未被转换为 `ConfigurationError`;配置加载因此泄漏底层异常,违反配置校验接口的统一错误契约。
**Triggers:** 当 `serverRoot` 或 `backupServerRoots` 包含非法端口,例如 `https://gw.example.com:abc`。
**Suggested fix:** 在读取 `parsed.port` 时捕获 `ValueError`,并重新抛出带字段名的 `ConfigurationError`。
```suggestion
try:
port = parsed.port
except ValueError as exc:
raise ConfigurationError(f"{field_name} 不是合法 URL: {trimmed}") from exc
```
</issue_to_address>Sourcery assessment
Needs a human reviewer. 2 findings to address first, and this adds a new RSA-2048 signing/encryption path and a configuration-driven execute flow that can send signed or encrypted requests to configured gateway hosts; a cryptographic or host-validation mistake could expose credentials or request data, and reverting would not undo traffic already sent or data already exposed.
Blocking findings: src/wop_sdk/config/_loader.py:116, src/wop_sdk/config/_validator.py:79
Sourcery 评审两条(PR #39): - 配置发现兜底(K6 优先级 6):默认模板此前仅在仓根 config/ wopSdkConfigDefault.json,包内无 wopSdkConfig.json,无用户配置时 load_default() 必然「未找到可读配置文件」。现将模板打入 wop_sdk/config/wopSdkConfig.json(pyproject 增加 package-data), 兜底可被发现并读取(占位符密钥在密钥校验阶段给出明确文案) - validate_gateway_url:parsed.port 对非法端口(:abc/越界)抛原生 ValueError,归一为带字段名的 ConfigurationError,符合配置校验 统一错误契约 测试:新增打包兜底与非法端口 2 项回归,348 全绿;anchors 与 api-snapshot 门禁通过
- extra_headers 携带 x-wop-request-id 不再入签名集合,并入 request_id 解析链同口径校验;双来源同传构造期拒 - EXPECTED_SHA256 回滚为真源实测值 c920ca1a(9a51486d 无来源,合入即红) - urllib 传输接线 readTimeout 超时,消除无限挂起面 - 冻结向量接入:rsa2048 签名字节级/OAEP 解包/位宽校验/L2 往返 + extra_headers 组合的恒不入签金丝雀(先红后绿 7 例)
重审(2026-10-18)发现:双变体同传时按插入序取首值、其余静默丢弃, 与双来源构造即拒同属消歧语义,补测试显式钉定防漂移。
字节级同步合并后 crypto-vectors.json:_meta v0.4-draft、rsa2048 节内联就位
|
Add Carrot credits or activate Agent usage billing to use Autofix |
- parser/loader/validator/builder/transport 发现负例与边界闭合(91→99%) - 修 expiredSeconds 整 float 被拒:与 _parse_int_field 同语义
|
本仓未启用 changesets 体系(无 |
_read_positive_int 语义(须为正,与 dotnet 口径一致)下 readTimeout=0 应拒绝;ok 判定同时修掉 bool 陷阱 (False == 0 误判为 maxRetryCount=0 合法组)。
对齐 wop-specs(crypto-spec E1 扩展位 + sdk-spec 附录 I,wop-java-sdk feature_20260922_fix 基准):
RSA2048 套件(默认支持)
x-wop-request-id 透传头(附录 I)
配套
验证
Sourcery 摘要
支持 RSA2048 套件和请求 ID 传播,同时提供经过验证的配置驱动客户端执行功能。
新功能:
x-wop-request-id传播功能,包括验证、默认生成、出站日志记录和执行路径转发。错误修复:
增强功能:
测试:
Original summary in English
Sourcery 摘要
新增 RSA2048 支持、请求 ID 传播以及配置驱动的客户端执行,同时保持协议签名和互操作性行为不变。
新功能:
x-wop-request-id值,同时不影响已签名的请求字节。错误修复:
增强功能:
构建:
测试:
Original summary in English
Sourcery 摘要
在保持签名行为和互操作性行为不变的前提下,添加对 RSA2048 的支持、请求 ID 传递,以及由配置驱动的请求执行。
新功能:
x-wop-request-id请求头,但不将其纳入签名请求头。错误修复:
增强功能:
构建:
测试:
Original summary in English
Sourcery 摘要
新增对 RSA2048 的支持、请求 ID 传递和由配置驱动的请求执行,同时保持签名行为和互操作性。
新功能:
x-wop-request-id,并在未提供时默认生成。错误修复:
增强:
构建:
测试:
Original summary in English
Sourcery 总结
在保留签名和互操作行为的同时,添加对 RSA2048 的支持、请求 ID 传递,以及由配置驱动的请求执行。
新功能:
错误修复:
增强功能:
构建:
测试:
Original summary in English
Sourcery 摘要
新增 RSA2048 支持、请求 ID 传递和由配置驱动的请求执行,同时保持签名与互操作行为不变。
新功能:
错误修复:
改进:
构建:
测试:
Original summary in English
Sourcery 摘要
在保留签名和互操作行为的同时,新增对 RSA2048 的支持、请求 ID 传递,以及由配置驱动的请求执行。
新功能:
错误修复:
增强功能:
构建:
测试:
Original summary in English
Summary by Sourcery
Add RSA2048 support, request ID propagation, and configuration-driven request execution while preserving signing and interoperability behavior.
New Features:
Bug Fixes:
Enhancements:
Build:
Tests: