Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOMPurify.sanitize is not a function #526

Closed
akashgp09 opened this issue Mar 22, 2021 · 10 comments
Closed

DOMPurify.sanitize is not a function #526

akashgp09 opened this issue Mar 22, 2021 · 10 comments

Comments

@akashgp09
Copy link

Background & Context

I am using DOMPurify in my react App

Bug

DOMPurify.sanitize is not a function

Input

import DOMPurify from "dompurify";

const dirty = `I love to do evil <img src="http://unsplash.it/100/100?random" onload="alert('you got hacked');" />`;

const App = () => (
  <div
    dangerouslySetInnerHTML={{
      __html: DOMPurify.sanitize(dirty)
    }}
  />
);

Given output

DOMpurify.sanitize is not a function

Expected output

Should execute well

@cure53
Copy link
Owner

cure53 commented Mar 23, 2021

Not our bug, me thinks.

@cure53 cure53 closed this as completed Mar 23, 2021
@binyamin
Copy link

@cure53 same problem here. Do you have any idea who's bug it is?

@binyamin
Copy link

Ah, maybe it needs jsdom? The readme doesn't seem to say that in node.js, you need jsdom to work

@Fensterbank
Copy link

I had this issue with NextJS on server-side rendering.
To make this work server-side and client-side the same way, you can use the wrapper https://github.com/kkomelin/isomorphic-dompurify

@cyocun
Copy link

cyocun commented Feb 18, 2023

I was into the same problem.

the solution is
import * as DOMPurify from 'dompurify';
⭕️ import DOMPurify from 'dompurify';

@duoluodexiaoxiaoyuan
Copy link

duoluodexiaoxiaoyuan commented Feb 21, 2023

Background & Context

I am using DOMPurify in my react App

Bug

DOMPurify.sanitize is not a function

Input

import DOMPurify from "dompurify";

const dirty = `I love to do evil <img src="http://unsplash.it/100/100?random" onload="alert('you got hacked');" />`;

const App = () => (
  <div
    dangerouslySetInnerHTML={{
      __html: DOMPurify.sanitize(dirty)
    }}
  />
);

Given output

DOMpurify.sanitize is not a function

Expected output

Should execute well

i find a answer, this is a demo https://codesandbox.io/s/ei98d?file=/src/App.tsx

@bonface221
Copy link

🤔

@mtoha2013
Copy link

I have similar issue, how to achieve this at pure javascript no framework like react?
I run it on .NET MVC app

@Bunpasi
Copy link

Bunpasi commented May 3, 2024

I had the same problem. Check DOMPurify.isSupported. For me it wasn't supported, because my application didn't have a global window object.

@MortenHofft
Copy link
Contributor

What threw me off is this example from the docs

import * as DOMPurify from 'dompurify';
const clean = DOMPurify.sanitize('<b>hello there</b>');

which doesn't work, but this does

import DOMPurify from 'dompurify';
const clean = DOMPurify.sanitize('<b>hello there</b>');

MortenHofft added a commit to MortenHofft/DOMPurify that referenced this issue May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants