fix: strip untrusted metadata blocks and system event lines from webchat UI#22147
fix: strip untrusted metadata blocks and system event lines from webchat UI#22147takeiteasydragon wants to merge 1 commit intoopenclaw:mainfrom
Conversation
…hat UI (openclaw#20297) The webchat UI was rendering raw internal metadata in chat bubbles, including "Conversation info (untrusted metadata):" JSON blocks, "Sender (untrusted metadata):" blocks, and "System: [timestamp]" event lines. Added stripUntrustedMetadataBlocks() and stripSystemEventLines() to the shared chat-envelope module, and wired them into both the gateway sanitization pipeline and the UI message extraction layer as defense in depth. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Disclosure: AI-assisted contributionThis PR was developed in a pair-programming session with Claude Code (claude-opus-4-6). Full transparency on the division of work: Claude Code handled:
I (human) handled:
The entire session — from reading the issue to submitting this PR — took about one hour. I'm relatively new to open-source contribution, and Claude Code served as both a coding partner and a patient teacher, walking me through the fork → branch → fix → test → PR workflow step by step. For reference, PR #20231 (generated by an automated AI agent) attempted a narrower fix targeting only the |
|
Duplicate/covered by #22142. Closed to avoid redundant overlap. |
Summary
Fixes #20297
The webchat UI was rendering raw internal metadata in chat bubbles. This PR adds stripping for two categories of leaked metadata:
Conversation info (untrusted metadata):,Sender (untrusted metadata):,Thread starter (untrusted, for context):,Replied message (untrusted, for context):,Forwarded message context (untrusted metadata):, andChat history since last reply (untrusted, for context):followed by ```json code fencesSystem: [timestamp] event descriptionlines prepended byprependSystemEvents()Changes
src/shared/chat-envelope.tsstripUntrustedMetadataBlocks()andstripSystemEventLines()src/gateway/chat-sanitize.tsui/src/ui/chat/message-extract.tssrc/gateway/chat-sanitize.test.tsSanitization pipeline (after this fix)
Test plan
npx vitest run src/gateway/chat-sanitize.test.ts— 10/10 passnpx vitest run src/auto-reply/reply/inbound-meta.test.ts— 13/13 passpnpm build— passpnpm lint— 0 errors, 0 warnings🤖 Generated with Claude Code
Greptile Summary
Adds stripping for untrusted metadata blocks and system event lines that were leaking into webchat UI. The implementation correctly removes internal metadata like "Conversation info (untrusted metadata):" JSON blocks, "Sender (untrusted metadata):" blocks, and "System: [timestamp]" event lines. The fix is applied at both the gateway sanitization pipeline and the UI extraction layer for defense-in-depth.
stripUntrustedMetadataBlocks()with regex pattern to match all untrusted metadata block variantsstripSystemEventLines()to remove leading system event lines and trailing blank linesConfidence Score: 5/5
Last reviewed commit: efd894b
(2/5) Greptile learns from your feedback when you react with thumbs up/down!