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

Added rehypeSanitize to improve preview xss issues #323

Merged
merged 3 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"rehype-external-links": "^3.0.0",
"rehype-katex": "^7.0.1",
"rehype-rewrite": "^4.0.2",
"rehype-sanitize": "^6.0.0",
"remark-math": "^6.0.0",
"vite-plugin-package-version": "^1.1.0",
"yorkie-js-sdk": "^0.4.31"
Expand Down
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" }],
]}
devleejb marked this conversation as resolved.
Show resolved Hide resolved
components={{
code: ({ children = [], className, ...props }) => {
// https://www.npmjs.com/package/@uiw/react-markdown-preview#support-custom-katex-preview
Expand Down