Harden: reject clipboard-paste HTML on the message field - #216
Merged
Baskarayelu merged 1 commit intoAug 28, 2026
Merged
Conversation
No paste-sanitization utility existed anywhere in the app. Add lib/sanitizePaste.ts: getPlainTextFromPaste() reads only the text/plain clipboard entry, never text/html, and createPlainTextPasteHandler() is a drop-in onPaste handler that prevents the default paste and splices the plain text in at the current selection instead, so HTML from a rich-text clipboard source can never reach a plain-text field's value.
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.
Note on scope
This app has no message/rich-text field yet. Rather than skip the issue, I added the reusable sanitization utility a message field would use, so it's ready to wire in.
Summary
No paste-sanitization existed anywhere in the codebase -- a plain-text field's default paste behavior carries whatever MIME types the clipboard has, including `text/html` from a rich-text source (an email client, a web page), which can inject markup a plain-text field was never meant to hold.
Change
`lib/sanitizePaste.ts`:
Tests
`lib/sanitizePaste.test.ts`: `getPlainTextFromPaste` returns the plain-text payload, never reads `text/html`, handles missing clipboard data; the handler prevents default, splices at an empty selection, and replaces a non-empty selection.
`npx vitest run lib/sanitizePaste.test.ts`: 6 passed. `npx tsc --noEmit` / `npx eslint` on changed files: clean.
Related to #111