Skip to content

Commit 292ea7a

Browse files
fix(outbound): preserve angle-address emails in plain-text replies (#124249)
Preserve RFC 5322 angle-address emails without weakening namespaced tag stripping, and keep the iMessage security projection aligned. Co-authored-by: Aria Ghasedi <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]>
1 parent fa57fe5 commit 292ea7a

4 files changed

Lines changed: 28 additions & 2 deletions

File tree

‎extensions/imessage/src/monitor/sanitize-outbound.test-support.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Imessage test support covers sanitize outbound plugin behavior.
2+
import { sanitizeForPlainText } from "openclaw/plugin-sdk/channel-outbound";
23
import { describe, expect, it } from "vitest";
34
import {
45
protectIMessageFencedRoleMarkers,
@@ -97,6 +98,14 @@ describe("sanitizeOutboundText", () => {
9798
}
9899
});
99100

101+
it("strips colon-qualified tags before the final security projection", () => {
102+
const text = sanitizeForPlainText("<vendor:note>visible</vendor:note>", {
103+
style: "markdown",
104+
});
105+
106+
expect(sanitizeIMessageFinalOutboundText(text).text).toBe("visible");
107+
});
108+
100109
it.each([
101110
"<system-reminder>PRIVATE_RUNTIME_SECRET</system-reminder>",
102111
"< SYSTEM-REMINDER data-origin='runtime'>PRIVATE_RUNTIME_SECRET< / SYSTEM-REMINDER >",

‎extensions/imessage/src/monitor/sanitize-outbound.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const PRIVATE_USE_START = 0xe000;
2525
const PRIVATE_USE_END = 0xf8ff;
2626
const MAX_PRIVATE_MARKDOWN_UNWRAP_PASSES = 32;
2727
// Mirror the private shared plain-text HTML grammar to inspect every destructive removal stage.
28-
const PLAIN_TEXT_HTML_TAG_RE = /<\/?[a-z][a-z0-9_-]*\b[^>]*>/gi;
28+
const PLAIN_TEXT_HTML_TAG_RE = /<\/?[a-z][a-z0-9_.:-]*(?=[\s/>])[^>]*>/gi;
2929
const PRIVATE_PROVIDER_TAG_NAMES = [
3030
"think",
3131
"thinking",

‎src/infra/outbound/sanitize-text.test.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ describe("sanitizeForPlainText", () => {
8282
expect(sanitizeForPlainText('<a href="https://example.com">link</a>')).toBe("link");
8383
});
8484

85+
it("strips colon- and dot-qualified tags", () => {
86+
expect(
87+
sanitizeForPlainText("<vendor:note>one</vendor:note><vendor.note>two</vendor.note>"),
88+
).toBe("onetwo");
89+
});
90+
8591
it("keeps stripping tags exposed by malformed tag text", () => {
8692
const sanitized = sanitizeForPlainText(
8793
"before <<script>script>alert(1)</<script>script> after",
@@ -170,6 +176,16 @@ describe("sanitizeForPlainText", () => {
170176
);
171177
});
172178

179+
it("preserves angle-addr email addresses", () => {
180+
expect(sanitizeForPlainText("Contact us at Support <[email protected]> or reply here")).toBe(
181+
"Contact us at Support <[email protected]> or reply here",
182+
);
183+
});
184+
185+
it("still strips tags whose name ends at a tag boundary", () => {
186+
expect(sanitizeForPlainText("Ping <users/abc> for access")).toBe("Ping for access");
187+
});
188+
173189
// --- passthrough --------------------------------------------------------
174190

175191
it("passes through clean text unchanged", () => {

‎src/infra/outbound/sanitize-text.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import { stripInternalRuntimeScaffolding } from "./protocol-scaffolding.js";
77
// Retained for the deprecated plugin-sdk/infra-runtime compatibility barrel.
88
export { stripInternalRuntimeScaffolding };
99

10-
const HTML_TAG_RE = /<\/?[a-z][a-z0-9_-]*\b[^>]*>/gi;
10+
// A tag name ends at whitespace, `/`, or `>`; `<[email protected]>` is prose, not markup.
11+
const HTML_TAG_RE = /<\/?[a-z][a-z0-9_.:-]*(?=[\s/>])[^>]*>/gi;
1112
const MAY_CONTAIN_MARKDOWN_CODE_RE = /[`~]|\t| {4}/;
1213
const CODE_ESCAPE = "\u0000e";
1314
const CODE_PLACEHOLDER = "\u0000p";

0 commit comments

Comments
 (0)