react-md-editor icon indicating copy to clipboard operation
react-md-editor copied to clipboard

rehype pluguns doesn't affected (XSS Vulnerable)

Open fuaditrockz opened this issue 9 months ago • 1 comments

I try to implement this into my next js project using app next js version.

And I wanna try to test the security using this inside the string markdown;

<IFRAME SRC="javascript:javascript:alert(window.origin);"></IFRAME>

And this is my code.

import "@uiw/react-md-editor/markdown-editor.css";
import "@uiw/react-markdown-preview/markdown.css";
import { useState } from "react";
import MDEditor from "@uiw/react-md-editor";
import rehypeSanitize from "rehype-sanitize";

const PostEditor = () => {
  const [value, setValue] = useState<string | undefined>(
    '**Hello world!!!** <IFRAME SRC="javascript:javascript:alert(window.origin);"></IFRAME>'
  );

  return (
    <div className="container">
      <MDEditor
        value={value}
        onChange={setValue}
        previewOptions={{
          rehypePlugins: [rehypeSanitize],
          transformLinkUri: null,
          skipHtml: true,
        }}
      />
      <MDEditor.Markdown source={value} style={{ whiteSpace: "pre-wrap" }} />
    </div>
  );
};

export default PostEditor;

And then javascript dialog still up there. Screenshot 2023-09-28 at 20 17 32 How to avoid that dialog appear to our website, especially during production.

fuaditrockz avatar Sep 28 '23 13:09 fuaditrockz

Those are two different components. The separate viewer needs it's own rehypeSanitize. This should work.

<MDEditor.Markdown
        source={value}
        rehypePlugins={[rehypeSanitize]}
      />

isimmons avatar Oct 27 '23 10:10 isimmons