Skip to content

fix: escape Satori file attributes - #11397

Merged
RC-CHN merged 1 commit into
AstrBotDevs:masterfrom
RC-CHN:fix/escape-satori-file-and-weixin-caption
Nov 27, 2026
Merged

RC-CHN merged 1 commit into
AstrBotDevs:masterfrom
RC-CHN:fix/escape-satori-file-and-weixin-caption

Conversation

@RC-CHN

@RC-CHN RC-CHN commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

#11379 的后续,修复审查中发现的一个已有问题。

  • Satori:<file> 的 src/name 没转义,文件名带 " < & 会生成坏标签,甚至注入 <at id="all"/>。

(审查中提到的 Weixin OC 说明发送失败被忽略,已由 #11354 修复,本 PR 不再包含。)

Modifications / 改动点

  • satori_event.py:两处 <file> 改用 html.escape(..., quote=True)。

  • 加一个回归测试。

  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果

pytest -q tests/test_satori_buttons.py tests/test_weixin_buttons.py tests/test_satori_group_info.py
14 passed, 1 warning

ruff format . && ruff check .
All checks passed!

Checklist / 检查清单

  • 新功能已提前讨论(不适用,纯修复)
  • 已提供验证步骤和测试结果
  • 只改平台适配器,无需更新 WebUI 文档
  • 无新增依赖
  • 无恶意代码

Summary by Sourcery

Prevent malformed or injectable Satori file markup by safely escaping file attributes.

Bug Fixes:

  • Escape Satori file source and name attributes to prevent malformed markup and attribute-based injection.

Tests:

  • Add a regression test covering escaping of special characters and injection-like content in Satori file attributes.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="astrbot/core/platform/sources/weixin_oc/weixin_oc_adapter.py" line_range="1077" />
<code_context>
                     logger.error(f"图片转换为base64失败: {e}")

             elif isinstance(component, File):
-                return (
</code_context>
<issue_to_address>
**Retry duplicates delivered attachment**

When the caption API reports failure, the media API succeeds, and the caller retries the raised send, `send_by_session` raises for the failed caption even though the media request succeeded; a caller retry then resends the already-delivered attachment because `_send_items_to_session` assigns a fresh `client_id` to each request, so the recipient sees a duplicate attachment.

Track successful subparts so retries resend only the failed caption, or use stable idempotency keys for the media request.
</issue_to_address>

### Comment 2
<location path="tests/test_satori_buttons.py" line_range="133" />
<code_context>
+
+@pytest.mark.asyncio
+async def test_satori_escapes_file_attributes(tmp_path):
+    file_path = tmp_path / "x&y.html"
+    file_path.write_text("report")
+    rendered = await SatoriPlatformEvent._convert_component_to_satori_static(
</code_context>
<issue_to_address>
**Source paths can inject markup**

When the converter escapes ampersands in `src` but leaves quotes unescaped, `test_satori_escapes_file_attributes` computes `escaped_src` at line 139 by replacing only `&`, and its source path from line 133 contains no quotes. A converter that leaves `"` unescaped in `src` therefore still passes the equality assertion at line 140, despite allowing attribute injection.

Use a source path containing a quote or markup characters and assert that the complete attribute is escaped.
</issue_to_address>

Sourcery assessment

Approval pending. 2 findings to address first.

Blocking findings: astrbot/core/platform/sources/weixin_oc/weixin_oc_adapter.py:1077, tests/test_satori_buttons.py:133


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

)
# Report failure if either the caption or the media item was not delivered.
return text_sent and media_sent

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Retry duplicates delivered attachment

When the caption API reports failure, the media API succeeds, and the caller retries the raised send, send_by_session raises for the failed caption even though the media request succeeded; a caller retry then resends the already-delivered attachment because _send_items_to_session assigns a fresh client_id to each request, so the recipient sees a duplicate attachment.

Track successful subparts so retries resend only the failed caption, or use stable idempotency keys for the media request.

Prompt for AI agents
In `astrbot/core/platform/sources/weixin_oc/weixin_oc_adapter.py` at line 1077:

**Retry duplicates delivered attachment**

When the caption API reports failure, the media API succeeds, and the caller retries the raised send, `send_by_session` raises for the failed caption even though the media request succeeded; a caller retry then resends the already-delivered attachment because `_send_items_to_session` assigns a fresh `client_id` to each request, so the recipient sees a duplicate attachment.

Track successful subparts so retries resend only the failed caption, or use stable idempotency keys for the media request.

Comment thread tests/test_satori_buttons.py Resolved
@RC-CHN
RC-CHN force-pushed the fix/escape-satori-file-and-weixin-caption branch from f2bea1b to bbdef2d Compare November 27, 2026 00:52
@RC-CHN RC-CHN changed the title fix: escape Satori file markup and report Weixin OC caption failures fix: escape Satori file attributes Nov 27, 2026
@RC-CHN
RC-CHN merged commit f37e158 into AstrBotDevs:master Nov 27, 2026
8 checks passed
@RC-CHN
RC-CHN deleted the fix/escape-satori-file-and-weixin-caption branch November 27, 2026 01:07
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.

1 participant