feat: 增强 Webhook POST 请求配置 - #305
Open
DoSerZBlock wants to merge 5 commits into
Open
Conversation
- Parse body templates as JSON before placeholder substitution to preserve escaping - Restore the WinSafe API supported by the locked dependency - Move webhook task definitions and translations into existing project registries - Add a regression test for quoted and escaped webhook content Affects: src-tauri/src/mxu_actions.rs, src/types/specialTasks.ts, src/i18n/locales/* Risk: 中,調整 Webhook 請求序列化與特殊任務設定結構 Refs: PR #4 Breaking-Change: None
- Skip custom header slots whose name or value is blank - Preserve valid header values without normalization - Add regression coverage for one-header configuration Affects: src-tauri/src/mxu_actions.rs Risk: 低,仅过滤无法使用的空白请求头配置 Refs: None Breaking-Change: None
DoSerZBlock
marked this pull request as ready for review
July 31, 2026 07:19
Contributor
There was a problem hiding this comment.
Hey - 我发现了 1 个问题。
供 AI 代理使用的提示
请解决本次代码审查中的以下评论:
## 逐条评论
### 评论 1
<location path="src/types/specialTasks.ts" line_range="386-387" />
<code_context>
+ label: 'specialTask.webhook.headerNameLabel',
+ default: 'Authorization',
+ pipeline_type: 'string',
+ verify: '^[A-Za-z0-9-]+$',
+ pattern_msg: 'specialTask.webhook.headerNameError',
+ placeholder: 'specialTask.webhook.headerNamePlaceholder',
+ },
</code_context>
<issue_to_address>
**suggestion (bug_risk):** 头名称的校验正则比 HTTP 规范更严格,可能会拒绝一些合法的头名称。
当前 `header_1_name` / `header_2_name` 使用的模式 `^[A-Za-z0-9-]+$` 会排除掉符合 RFC 7230 的部分 `tchar`(例如下划线),因此某些合法的头名称会被前端界面拦截,而后端仍然可以接受它们。建议将正则与 RFC 允许的字符集对齐,或者将验证逻辑下放到 `build_webhook_headers`,以避免拒绝合法的头名称。
建议实现:
```typescript
// RFC 7230 header field-name: 1*("!" / "#" / "$" / "%" / "&" / "'" / "*" / "+" / "-" / "." /
// "^" / "_" / "`" / "|" / "~" / DIGIT / ALPHA)
// This regex allows the full tchar set while still preventing whitespace and control chars.
verify: "^[!#$%&'*+\\-.^_`|~0-9A-Za-z]+$",
```
1. 请在其他头名称输入(例如 `header_2_name`)上也应用相同的正则更新,只要它们目前使用的是 `^[A-Za-z0-9-]+$`,以确保所有头名称字段的行为一致。
2. 如果后端在 `build_webhook_headers` 中已经执行了更严格或不同的验证,请仔细检查此客户端正则模式不会与后端规则冲突;如果你决定完全依赖后端验证,则可以从这些头名称输入中移除 `verify`/`pattern_msg` 属性。
</issue_to_address>帮我变得更有用!请在每条评论上点击 👍 或 👎,我会根据这些反馈改进后续的审查。
Original comment in English
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/types/specialTasks.ts" line_range="386-387" />
<code_context>
+ label: 'specialTask.webhook.headerNameLabel',
+ default: 'Authorization',
+ pipeline_type: 'string',
+ verify: '^[A-Za-z0-9-]+$',
+ pattern_msg: 'specialTask.webhook.headerNameError',
+ placeholder: 'specialTask.webhook.headerNamePlaceholder',
+ },
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Header name validation regex is stricter than HTTP allows and may reject some legitimate header names.
The current `^[A-Za-z0-9-]+$` pattern for `header_1_name` / `header_2_name` excludes valid RFC 7230 `tchar`s (e.g., underscores), so some legitimate header names will be blocked by the UI while the backend can still accept them. Consider aligning the regex with the RFC’s allowed characters or deferring validation to `build_webhook_headers` to avoid rejecting valid headers.
Suggested implementation:
```typescript
// RFC 7230 header field-name: 1*("!" / "#" / "$" / "%" / "&" / "'" / "*" / "+" / "-" / "." /
// "^" / "_" / "`" / "|" / "~" / DIGIT / ALPHA)
// This regex allows the full tchar set while still preventing whitespace and control chars.
verify: "^[!#$%&'*+\\-.^_`|~0-9A-Za-z]+$",
```
1. Apply the same regex update to any other header name inputs (e.g., `header_2_name`) that currently use `^[A-Za-z0-9-]+$`, so the behavior is consistent across all header name fields.
2. If the backend already performs stricter or different validation in `build_webhook_headers`, double-check that this client-side pattern does not conflict with backend rules; if you decide to fully defer to backend validation instead, you can remove the `verify`/`pattern_msg` properties from these header name inputs.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
- Align frontend validation with HTTP tchar rules to accept valid custom header names - Apply the same validation to both header name inputs for consistent behavior Affects: src/types/specialTasks.ts Risk: 低,僅放寬前端格式驗證且後端仍執行 HeaderName 驗證 Refs: MistEO#305 Breaking-Change: None
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概述
{title}、{content}、{time}消息模板变量问题与原因
原有
MXU_WEBHOOK_ACTION只能发送 GET 请求,无法直接适配 Discord、企业通知服务等要求 POST JSON 的 Webhook。初版实现还将 JSON 模板作为普通字符串替换,通知内容包含引号或反斜杠时可能生成无效 JSON;自定义请求头只填写一组时,也会发送另一组空凭据。本 PR 先将模板解析为 JSON 结构,再替换变量并交由
serde_json序列化,同时过滤名称或值为空白的请求头配置。主要变更
src-tauri/src/mxu_actions.rssrc/types/specialTasks.tssrc/i18n/locales/*验证
pnpm buildcargo test --manifest-path src-tauri/Cargo.toml --all-targets(8 个测试全部通过)git diff --check风险与回滚
QA 说明
建议合并前使用至少一个真实 Webhook 服务验证默认模板、包含引号或反斜杠的通知内容,以及仅配置一组自定义请求头的场景。
Summary by Sourcery
扩展 MXU Webhook 特殊任务,使其支持可配置的 POST JSON 请求,包括可模板化的请求负载、请求头、超时时间以及更严格的错误处理,同时保持与现有行为的兼容性。
新特性:
{title}、{content}和{time}占位符的 JSON 请求体模板、可选的自定义请求头、请求超时时间,以及对非成功状态码的处理。改进:
测试:
Original summary in English
Summary by Sourcery
Extend the MXU webhook special task to support configurable POST JSON requests with templated payloads, headers, timeouts, and stricter error handling while keeping compatibility with existing behavior.
New Features:
Enhancements:
Tests: