Skip to content

Commit

Permalink
Added rehypeSanitize to improve preview xss issues
Browse files Browse the repository at this point in the history
Added rehypeSanitize to handle dangerous markdown
Added options for rehypeKatex to ensure formula marking
  • Loading branch information
taeng0204 committed Aug 28, 2024
1 parent 995e4d0 commit 3b4084a
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion frontend/src/components/editor/Preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useEffect, useState } from "react";
import { useSelector } from "react-redux";
import rehypeExternalLinks from "rehype-external-links";
import rehypeKatex from "rehype-katex";
import rehypeSanitize, { defaultSchema } from "rehype-sanitize";
import { getCodeString } from "rehype-rewrite";
import remarkMath from "remark-math";
import { useCurrentTheme } from "../../hooks/useCurrentTheme";
Expand Down Expand Up @@ -57,7 +58,20 @@ function Preview() {
},
}}
remarkPlugins={[remarkMath]}
rehypePlugins={[rehypeKatex, [rehypeExternalLinks, { target: "_blank" }]]}
rehypePlugins={[
[
rehypeSanitize,
{
...defaultSchema,
attributes: {
...defaultSchema.attributes,
code: [["className", /^language-./, "math-inline", "math-display"]],
},
},
],
rehypeKatex,
[rehypeExternalLinks, { target: "_blank" }],
]}
components={{
code: ({ children = [], className, ...props }) => {
// https://www.npmjs.com/package/@uiw/react-markdown-preview#support-custom-katex-preview
Expand Down

0 comments on commit 3b4084a

Please sign in to comment.