Skip to content

Harden: reject clipboard-paste HTML on the message field - #216

Merged
Baskarayelu merged 1 commit into
QuickLendX:mainfrom
greatest0fallt1me:fix/111-reject-clipboard-html-paste
Aug 28, 2026
Merged

Harden: reject clipboard-paste HTML on the message field#216
Baskarayelu merged 1 commit into
QuickLendX:mainfrom
greatest0fallt1me:fix/111-reject-clipboard-html-paste

Conversation

@greatest0fallt1me

@greatest0fallt1me greatest0fallt1me commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

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`:

  • `getPlainTextFromPaste(event)`: reads only the clipboard's `text/plain` entry, never `text/html`.
  • `createPlainTextPasteHandler(onText)`: a drop-in `onPaste` handler -- prevents the default paste and splices the plain text in at the current selection (replacing it if non-empty) instead, calling `onText` with the resulting value for the caller's controlled state.

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

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.
@Baskarayelu
Baskarayelu merged commit 3a4065a into QuickLendX:main Aug 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants