1. Sanitizing the inputs
<script />, Javacript:URL() or event handlers like onclick(), onfocus() etc... from a given input, to avoid SQL code injection and Cross site scripting.
Let's say you have a WYSIWYG/Rich-text editor in your site to get user input for a conversation in a ticket.
This html input once submitted, will be rendered as HTML in the list of conversations made. This conversation can have inline-images, tables, text content with inline styles etc...
React has a attribute "dangerouslySetInnerHTML" to render html in the DOM. To avoid XSS attacks, this html must be sanitized.
It is a best practice to do it before sending the input to BE, like below.
and also before rendering in the DOM
DOMPurify is a Javascript library, that extensively sanitizes HTML.
2. Content Security Policy (CSP)
If you need to load a image, let's say from "unsplash.com" https://images.unsplash.com/photo-1701311310084-159429e16320