Repository navigation
feat(feishu): answer an unreadable attachment instead of dropping it silently - #16980
Conversation
|
Supersedes #8228 (fork PR by @JiaDe-Wu). Rebased onto current main and re-authored as an in-repo PR so the same-repo review lanes adjudicate the two security-class findings the fork pipeline fenced; both are fixed here (governance ceiling before the reply, and dropping the dedup id on a transient send failure). Original author @JiaDe-Wu keeps commit authorship (Co-authored-by trailer records the fixes). |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Still to check: send one real image from an allow-listed account and confirm the reply arrives as a threaded answer. The tests only exercise mocked lark frames. [DESIGN-REVIEWED] 778c506 Description read[DESCRIPTION-READ] 64fd973891e9d55fd22944ae8f81ce0b56c65ebb2e3f9ed4ee184407709eb43a That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Review detailsNo findings block this merge. FINDING — src/kiro_crew/messaging/transport.py:165 — the diff moves [OPUS-REVIEWED] 778c506 Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
First Principles Review (Opus 5.5) — 🟡 CONCERNSPremise-level review of First-Principles-Verdict: CONCERNS The Not justified as shipped
What this change shipsInventory (9 items) — 8 justifiedIntent: someone who sends a file to the Feishu bot gets a reply saying the channel reads text only, instead of silence. FIX (#7848).
[FIRST-PRINCIPLES-REVIEWED] 778c506 Description read[DESCRIPTION-READ] d46f31358d9725cb4900d55c1499cdf682caa41b32187cdaeeb68f43ad6bccf6 That sha256 names the PR description this verdict read. Recompute it with |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
|
Self-review (crew-pr-reviewer, read-only): CHANGES NEEDED Read-only review. The gate order is right: governance, the allow-list, the group gate and dedup all run before the reply. One defect. |
|
Moved to draft by crew-pr-reviewer (self-review gate). The self-review comment above lists changes this PR still needs. GitHub does not let an author request changes on their own PR, and PR Readiness does not read human review decisions, so a draft is the signal: it keeps readiness at To resume: address each point in the self-review comment, push, then run |
6d69474 to
83b92cb
Compare
|
Thanks — addressed in 1. Dead redelivery path ( 2. First Principles CONCERNS. This answers it. That concern was the same defect (Item 4, "inherited (unverified premise)"): the rollback assumed a redelivery that cannot occur. With the redelivery assumption dropped and the failure logged, the premise is gone, not papered over. 3. Removed the redelivery test and comment. 4. Nit — Design Review's note stands: the unit tests use a fake client, so a live-tenant send is still worth a manual check before merge. |
…silently Send a photo to the Feishu bot and nothing happened. Not an error, not a hint -- silence. The sender could not tell a refused attachment from a dead WebSocket, a wrong App ID, a missing scope, or an allow-list rejection. `messaging/attachments.py` exists to prevent exactly this: "Silently dropping an attachment is the original defect this module exists to fix ... Callers are expected to surface IngestResult.rejections to the user." But a transport declaring `files_inbound=False` never reaches `ingest`, so it has no result to carry a reason and the mechanism never runs for it. #7551 added the operator's log line for this drop; the sender's half was still missing. Feishu now replies with `attachments.channel_reads_no_attachments()`, in the same bracketed shape every `ingest` rejection already uses, so a channel that later gains real ingestion changes which function builds the string rather than how it reads. Three gates decide WHERE the reply happens, and each is a security property: - after `authorize`, so an unauthorised sender still learns nothing -- telling a stranger the bot is alive is a disclosure this channel deliberately avoids; - after the group gate, so a bot merely sitting in an unlisted group does not announce itself to the room; - after the redelivery-dedup window, so lark's WS replaying a frame cannot answer the same photo twice. The parse step had to change to make that possible. `_handle_receive_v1` dropped a non-text message before extracting the sender, and the transport is the only layer that knows whether that sender is authorised. The type is now decided after `open_id` and the message is carried on with an empty `text` and `unsupported_type` set, so it can never be mistaken for an instruction and never drives a turn. The existing log line is unchanged. `files_inbound` moves ASPIRATIONAL -> ENFORCED in the ledger with its read site cited, per the migration contract that module documents. Scope: Feishu only. iMessage also declares `files_inbound=False`, but its `receive` checks text ahead of `is_own_echo`, whose position its own comment calls load-bearing in both directions -- reordering it "would restore the loop while looking fixed". That belongs in its own change. The platform-supplied `message_type` is echoed back, so it is stripped to a word and length-capped first: brackets and dashes are what a rejection line is made of, and leaving them in would let a crafted type forge a second segment. Co-authored-by: iamwhatever <12429733+iamwhatever@users.noreply.github.com>
83b92cb to
778c506
Compare
|
Follow-up on
|
buluoray
left a comment
There was a problem hiding this comment.
Verdict: APPROVE
Reviewed at 778c506.
No blocking findings. I did not run the full suite. I ran only the four directly related test files (189 passed) plus the mutation runs described below. CI on this head: 86 pass, 12 skipping, 0 failing.
What I verified
The reply goes to the right conversation only.
src/kiro_crew/feishu/transport.py:393-396: the reply issend_message(inbound.message_id, …). That resolves toim.v1.message.replyanchored on the inbound message id (transport.py:205-222,client.pysend_reply), so it threads under the sender's own message in the chat it came from. This is the same anchor the text path uses. No chat_id or open_id is taken from anywhere else, and nothing is sent proactively. Ifmessage_idis empty the send raises (transport.py:219-220), theexceptcatches it, and the failure is only logged. In practiceclient.pydrops id-less frames before this point.- The reply sits after every existing gate, in order: the chat-type gate (
transport.py:319), the group allow-list conjunction (:331),authorize(:351) and dedup (:364-372). It then also passes the per-message governance ceilinginbound_permitted("feishu")(:391). The defaulttext=""keeps the cancel exemption off (messaging/dispatch.py:500-523), so a governed-off channel stays silent. - Fail-closed classification: every new guard is a
returnbefore any send. If a guard is wrong, the result is the old silent drop, not an extra or misdirected reply. The one fail-open direction, answering someone who is not authorised, is covered by the deny tests below.
No bytes, paths or credentials leak.
client.py:325-345never readsmessage.contentfor a non-text message, so no file key, image key or download happens. TheLarkInboundcarries onlyopen_id,message_id,chat_type,chat_idand the type string.messaging/attachments.py:140-166: the reply text is a fixed template plusmessage_type, stripped to[a-zA-Z0-9_]and capped at 32 characters. No path, id or exception text gets into the reply. Thelogger.exceptionline intransport.py:405-410goes to the operator log only.
No reply loop. The reply is always msg_type("text"). A redelivery or echo of it would therefore take the existing text path, never the unsupported_type branch. Dedup sits before the reply, so a redelivered image is answered once. Unknown senders, including other bots, fail authorize.
The readable path is unchanged. For message_type == "text" the only change is that the type decision now comes after the open_id extraction, and the extraction was already an early return. The run_coroutine_threadsafe hand-off moved into _deliver (client.py:398-409) byte for byte. In receive, if not inbound.text and not inbound.unsupported_type (transport.py:311) still stops empty text frames. A files_inbound=True transport falls through to return with no reply and no dispatch. That is the right result, because unsupported_type is only set for non-text frames.
Mutation results. I made six mutations in the worktree, restored each from a backup, and confirmed git status was clean afterwards.
| Guard neutered | Named test that reddened |
|---|---|
inbound_permitted check → if False |
test_feishu_transport.py::…::test_a_governance_disabled_channel_stays_silent |
files_inbound check → if True |
…::test_a_channel_that_reads_files_does_not_answer |
| sanitizer removed | test_messaging_attachments.py::…::test_a_platform_kind_cannot_forge_a_second_segment |
| dedup membership check removed | …TestUnreadableInboundIsAnswered::test_a_redelivered_frame_is_answered_once (+2) |
receive text gate reverted to if not inbound.text |
…::test_an_image_from_an_authorised_sender_is_answered (+5) |
except re-raises instead of logging |
…::test_a_failed_send_is_logged_and_leaves_a_trace |
Non-blocking follow-ups
- Stale docstring. The
ChannelCapabilitiesdocstring insrc/kiro_crew/messaging/transport.py(~line 165-170) still listsfiles_inboundunder ASPIRATIONAL ("nothing reads them yet"). The ledger test now classes it as ENFORCED. Move it to the enforced list and name the read site atfeishu/transport.py:384. - Spec drift. The Feishu section of
docs/system-specs/modules/messaging.mdwas not updated. It should say that an unreadable message is answered after the dedup gate (so it takes a dedup slot) and passes the governance ceiling. AGENTS.md asks for this in the same commit. - Group behaviour depends on scope. With the at-mention-only group scope, images never reach the bot in groups. With the receive-all-group-messages scope, every image an allow-listed user posts in an allow-listed group will get the reply. That matches how text already behaves under that scope, but the doc line "in a group only one that is allow-listed too" could mention it.
- No live check yet. As Design Review notes, nobody has sent a real image from an allow-listed account. Do one live check before relying on the threaded reply.
Bot concern dispositions
- Opus 5.5 (no blocking; FINDING on the docstring and spec): checked, still true at head. It covers documentation only, not behaviour, so it does not gate. Recorded as follow-ups 1-2.
- First Principles (CONCERNS: the
files_inboundbranch is unreachable for Feishu): checked.FEISHU_CAPABILITIESsets itFalseand nothing insrc/changes it, so theTruearm is reachable only in tests. It does not gate. The check is one line, it fails closed, and it ties the reply to the capability that a later ingestion change will flip. Without it, that change would leave the "not opened" reply firing next to real ingestion. Keeping it is a defensible design choice, not a defect. - Design Review (PASS, asks for a live send): this is a manual check. It does not gate. Recorded as follow-up 4.
- GPT 6.1 (no findings): nothing to dispose of.
- Earlier First Principles BLOCK (the description said re-raise, the code logs): the author fixed the description, and the code's log-only choice is correct.
_delivernever awaits the future, so a re-raise would be invisible. Confirmed atclient.py:408-409.
Problem / Motivation
Goal: Someone who sends a file to the Feishu bot gets a one-line answer saying the channel reads text only, instead of silence.
Send a photo to the Feishu bot and nothing happens. Not an error, not a hint, not a reaction — silence.
feishu/client.pydrops any non-text message at the parse step, so the sender cannot tell a refused attachment from a dead WebSocket, a wrong App ID, a missing scope, or an allow-list rejection. The rational next move is to send it again — or to ask "did you get that?", which does get answered, making the first look like a bug.Why it matters
messaging/attachments.pyalready exists to prevent precisely this, and says so: silently dropping an attachment is the original defect that module exists to fix, and callers are expected to surfaceIngestResult.rejectionsto the user. But a transport declaringfiles_inbound=Falsenever reachesingest, so it has noIngestResultto carry a reason and that mechanism never runs for it. The guarantee exists; two channels sit outside it, and Feishu is one.Not a goal
files_inbound=Falseand still drops silently. Itsreceivecheckstextahead ofis_own_echo, whose own comment calls its position load-bearing in both directions ("consuming it there would restore the loop while looking fixed"). Reordering a gate whose comment warns it can silently restore a message loop belongs in its own change.What changed (motivation → approach → change)
The reply reuses the existing mechanism's shape.
attachments.channel_reads_no_attachments()builds the same single bracketed, em-dash-separated segment everyingestrejection already produces. It lives in that module because that module owns rejection wording, so a channel that later gains real ingestion changes which function builds the string, not how it reads.Three gates decide where the reply happens, and each is a security property: after
authorize(an unauthorised sender still learns nothing), after the group gate (a bot merely sitting in an unlisted group does not announce itself to the room), and after the dedup window (lark's WS redelivery cannot answer one photo twice).The parse step changed to make that possible.
_handle_receive_v1dropped the message before extractingopen_id, and the transport is the only layer that knows whether a sender is authorised. The type is now decided after the sender, and an unreadable message is carried on withtext=""andunsupported_typeset. Empty text plus nounsupported_typestill stops inreceiveexactly as before. The existing log line is untouched.files_inboundmoves ASPIRATIONAL → ENFORCED intest_capability_ledger.py, with its read site cited inline, per the migration contract that module documents. A channel declaringTrueis untouched: its attachments go throughingestas before.The echoed
message_typeis treated as untrusted. It is platform-supplied and goes back to the sender, so it is stripped to[a-zA-Z0-9_]and length-capped: brackets and dashes are what a rejection line is made of, and leaving them in would let a crafted type forge a second bracketed segment.Two review findings from the original fork PR (#8228) are fixed here:
inbound_permitted("feishu")before sending. The replyreturns before the dispatcher, so it never reaches the dispatcher's owninbound_permittedgate — without this, an administratively-disabled channel would still respond to an authorised owner's attachment.client._deliverdispatchesreceivethroughasyncio.run_coroutine_threadsafeand never awaits it, so the WS frame is acked the moment the handler returns and no redelivery is ever held back; the re-raise only surfaced in a future nothing reads. So the failure is logged instead (logger.exception), the id stays recorded, and no redelivery is courted. A failed reply now leaves the one trace it actually can — a log line.Backwards compatibility
Compatible: no field is rejected, renamed, or removed. A frame that resolves to empty text with no
unsupported_typestill stops inreceiveexactly as before, and a transport declaringfiles_inbound=Trueis unaffected. The dataclass gains one optional field (unsupported_type: str = "") with a default, so every existingLarkInboundconstruction keeps working.Removes nothing: the change only adds a reply path for a message that was previously dropped; no reader of any existing capability is affected.
Tests
New tests.
TestUnreadableInboundIsAnsweredpins the reply and, one test per gate, the deny paths that must stay silent — unauthorised sender, empty allow-list, unlisted group, unknown chat type — plus answered-once on redelivery, never-drives-a-turn, an allow-listed group is answered, afiles_inbound=Truetransport answering nothing, a governance-disabled channel staying silent, and a failed send being logged (the id stays recorded; no redelivery is courted).TestChannelReadsNoAttachmentspins the string's shape rather than its prose, including thatpost(rich text, not a file) gets its own wording. Client tests replace the old "ignored" assertion with the carry-through contract, including that a message with no sender is still dropped.Manual verification
N/A — unit coverage is sufficient: every gate (authorize, group, dedup, governance, capability, send-failure) is exercised by a dedicated test, and the reply shape is pinned structurally.
Related Issues
Fixes #7848
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)