DOMPurify VS remark

Compare DOMPurify vs remark and see what are their differences.

DOMPurify

DOMPurify - a DOM-only, super-fast, uber-tolerant XSS sanitizer for HTML, MathML and SVG. DOMPurify works with a secure default, but offers a lot of configurability and hooks. Demo: (by cure53)

remark

markdown processor powered by plugins part of the @unifiedjs collective (by remarkjs)
SurveyJS - Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App
With SurveyJS form UI libraries, you can build and style forms in a fully-integrated drag & drop form builder, render them in your JS app, and store form submission data in any backend, inc. PHP, ASP.NET Core, and Node.js.
surveyjs.io
featured
InfluxDB - Power Real-Time Data Analytics at Scale
Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
www.influxdata.com
featured
DOMPurify remark
42 42
12,802 7,211
- 0.9%
8.8 7.0
7 days ago 7 days ago
JavaScript JavaScript
GNU General Public License v3.0 or later MIT License
The number of mentions indicates the total number of mentions that we've tracked plus the number of user suggested alternatives.
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

Posts with mentions or reviews of DOMPurify. We have used some of these posts to build our list of alternatives and similar projects. The last one was on 2024-04-09.
  • JavaScript Libraries for Implementing Trendy Technologies in Web Apps in 2024
    12 projects | dev.to | 9 Apr 2024
    DOMPurify
  • Lessons from open-source: Use window.trustedTypes to prevent DOM XSS.
    2 projects | dev.to | 8 Apr 2024
  • Launched my Social Media website for lonely people living abroad, all thanks to NextJS!
    1 project | /r/nextjs | 8 Dec 2023
    I saw that some people were injecting alerts. If you haven't fixed it yet, consider using something like DOMPurify to sanitize the HTML input before posting it to the db.
  • Mastering DOM manipulation with vanilla JavaScript
    5 projects | news.ycombinator.com | 6 Nov 2023
    You mean from this article "Sanitize HTML strings"? https://phuoc.ng/collection/html-dom/sanitize-html-strings/

    Yeah, that article really shouldn't imply that sanitization is "that easy". It does at least mention https://github.com/cure53/DOMPurify at the end but it should LOUDLY argue against attempting to write this particular thing yourself and promote that exclusively in my opinion.

  • Crafting a Dynamic Blog with Next.js 13 App Directory
    3 projects | dev.to | 1 Sep 2023
    It is highly recommended to use an XSS Sanitizer like DOMPurify to sanitize HTML and prevent XSS attacks. For Next.js projects, which prominently feature server-side rendering, Isomorphic DOMPurify is especially valuable. It offers a seamless sanitization process across both server and client, ensuring consistent HTML sanitization in environments like Next.js where a native server-side DOM isn't present.
  • Mitigating DOM clobbering attacks in JavaScript
    1 project | dev.to | 7 Aug 2023
    Note: We’ve used DOMPurify to sanitize the HTML in the above code block. You can install it in Node.js with npm install dompurify. Include it in your HTML with .
  • 5 injection vulnerabilities hackers don't want developers to know about (and how to prevent them)
    3 projects | /r/node | 22 Jun 2023
    body, input.value property, or body are all different). If you need to insert untrusted input into raw HTML, use a well-tested sanitizer such as DOMPurify.

    Setting a strong Content Security Policy without unsafe-inline or unsafe-eval in the script-src or default-src directives is an effective defense-in-depth) measure to prevent modern browsers from executing attacker code even if the attacker is able to insert </code> elements into the page.</p> <p><strong>3. HTTP API injection</strong></p> <p>RESTful APIs, GraphQL, and other HTTP-based APIs are ubiquitous. When a web application makes an API call to another service, injection vulnerabilities are possible when that request includes untrusted input.</p> <p>Consider a contrived example in which a web app integrates with a payments service that has a REST API endpoint for creating a subscription: <code>POST /subscriptions/{product_id}?price_usd=<price></code> where <code>price_usd</code> is optional, and a pre-configured price is used if omitted. If an attacker controls the value of <code>product_id</code> and passes a value of <code>desired_product_id?price_id=0</code>, the web app would end up making a request to <code>POST /subscriptions/desired_product_id?price_id=0</code>, which would allow the attacker to sign up for a free subscription.</p> <p>In JavaScript, the standard way to sanitize untrusted inputs in URL paths is <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent"><code>encodeURIComponent</code></a>, which replaces problematic characters such as <code>?</code> and <code>/</code> with safe percent-encoded sequences. When inserting untrusted input into URL query parameters, <a href="https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams/URLSearchParams"><code>new URLSearchParams(queryParams)</code></a> provides a convenient, safe interface for building a query string from a JavaScript object of key-value pairs.</p> <p><strong>4. Shell injection</strong></p> <p>Backend APIs sometimes need to execute external commands on the machine where they run. Consider an API that performs <a href="https://en.wikipedia.org/wiki/WHOIS">WHOIS</a> lookups for a requested domain by executing the <code>whois</code> command locally.</p> <p>Consider the following <strong>vulnerable</strong> Node.js code:</p> <pre><code>const whois = child_process.execSync(`whois ${whoisRequest.domain}`); </code></pre> <p>If an attacker can pass the domain <code>reddit.com && rm -rf /</code>, the backend will execute the command <code>whois reddit.com && rm -rf /</code>. The <a href="https://nodejs.org/api/child_process.html#child_processexecsynccommand-options"><code>child_process.execSync</code></a> function passes the command string to the shell (<code>/bin/sh</code> by default on Linux), which parses <code>&& rm -rf /</code> as a subsequent command to wipe the filesystem.</p> <p>To avoid this issue, <strong>never pass untrusted input to a shell</strong>. Instead, use an interface such as <a href="https://nodejs.org/api/child_process.html#child_processexecfilesyncfile-args-options"><code>child_process.execFileSync</code></a> that executes a specific binary (which shouldn't be a shell!) and passes arguments <em>as an array</em>:</p> <pre><code>const whois = child_process.execFileSync("whois", [whoisRequest.domain]); </code></pre> <p>Now, even if the user passes a domain <code>reddit.com && rm -rf /</code>, that entire string will be passed as the command-line argument to <code>whois</code>, which will exit with an error but will not cause any harmful side-effects. Perhaps an even better solution would be to use a library to perform WHOIS queries without needing to execute a separate command.</p> <p>Astute readers may point out that validating the domain against a regex would also likely prevent shell injection in this case. However, avoiding the possibility of shell injection by using a safe interface that keeps untrusted input away from a shell's command parser is a more robust solution that avoids shell injection in all cases.</p> <p><strong>5. Path traversal</strong></p> <p>Finally, a path traversal vulnerability arises when an untrusted input is inserted into a filesystem path, which can cause the wrong file to be read or even written. Consider a backend API that reads a file at the path <code>/teams/${team_id}/${report_name}.csv</code>. If an attacker controls the value of <code>report_name</code> but not <code>team_id</code>, they could pass a <code>report_name</code> of <code>../other_team_id/private.</code> This would cause the file <code>/teams/team_id/../other_team_id/private.csv</code> (resolved to <code>/teams/other_team_id/private.csv</code>) to be read, leaking data from a different team.</p> <p>To avoid path traversal vulnerabilities, <strong>never use untrusted input in file or directory names</strong>. It's safest always to control the names of files and directories, including IDs that you generate and control (e.g., UUIDs, KSUIDs, etc.). If the name of a file or directory absolutely <em>must</em> be derived from untrusted input, consider hashing it (e.g., using SHA-256) or at least encoding it into a format that doesn't include dots or slashes (e.g., <a href="https://datatracker.ietf.org/doc/html/rfc4648#section-5">URL-safe base64</a>).</p> <p>​</p> <p>Know of good Node.js libraries for avoiding injection vulnerabilities? Let folks know in the comments!</p> </div><!-- SC_ON -->

  • Is it harder to build and maintain web applications using vanilla js or react?
    1 project | /r/Frontend | 2 May 2023
    https://stackoverflow.com/questions/43584685/input-sanitization-in-reactjs https://www.npmjs.com/package/dompurify
  • Six security risk of user input in ruby code
    2 projects | dev.to | 11 Apr 2023
    If you're using an external view engine, or a javascript framework like react in addition to your ruby backend, you can rely on similar sanitization methods like the DOMPurify library.
  • Wat
    5 projects | news.ycombinator.com | 29 Mar 2023
    You shouldn't roll your own for this. From what I've had to do web-wise, here's a few tools.

    First, for the APIs, you need documentation: https://swagger.io/

    From which you can generate JSON schemas and use those to validate in the browser and on the backend. https://www.npmjs.com/package/jsonschema

    As well you should be writing a few more schemas for your application state and leverage the regex validation of your input components...

    Speaking of which, you also need to sanitize out some potentially nasty input. https://www.npmjs.com/package/dompurify

    Obviously this isn't everything and not perfect, but a lot of this tedium can be automated away if you have a few good examples of the happy path and some basic tests in place to prevent quick and dirty changes from poking holes in these layers.

remark

Posts with mentions or reviews of remark. We have used some of these posts to build our list of alternatives and similar projects. The last one was on 2023-12-11.
  • Which software do you use to create presentations using Vim that is superior to existing ones?
    10 projects | /r/neovim | 11 Dec 2023
    I also didn't try this tool but it's called RemarkJS which is named too similar to revealjs.
  • How We Started Managing BSA Delivery Processes on GitHub
    6 projects | dev.to | 26 Nov 2023
    remark. Primarily, this is a linter for Markdown. Additionally, thanks to its numerous plugins, it allows us to perform additional checks for grammatical mistakes within the content itself. Before using this linter, our content was not scrutinized to this extent.
  • I built an Markdown editor using Next.js and TailwindCss 🔥
    5 projects | dev.to | 14 Nov 2023
    Rehype and Remark are plugins used to transform and manipulate the HTML and Markdown content of a website, helping to enhance its functionality and appearance.
  • how to retain position of markdown element in remark.js
    3 projects | dev.to | 4 Sep 2023
    I usually combine remark-parse, remark-rehype and rehype-react to transform markdown into react components. The configuration of the processor is like:
  • Building an Astro Blog with View Transitions
    5 projects | dev.to | 24 Aug 2023
    Astro content collection are as simple as a folder containing a bunch of Markdown (or Markdoc or MDX) files if that's the only thing you need, but they can also do relationship matching between different collections, frontmatter validation using zod and you can also customize how the markdown is parsed and translated to html using rehype and remark and their plugin ecosystem.
  • Simple markdown plugin to open external links in a new tab
    2 projects | dev.to | 4 Jun 2023
    On my personal blog I have few external links in my posts. I wanted to keep people on my website by applying target="_blank" on external (those what don't reference to my site) links. This is a common and good practice too. I write my content in Markdown, so I decided to write a remark plugin. It is simple to implement, just few lines of code.
  • Create an Interactive Table of Contents for a Next.js Blog with Remark
    5 projects | dev.to | 21 Apr 2023
    Although we are building a custom table of contents, we won't have to write everything from scratch. To separate the Markdown/MDX content from the front matter, we'll use the Gray-matter package. It is optional in case you don't have front matter in your Markdown files. To process the Markdown itself, we'll use the Remark package. We'll also need the unist-util-visit package for traversing node trees and mdast-util-to-string for getting the text content of a node.
  • How to integrate your blog with dev.to API Next.js 13
    5 projects | dev.to | 16 Feb 2023
    That's all to render the post as HTML, there are lots of things you can do to customize the results, you can check the remark plugins and rehype plugins to pass as props to and you can also take a look at some other bloggers if you're looking for different styles for example Lee Robinson's or if you liked mine.
  • Contentlayer with next/image
    11 projects | dev.to | 4 Jan 2023
    contentlayer uses remark to parse the markdown in an mdast. We can now use remark plugins to modify the mdast. Then rehype comes into play and converts the mdast into a hast. rehype plugins can now modify the hast. Finally the hast is converted into react components.
  • Serving Docusaurus images with Cloudinary
    3 projects | dev.to | 25 Dec 2022
    Now we have our Cloudinary account set up, we can use it with Docusaurus. To do so, we need to create a remark plugin. This is a plugin for the remark markdown processor. It's a plugin that will transform the markdown image syntax into a Cloudinary URL.

What are some alternatives?

When comparing DOMPurify and remark you can also consider the following projects:

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

marked - A markdown parser and compiler. Built for speed.

js-xss - Sanitize untrusted HTML (to prevent XSS) with a configuration specified by a Whitelist

markdown-it - Markdown parser, done right. 100% CommonMark support, extensions, syntax plugins & high speed

HtmlSanitizer - Cleans HTML to avoid XSS attacks

rehype - HTML processor powered by plugins part of the @unifiedjs collective

xss-filters

react-markdown - Markdown component for React

Next.js - The React Framework

gray-matter - Smarter YAML front matter parser, used by metalsmith, Gatsby, Netlify, Assemble, mapbox-gl, phenomic, vuejs vitepress, TinaCMS, Shopify Polaris, Ant Design, Astro, hashicorp, garden, slidev, saber, sourcegraph, and many others. Simple to use, and battle tested. Parses YAML by default but can also parse JSON Front Matter, Coffee Front Matter, TOML Front Matter, and has support for custom parsers. Please follow gray-matter's author: https://github.com/jonschlinkert

isomorphic-dompurify - Use DOMPurify on server and client in the same way

micromark - small, safe, and great commonmark (optionally gfm) compliant markdown parser