-
-
Notifications
You must be signed in to change notification settings - Fork 749
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
Created an isomorphic wrapper for DOMPurify #400
Comments
Haha, this is cool, thanks for pointing this out :D |
@cure53 You're welcome. |
For usage of DOMPurify in Next.js Server Components without the wrapper package
Mainly the code is this: import DOMPurify from "dompurify";
import { JSDOM } from "jsdom";
export default function Home() {
return (
<div
dangerouslySetInnerHTML={{
__html: DOMPurify(new JSDOM("<!DOCTYPE html>").window).sanitize(
"<img src=x onerror=alert(1)//>"
),
}}
/>
);
} There is also some needed webpack configuration to fix the issues with bundling @cure53 maybe this recipe above would be good to add to the readme for Node.js and Next.js users? I was looking for an example of how to use it with Node.js and ended up looking at the source of |
@karlhorky Thanks. If the webpack configuration is adjusted for better bundling of jsdom/canvas as you suggested, will |
No, I personally think I think this because:
If the wrapper can be done with a few lines of code in a project, I think the wrapper package should not exist. Alternative: it could be absorbed into the DOMPurify repo itself (eg. as a separate import path |
@karlhorky Thank you for your opinion. I can't agree with it but I respect it.
|
Indeed, small packages + unavailable maintainers are not normally a problem - the community heals - but |
Makes sense. If you help |
Hey guys,
The issue is not typical, so excuse me for not following the issue template.
I don't have proper words to thank you for your work on the library. It's probably one of the most important projects in the JS ecosystem, even if some people don't know about it yet.
While working with DOMPurify in Next.js (with and without SSR), I noticed that it needs some additional initialization logic for server-side code (sort of a fake DOM tree). To simplify the initialization and make it universal on both frontend and backend, I've created an isomorphic wrapper https://github.com/kkomelin/isomorphic-dompurify
I would appreciate your feedback on the project and it would be an honor for me if it could give ideas on how to make DOMPurify itself even better.
Thanks,
Konstantin
The text was updated successfully, but these errors were encountered: