feat: add content sanitizer to strip hidden text before AI processing#2137
Open
gentlemandev wants to merge 1 commit intomainfrom
Open
feat: add content sanitizer to strip hidden text before AI processing#2137gentlemandev wants to merge 1 commit intomainfrom
gentlemandev wants to merge 1 commit intomainfrom
Conversation
…I processing Strips zero-width Unicode characters, RTL/LTR overrides, hidden HTML elements (display:none, visibility:hidden, zero font-size, opacity:0, white-on-white text, offscreen positioning), and HTML comments that attackers use to inject invisible instructions into email content. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
Contributor
There was a problem hiding this comment.
2 issues found across 2 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="apps/web/utils/ai/content-sanitizer.ts">
<violation number="1" location="apps/web/utils/ai/content-sanitizer.ts:14">
P1: The `color` regex also matches `background-color`, causing false positives that remove visible content.</violation>
<violation number="2" location="apps/web/utils/ai/content-sanitizer.ts:46">
P2: `sanitizeForAI` drops empty-string inputs by using truthy checks; use an explicit `undefined` check so empty content is preserved.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| /visibility\s*:\s*hidden/i, | ||
| /font-size\s*:\s*0(?:px|em|rem|%|pt)?\s*[;"']/i, | ||
| /opacity\s*:\s*0\s*[;"']/i, | ||
| /color\s*:\s*(?:#fff(?:fff)?|white|rgb\(\s*255\s*,\s*255\s*,\s*255\s*\))\s*[;"']/i, |
Contributor
There was a problem hiding this comment.
P1: The color regex also matches background-color, causing false positives that remove visible content.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/web/utils/ai/content-sanitizer.ts, line 14:
<comment>The `color` regex also matches `background-color`, causing false positives that remove visible content.</comment>
<file context>
@@ -0,0 +1,87 @@
+ /visibility\s*:\s*hidden/i,
+ /font-size\s*:\s*0(?:px|em|rem|%|pt)?\s*[;"']/i,
+ /opacity\s*:\s*0\s*[;"']/i,
+ /color\s*:\s*(?:#fff(?:fff)?|white|rgb\(\s*255\s*,\s*255\s*,\s*255\s*\))\s*[;"']/i,
+];
+
</file context>
| textHtml?: string; | ||
| }): { textPlain?: string; textHtml?: string } { | ||
| return { | ||
| textPlain: input.textPlain ? stripHiddenText(input.textPlain) : undefined, |
Contributor
There was a problem hiding this comment.
P2: sanitizeForAI drops empty-string inputs by using truthy checks; use an explicit undefined check so empty content is preserved.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/web/utils/ai/content-sanitizer.ts, line 46:
<comment>`sanitizeForAI` drops empty-string inputs by using truthy checks; use an explicit `undefined` check so empty content is preserved.</comment>
<file context>
@@ -0,0 +1,87 @@
+ textHtml?: string;
+}): { textPlain?: string; textHtml?: string } {
+ return {
+ textPlain: input.textPlain ? stripHiddenText(input.textPlain) : undefined,
+ textHtml: input.textHtml ? stripHiddenHtml(input.textHtml) : undefined,
+ };
</file context>
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
utils/ai/content-sanitizer.tsthat strips invisible/hidden content from emails before passing to AIWhat it strips
\u200B,\u200C,\u200D,\u2060,\uFEFF\u202A-\u202E,\u2066-\u2069display:none,visibility:hidden,font-size:0,opacity:0color:#fff/#ffffff/white/rgb(255,255,255)position:absolute+left:-9999pxwidth:0/height:0+overflow:hidden<!-- ... -->API
Not yet wired in
This PR adds the utility and tests. A follow-up PR will call
sanitizeForAI()beforeaiChooseRule(),aiGenerateArgs(), andaiDraftReply().Test plan
🤖 Generated with Claude Code