Hi,
to prevent Cross-site scripting attacks on your website we strongly recommend to use out-of-box web parts which are XSS safe. If you need to write your own web parts, layouts, transformations etc. I would recommend to check our documentation mentioned by Peter Mogilnitski or check our blog post about XSS protection.
Create a general rule how to protect against XSS is quite hard because it depends on the context (HTML, JavaScript etc.) the data is rendered. Our guidelines should help you to create a secure website.
Best regards,
Juraj