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

rehype pluguns doesn't affected (XSS Vulnerable) #574

Open
fuaditrockz opened this issue Sep 28, 2023 · 1 comment
Open

rehype pluguns doesn't affected (XSS Vulnerable) #574

fuaditrockz opened this issue Sep 28, 2023 · 1 comment

Comments

@fuaditrockz
Copy link

fuaditrockz commented Sep 28, 2023

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.

@isimmons
Copy link

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

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

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

2 participants