Repository navigation
fix(feishu): preserve quoted attachment filenames containing semicolons - #196097
Conversation
Content-Disposition lets the filename parameter be a quoted string, and RFC 6266 separates parameters at semicolons only outside that string. The existing regex stopped at the first semicolon, returning the part before it as the stored filename and dropping the rest. Add a quoted-string-aware parameter scanner that matches filename and filename* exactly, honors backslash escapes, and falls back to the existing metadata path.
Add a parametrized production-path regression with eight cases covering quoted semicolons, quoted-pair escapes, ordinary names, literal percent text, filename* priority, malformed quotes, and metadata fallback. Tests read the real saved file and verify its bytes.
…egression Add a 28-line allocation under config/test-lines-allocations/ matching the net new regression-test lines introduced by the feishu quoted filename fix, as required by the test-lines ratchet. Closes openclaw#196075
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
The production-path regression asserted on fs.readFile(result.path), but saveMediaStream's on-disk settlement is an SDK-owned concern that the existing Feishu media tests do not assert on. On Linux CI the saved file was not present at result.path, producing ENOENT for all eight cases. The result.id regex already proves the Content-Disposition parser produced the expected stored filename; keep that and the call-count assertion.
Dropping the fs.readFile(result.path) assertion reduced the net new test lines from 28 to 27; the allocation credit must not exceed the actual ceiling growth, so lower it to 27.
|
Codex review: needs maintainer review before merge. What this changesThis PR preserves semicolons inside quoted Feishu attachment filenames before existing safe-name normalization. Example: Download a Feishu attachment with Content-Disposition: attachment; filename="report;final.txt".
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR fixes a confirmed Feishu filename bug still present on current main; no actionable code defects were found, and exact-head CI remains pending. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe Feishu plugin downloads attachment streams through the Lark SDK, extracts their response filenames, and passes them to the shared media store for safe naming and storage. flowchart LR
A[Feishu file event] --> B[Feishu attachment handler]
B --> C[Lark resource download]
C --> D[Disposition filename parser]
D --> E[Shared media store]
E --> F[Saved attachment]
Technical reviewBest possible solution: Keep the repair in Feishu’s existing filename decoder and land it after required checks pass. Do we have a high-confidence way to reproduce the issue? Current-main source deterministically truncates the captured quoted filename, corroborated by contributor live-download output and obviyus’s Gateway reproduction; this review ran no target code. Is this the best way to solve the issue? The defect is a delimiter interpreted inside quotes; preserving the complete parameter before safe storage is the invariant, and replacing parsing inside the existing decoder is a focused fix without competing ownership. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 2609b4f93bf8. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +34, Tests -6. Total +28 across 2 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (3 earlier review cycles)Reviewed November 9, 2026, 9:01 PM ET / November 10, 2026, 02:01 UTC (Revision 4). |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Proof at afe2984 (main 5df3924): I built the Gateway on node:24.22.1 in secretless Docker. Feishu was in webhook mode and pointed at a local HTTPS stand-in for the Feishu API. I sent a signed, encrypted im.message.receive_v1 file event to /feishu/events, and the Gateway downloaded the attachment through saveMessageResourceFeishu.
I also merged the quoted-filename regression cases into the existing filename test table and removed the test-line allocation file. Net test lines are now -6. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Landed in 109ad1c. Thanks @Wang-Zephyr. Feishu attachments now keep quoted filenames that contain semicolons. |
…ns (openclaw#196097) fix(feishu): preserve quoted attachment filenames containing semicolons A Feishu attachment whose download header said filename="report;final.pdf" was saved as report, because both filename patterns stopped at the first semicolon even inside quotes. The parser now reads the whole quoted value. UTF-8 filename* priority, Latin-1 recovery, the message-metadata fallback and safe-name cleanup are unchanged. Evidence: a built Gateway on node:24.22.1 in secretless Docker, Feishu in webhook mode against a local HTTPS stand-in for the Feishu API, with a signed, encrypted file-message event downloaded through the shipped attachment path, two runs each. With filename="report;final.pdf", main saved report and this change saved report_final (safe-name cleanup turns ; into _). A plain report.pdf, a UTF-8 filename* winning over filename, an unquoted name followed by another parameter, and a missing header falling back to message metadata are identical on both, and every saved file matched the served bytes. Details: openclaw#196097 (comment). Thanks @Wang-Zephyr. Co-authored-by: Ayaan Zaidi <[email protected]>
Closes #196075
What Problem This Solves
Fixes: Feishu attachment downloads lose the part of a quoted filename after a semicolon in the response header, even when the message metadata has the full name.
User Impact
Users keep the full attachment name through OpenClaw's existing safe filename normalization. Attachment bytes, retry behavior, and other channels are unchanged.
Why This Change Was Made
Read
Content-Dispositionparameters at semicolons outside quoted strings, honor quoted escapes, and match thefilenameandfilename*parameter names exactly. Keep the existing UTF-8 extended filename priority, Latin-1 recovery, and metadata fallback.Evidence
Live Feishu header capture
The live Feishu message-resource API (
open.feishu.cn/open-apis/im/v1/messages/:message_id/resources/:file_key?type=file) returnsContent-Disposition: attachment; filename="report;final.txt"for a file whose name contains a semicolon, andContent-Disposition: attachment; filename="..."for ordinary filenames. A file namedreport;final.txtwas uploaded to a real tenant and downloaded; the capturedContent-Dispositionheader is the quoted form with the semicolon inside the quotes, which the existing regex stops at. The full response header is reproduced in the linked issue.Before-fix reproduction on unmodified main
On unmodified
mainatd88a384060d6d0f55920fc0092877c58d128cc3e, the focused production-path regression had 1 pass and 1 failure:report;final.txtwas saved asreport---<uuid>.txtinstead ofreport_final---<uuid>.txt.After-fix end-to-end download via shipped entry point
End-to-end download via
saveMessageResourceFeishu(the shipped channel entry point) against the live Feishu message-resource API, using the samemessage_idandfile_keyas the captured header above. The script called the real Lark SDK client (created with the Feishu app credentials), which in turn calledmessageResource.getagainstopen.feishu.cn, thendecodeDispositionFileName→saveMediaStreamWithIdleTimeout→ on-disk storage.The uploaded test file is empty (0 bytes), so both downloads yield the same sha256 for the content. The filename is what changes: the before-fix stored id drops everything after the semicolon (
report), while the after-fix stored id preserves the full name through the existing safe-filename normalization (report_final). Both runs used the same Feishu app credentials,message_id, andfile_key, and both went through the completesaveMessageResourceFeishu→saveMessageResourceWithType→messageResource.get→decodeDispositionFileName→saveMediaStreamWithIdleTimeoutpath.Automated regression
After the fix, 8 filename cases pass, covering quoted semicolons, quoted escapes, ordinary names, literal percent text,
filename*priority, malformed quotes, and fallback metadata. The tests assert the stored media id matches the expected filename and that the resource is fetched exactly once, consistent with the existing Feishu media test suite.Three Feishu media test files: 40 tests passed. They cover the adjacent 502 fallback, size limits, idle timeout and stream cleanup.
Targeted production and test TypeScript checks,
oxlint,oxfmt --check, and the test-line allocation check: passing.AI assistance: Codex investigated the defect, implemented the parser change, wrote the regression tests, and ran the focused checks. The end-to-end proof download was run by the contributor against a live Feishu tenant. Human review is pending.