DOMPurify
html-react-parser


DOMPurify | html-react-parser | |
---|---|---|
52 | 6 | |
15,769 | 2,335 | |
2.4% | 1.2% | |
8.7 | 9.6 | |
16 days ago | 2 days ago | |
JavaScript | TypeScript | |
GNU General Public License v3.0 or later | MIT License |
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.
DOMPurify
-
NodeJS Fundamentals: pure function
Pure functions, by their nature, reduce the attack surface. Because they don’t modify external state, they’re less susceptible to side-effect vulnerabilities like object pollution or prototype attacks. However, if a pure function processes user input, it’s still crucial to validate and sanitize that input to prevent XSS or other injection attacks. Libraries like DOMPurify (https://github.com/cure53/DOMPurify) can be used to sanitize HTML content, and schema validation libraries like zod (https://github.com/colyseus/zod) can be used to validate data structures. Always treat user input as untrusted.
-
NodeJS Fundamentals: ECMAScript
ECMAScript features like Proxy can be exploited if not used carefully. Avoid creating proxies that intercept sensitive operations without proper validation. Prototype pollution attacks are a concern; sanitize user input and avoid modifying the Object.prototype. XSS vulnerabilities can arise from improperly handling user-provided data in dynamic contexts. Use DOMPurify (https://github.com/cure53/DOMPurify) to sanitize HTML before rendering it. Validation libraries like zod (https://github.com/colyseus/zod) can enforce data schemas and prevent unexpected input.
-
Your rich text could be a cross-site scripting vulnerability
Let's take a look at how we implement sanitization in the secure version of our vulnerable application. Since this application is primarily written using JavaScript, we use the dompurify library for the client side and the isomorphic-dompurify library for server-side sanitization. In the app.js program that acts as our web server, you will find an express endpoint /sanitized with a GET and POST implementation:
-
The Final Stretch of My Open Source Journey: Part 2
After several hours of code review, I finally spotted something unfamiliar in the Markdown Renderer component: a function called escapeHTML was being used to escape HTML, even though DOMPurify was already being used for sanitization right after!
-
Understanding Cross-Site Scripting (XSS): A Quick Reference
DOMPurify Documentation
-
Securing JavaScript Applications: Common Vulnerabilities and How to Avoid Them
Use libraries such as DOMPurify to sanitize input.
-
Mitigate XSS exploits when using React's `dangerously SetInnerHTML`
//https://github.com/cure53/DOMPurify import React from "react"; import DOMPurify from "dompurify"; const sanitize = (dirty) => DOMPurify.sanitize(dirty); const DangerousHtml = ({ innerHTML, tag }) => { const clean = sanitize(innerHTML); if (typeof tag === "undefined") { return
; } return ; }; export default DangerousHtml; -
Navigating the Security Risks of Arbitrary Values in Tailwind CSS
Input Sanitization: The most crucial step in preventing XSS attacks is to ensure that all user-generated content is properly sanitized before it is rendered on the page. Use libraries like DOMPurify or built-in sanitization functions provided by your framework (e.g., React's dangerouslySetInnerHTML) to strip out any potentially harmful code.
-
Safely Handling HTML in React
When using dangerouslySetInnerHTML, it is crucial to sanitize the HTML strings to prevent XSS attacks. DOMPurify is a robust library that cleans HTML content by removing or neutralizing potentially dangerous scripts or tags.
-
Show HN: Markdown HN profiles at {user}.at.hn
Since marked doesn't do it for you, make sure you sanitize the user input (the text on the user profiles) before rendering it to visitors.
Some libraries for doing that with good defaults:
- https://github.com/cure53/DOMPurify
- https://github.com/apostrophecms/sanitize-html
- https://github.com/bevacqua/insane
(right now your site looks vulnerable to XSS)
html-react-parser
-
how to inject custom js/css/html code that is fetched from an API into nextjs app?
using libraries like html-react-parser but it did not work see: https://github.com/remarkablemark/html-react-parser/discussions/1015
-
Alternatives to dangerouslySetInnerHTML
I was thinking about some sanitization library but found this: https://github.com/remarkablemark/html-react-parser which i have reviewed to deeply yet.
-
Displaying WYSIWYG editor's output with React
I'm glad I could help! Please be careful though and check the FAQ section of the library. It says that it does not sanitize and it's not XSS safe. This is the issue where they explain: https://github.com/remarkablemark/html-react-parser/issues/94
-
react-icons, custom components and JSON rendering
I then switched to html-react-parser, but same result.
-
How to Render HTML string in a React component ?
by using dangerouslySetInnerHTML, entire html in the string is preserved. Other alternative would be to use a html-react-parser library.
-
A Walkthrough of Updating My Portfolio Site with Netlify Functions and the Dev.to API
However, when I insert the body_html field into my JSX map, it's just displaying a string with a bunch html tags in it. One quick google showed me html-react-parser and after the easiest install and application, my blogs are loading beautifully with pictures and links. All I had to add was the import (import parse from 'html-react-parser';) and a couple lines to my blogList map:
What are some alternatives?
sanitize-html - Clean up user-submitted HTML, preserving whitelisted elements and whitelisted attributes on a per-element basis. Built on htmlparser2 for speed and tolerance
node-csvtojson - Blazing fast and Comprehensive CSV Parser for Node.JS / Browser / Command Line.
js-xss - Sanitize untrusted HTML (to prevent XSS) with a configuration specified by a Whitelist
texthighlighter - a no dependency typescript npm package for highlighting user selected text
Themis - Easy to use cryptographic framework for data protection: secure messaging with forward secrecy and secure data storage. Has unified APIs across 14 platforms.
imparse - Parser generator that can be used to quickly and succinctly define a parser definition, and to deploy an automatically-generated implementations thereof in multiple languages and on multiple platforms.

