Skip to content

fix(ui): strip inbound metadata blocks and guard reply-tag streaming (clean rewrite)#22346

Merged
vincentkoc merged 3 commits intomainfrom
vincentkoc-code/clean-21643-rebase-origin-main
Feb 21, 2026
Merged

fix(ui): strip inbound metadata blocks and guard reply-tag streaming (clean rewrite)#22346
vincentkoc merged 3 commits intomainfrom
vincentkoc-code/clean-21643-rebase-origin-main

Conversation

@vincentkoc
Copy link
Copy Markdown
Member

@vincentkoc vincentkoc commented Feb 21, 2026

This is a clean reroute of the closed PR for this change.

  • Reuses the final intended payload from the previously closed work.
  • Rebased onto origin/main and squashed to a single clean commit.
  • This branch is clean and ready for normal review.

This supersedes #21643. The original PR became stale due a detached/dirty head after history churn while attempting rebase/cleanup.

Closes #21548.

Greptile Summary

This PR enhances security by preventing inbound metadata blocks from leaking into chat history and fixes streaming artifacts when reply tags are being processed.

Key changes:

  • Added stripInboundMetadataBlocks() function to remove untrusted metadata prefixes (like "Conversation info (untrusted metadata):", "Sender (untrusted metadata):", etc.) from user messages at display boundaries
  • Integrated the new stripping function into the sanitization pipeline in chat-sanitize.ts, applying it before envelope and message ID stripping
  • Added guard in stripTrailingDirective() to handle incomplete reply-tag streaming by removing trailing [ characters that haven't formed complete [[directive]] tags yet
  • Added comprehensive test coverage for the new metadata stripping behavior, including prefix-only matching (doesn't strip metadata blocks that appear mid-message)

The implementation correctly strips multiple consecutive metadata blocks at the start of messages using a loop with regex matching, then trims the result. The regex pattern properly escapes special characters in the header strings before building the alternation pattern.

Confidence Score: 4/5

  • This PR is safe to merge with minor risk
  • The changes are well-tested with comprehensive test coverage for the new stripping behavior. The security fix is straightforward and addresses a real vulnerability (metadata injection/leakage). The regex implementation is sound and the integration into existing sanitization pipeline is minimal and follows existing patterns. One minor logic concern was flagged regarding regex escaping, but this doesn't affect the current headers. The trailing [ guard is a simple defensive check that prevents streaming artifacts.
  • Review src/shared/chat-envelope.ts line 27 to verify regex escape pattern is complete

Last reviewed commit: 900afd4

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime agents Agent runtime and tooling size: S maintainer Maintainer-authored PR labels Feb 21, 2026
@vincentkoc vincentkoc self-assigned this Feb 21, 2026
@vincentkoc vincentkoc marked this pull request as ready for review February 21, 2026 02:30
Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment thread src/shared/chat-envelope.ts Outdated
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
@vincentkoc vincentkoc merged commit 9a6b26d into main Feb 21, 2026
13 of 14 checks passed
@vincentkoc vincentkoc deleted the vincentkoc-code/clean-21643-rebase-origin-main branch February 21, 2026 02:41
mmyyfirstb pushed a commit to mmyyfirstb/openclaw that referenced this pull request Feb 21, 2026
…(clean rewrite) (openclaw#22346)

* fix(ui): strip inbound metadata blocks from user messages

* chore: clean up metadata-strip format and changelog credit

* Update src/shared/chat-envelope.ts

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

---------

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
mreedr pushed a commit to mreedr/openclaw-custom that referenced this pull request Feb 24, 2026
…(clean rewrite) (openclaw#22346)

* fix(ui): strip inbound metadata blocks from user messages

* chore: clean up metadata-strip format and changelog credit

* Update src/shared/chat-envelope.ts

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

---------

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
zooqueen pushed a commit to hanzoai/bot that referenced this pull request Mar 6, 2026
…(clean rewrite) (openclaw#22346)

* fix(ui): strip inbound metadata blocks from user messages

* chore: clean up metadata-strip format and changelog credit

* Update src/shared/chat-envelope.ts

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

---------

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
VikrantSingh01 added a commit to VikrantSingh01/openclaw that referenced this pull request Mar 19, 2026
The `\-` inside a character class is unnecessary when `-` is at the end.
Fixes oxlint no-useless-escape error introduced in openclaw#22346.
lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
…(clean rewrite) (openclaw#22346)

* fix(ui): strip inbound metadata blocks from user messages

* chore: clean up metadata-strip format and changelog credit

* Update src/shared/chat-envelope.ts

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

---------

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
…(clean rewrite) (openclaw#22346)

* fix(ui): strip inbound metadata blocks from user messages

* chore: clean up metadata-strip format and changelog credit

* Update src/shared/chat-envelope.ts

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

---------

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling gateway Gateway runtime maintainer Maintainer-authored PR size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TUI renders gateway reconnect metadata as visible chat messages

1 participant