Repository navigation
fix: escape Satori file attributes - #11397
Conversation
There was a problem hiding this comment.
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
| ) | ||
| # Report failure if either the caption or the media item was not delivered. | ||
| return text_sent and media_sent | ||
|
|
There was a problem hiding this comment.
🟡 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.f2bea1b to
bbdef2d
Compare
#11379 的后续,修复审查中发现的一个已有问题。
<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 / 运行截图或测试结果
Checklist / 检查清单
Summary by Sourcery
Prevent malformed or injectable Satori file markup by safely escaping file attributes.
Bug Fixes:
Tests: