You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Summary
- implemented sanitization on all ends of the `EnrichedTextInput` and
`EnrichedText`
- we were allowing all custom mention attributes names, inluding
potentially malicious ones. Now the attributes are sanitized and if one
doesn't start with the `data-` prefix, we print a runtime warning that
it might get stripped by a sanitizer
- the `'default'` mention style functionality wasn't documented
- the normalizer let through only a predefined set of `mention`
attributes: `id`, `text` and `indicator` - now it allows every custom
attribute
- implemented a new web-only prop `sanitizationConfig`, currently with
only `linkRegex` field, allowing to persist custom links which would be
otherwise stripped by the sanitizer
## Test Plan
Try to create a mention with an illegal HTML attribute, eg. `onClick`.
It should be stripped and a suitable console warning should be visible.
## Compatibility
| OS | Implemented |
| ------- | :---------: |
| iOS | ❌ |
| Android | ❌ |
| Web | ✅ |
## Checklist
- [x] E2E tests are passing
- [x] Required E2E tests have been added (if applicable)
If only a single config is given, the style applies to all mention types. You can also set a different config for each mentionIndicator that has been defined, then the prop should be a record with indicators as a keys and configs as their values.
1044
+
If only a single config is given, the style applies to all mention types. You can also set a different config for each mentionIndicator that has been defined, then the prop should be a record with indicators as keys and configs as their values. Additionally, you can define a style using the `'default'` key, which will act as a base that the rest of your defined styles will fallback on.
1045
1045
1046
1046
-`color` defines the color of mention's text, takes [color](https://reactnative.dev/docs/colors) value and defaults to `blue`.
1047
1047
-`backgroundColor` is the mention's background color, takes [color](https://reactnative.dev/docs/colors) value and defaults to `yellow`.
Copy file name to clipboardExpand all lines: docs/WEB.md
+36-1Lines changed: 36 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -51,4 +51,39 @@ See [Web Keyboard Shortcuts](./INPUT_API_REFERENCE.md#web-keyboard-shortcuts) fo
51
51
52
52
## HTML sanitization
53
53
54
-
You are responsible for sanitizing HTML on both input and output. The library does not guarantee safe or clean HTML output. This applies to any HTML you persist, render elsewhere, or accept from untrusted sources (XSS, paste attacks, etc.).
54
+
On web, HTML is sanitized automatically with [DOMPurify](https://github.com/cure53/DOMPurify) on both input and output. This reduces XSS risk, but you should still treat untrusted HTML with caution and apply your own server-side sanitization.
55
+
56
+
-**`EnrichedText`** sanitizes its `children` before rendering.
57
+
-**`EnrichedTextInput`** sanitizes every HTML entry point — `defaultValue`, the `setValue` ref method, and pasted HTML — as well as its output from `getHTML` and the `onChangeHtml` callback.
58
+
59
+
### Allowing custom link protocols
60
+
61
+
By default, sanitization strips links with non-standard protocols (e.g. `custom://…`). Both `EnrichedText` and `EnrichedTextInput` accept a web-only `sanitizationConfig` prop whose `linkRegex` field lets you control which link URIs survive.
62
+
63
+
`linkRegex` maps directly to DOMPurify's [`ALLOWED_URI_REGEXP`](https://github.com/cure53/DOMPurify#can-i-configure-dompurify), so it **replaces** the default allow-list rather than extending it — remember to keep the standard protocols you still want to permit:
64
+
65
+
```tsx
66
+
<EnrichedText
67
+
sanitizationConfig={{
68
+
// Permit the usual protocols plus a custom "custom://" scheme.
When `sanitizationConfig` is omitted, DOMPurify's built-in default is used.
78
+
79
+
> Note: `sanitizationConfig.linkRegex` only controls what sanitization keeps. It is independent of the top-level `linkRegex` prop, which controls autolink detection while typing. To both autolink and preserve a custom protocol, configure both.
80
+
81
+
### Custom mention attributes
82
+
83
+
To attach custom data to a mention, use the `data-` prefix (e.g. `data-user-id`) to make sure they survive sanitization. Attributes passed to the `setMention` ref method are properly sanitized.
84
+
85
+
## Client-only rendering (no SSR)
86
+
87
+
Both `EnrichedText` and `EnrichedTextInput` are **client-only** components. They rely on browser-only APIs (`DOMParser`, `DOMPurify`, `TipTap`) and are **not designed for server-side rendering (SSR)**.
88
+
89
+
If your application uses SSR (Next.js, Remix, Gatsby, etc.), make sure these components only render on the client.
0 commit comments