-
I'd like for my users to be able to be able to write content in MDX, and I'm curious about how crazy I am. For example, I want my users to make a blog post where they can type in markdown but also embed React components. So letting them write in MDX seems awesome. However, I don't know how practical and safe this would be.
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Reframing the question: “Letting users write in JavaScript?” might help you figure it out. In short: no, it’s not safe, it’s dangerous. There are of course places online where you can write code, e.g., runkit, codesandbox, which is evaluated in a sandbox. You could do something like that. |
Beta Was this translation helpful? Give feedback.
-
You can use safe-mdx or hast-util-to-jsx-runtime to render MDX without eval and make it safe to run the user code in your server (at least if all the components you give the user access to are safe too) |
Beta Was this translation helpful? Give feedback.
Reframing the question: “Letting users write in JavaScript?” might help you figure it out.
In short: no, it’s not safe, it’s dangerous.
There are of course places online where you can write code, e.g., runkit, codesandbox, which is evaluated in a sandbox. You could do something like that.