Skip to content

fix(feishu): preserve quoted attachment filenames containing semicolons - #196097

Merged
obviyus merged 8 commits into
openclaw:mainfrom
Wang-Zephyr:fix/feishu-quoted-filename
Nov 10, 2026
Merged

obviyus merged 8 commits into
openclaw:mainfrom
Wang-Zephyr:fix/feishu-quoted-filename

Conversation

@Wang-Zephyr

@Wang-Zephyr Wang-Zephyr commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

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-Disposition parameters at semicolons outside quoted strings, honor quoted escapes, and match the filename and filename* 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) returns Content-Disposition: attachment; filename="report;final.txt" for a file whose name contains a semicolon, and Content-Disposition: attachment; filename="..." for ordinary filenames. A file named report;final.txt was uploaded to a real tenant and downloaded; the captured Content-Disposition header 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 main at d88a384060d6d0f55920fc0092877c58d128cc3e, the focused production-path regression had 1 pass and 1 failure: report;final.txt was saved as report---<uuid>.txt instead of report_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 same message_id and file_key as the captured header above. The script called the real Lark SDK client (created with the Feishu app credentials), which in turn called messageResource.get against open.feishu.cn, then decodeDispositionFileName → saveMediaStreamWithIdleTimeout → on-disk storage.

=== Before fix (unmodified main at d88a38406) ===
stored id:    report---0385cc99-d8dd-459a-8eae-edb1c5707181.txt
stored path:  <temp>/.openclaw/media/inbound/report---0385cc99-d8dd-459a-8eae-edb1c5707181.txt
size:         0 bytes
sha256:       e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
contentType:  text/plain

=== After fix (8eabc517f6) ===
stored id:    report_final---954f27c2-6318-4e46-b5aa-cf5abed1fa1b.txt
stored path:  <temp>/.openclaw/media/inbound/report_final---954f27c2-6318-4e46-b5aa-cf5abed1fa1b.txt
size:         0 bytes
sha256:       e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
contentType:  text/plain

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, and file_key, and both went through the complete saveMessageResourceFeishu → saveMessageResourceWithType → messageResource.get → decodeDispositionFileName → saveMediaStreamWithIdleTimeout path.

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.

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
@clawsweeper

clawsweeper Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@Wang-Zephyr
Wang-Zephyr marked this pull request as ready for review November 9, 2026 16:13
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 9, 2026
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.
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 9, 2026
@clawsweeper

clawsweeper Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This 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".

  • Before: The stored filename is report---<uuid>.txt.
  • After: The stored filename is report_final---<uuid>.txt.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused, useful repair with shipped-entry-point evidence, retained decoding behavior, and no actionable findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The contributor supplies live Feishu SDK download output, and obviyus supplies Gateway webhook proof through the actual resource-download path with filename controls and matching file hashes; the subsequent commit changes only test typing.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Feishu attachments lose the portion of their filenames after a quoted semicolon.
Reason: The patch restores intended filename preservation for a demonstrated live API response without adding settings or changing storage ownership.

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
Reviewed head: 32a206aaa407c323bcc2e23ee3809667e9e7e9db

Before merge

None.

Findings

None.

Agent review details

How this fits together

The 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]
Loading

Technical review

Best 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

  • Content-Disposition parsing keeps the original intent (3c6a49b: Preserve inbound Feishu filename and content-type metadata while hardening media handling.)
  • Latin-1 filename recovery keeps the original intent (4c72e60: Recover UTF-8 CJK filenames exposed through Latin-1 header decoding while retaining extended filename priority.)
  • Filename regression test organization keeps the original intent (3d7ef21: Consolidate repetitive setup while preserving distinct behavioral coverage.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Tak Hoffman: Raw commit 3c6a49b adds extensions/feishu/src/media.ts:94 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 3c6a49b27ea0; files: extensions/feishu/src/media.ts)
  • Vincent Koc: Raw commit 4c72e60 adds extensions/feishu/src/media.ts:153 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 4c72e605cdc7; files: extensions/feishu/src/media.ts)
  • Peter Steinberger: Raw commit 73fe145 adds extensions/feishu/src/media.ts:215 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 73fe145a1e6e; files: extensions/feishu/src/media.ts)

PR surface

Source +34, Tests -6. Total +28 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 37 3 +34
Tests 1 13 19 -6
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 50 22 +28

Preflight source

Source 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

Metric Value Why it matters
Production versus test changes Production +37/-3; tests +13/-19 Quote-aware parsing requires a small scanner; regression cases reuse the existing table and reduce test scaffolding.

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P2: A confirmed attachment naming defect has limited impact; attachment contents and delivery remain intact.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (3 earlier review cycles)
  • reviewed 2026-11-09T16:58:24.606Z sha 8eabc51 :: needs real behavior proof before merge. :: none
  • reviewed 2026-11-10T01:18:22.774Z sha 8eabc51 :: needs maintainer review before merge. :: none
  • reviewed 2026-11-10T01:35:07.369Z sha afe2984 :: needs maintainer review before merge. :: none

Reviewed November 9, 2026, 9:01 PM ET / November 10, 2026, 02:01 UTC (Revision 4).

@Wang-Zephyr

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 10, 2026
@obviyus

obviyus commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@openclaw-barnacle openclaw-barnacle Bot added channel: feishu Channel integration: feishu size: S labels Nov 10, 2026
@clawsweeper

clawsweeper Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 10, 2026
@obviyus

obviyus commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

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.

  • Header attachment; filename="report;final.pdf": main saved report on both runs. This PR saved report_final on both runs, which is the name after the normal safe-name cleanup.
  • Controls gave the same result on main and this PR, two runs each:
    • filename="report.pdf" saved as report.
    • UTF-8 filename* (报告) won over filename="fallback.pdf".
    • Unquoted filename=report.pdf; size=123 saved as report.
    • With no header, the message metadata name meta.pdf was used and saved as meta.
  • On all 20 downloads, the saved file's sha256 matched the bytes the stand-in served.

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.

@obviyus

obviyus commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 10, 2026
@obviyus
obviyus merged commit 109ad1c into openclaw:main Nov 10, 2026
104 checks passed
@obviyus

obviyus commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

Landed in 109ad1c. Thanks @Wang-Zephyr. Feishu attachments now keep quoted filenames that contain semicolons.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 10, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: feishu Channel integration: feishu P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Feishu attachment downloads truncate quoted filenames containing semicolons

2 participants