Skip to content
Merged
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
2 changes: 1 addition & 1 deletion mosu-app/src/entities/posts/ui/MarkDown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const MarkDownRenderer = ({ content, ...props }: MarkDownRendererProps) =
return (
<article
{...props}
className={cn(props.className, "prose max-w-none [&>h1]:my-1")}
className={cn(props.className, "prose max-w-none [&>h1]:my-1 [&_p]:whitespace-pre-line")}
dangerouslySetInnerHTML={{ __html: content }}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Sanitize HTML before injection to prevent XSS.

dangerouslySetInnerHTML is high risk if content can include user input. Sanitize on the client (or ensure it’s sanitized server-side) to block script/style injection.

Apply this minimal change here:

-            dangerouslySetInnerHTML={{ __html: content }}
+            dangerouslySetInnerHTML={{ __html: sanitized }}

And add the supporting code (outside this hunk):

// imports
import { useMemo } from "react";
import DOMPurify from "isomorphic-dompurify";

// inside component
const sanitized = useMemo(
  () =>
    DOMPurify.sanitize(content, {
      USE_PROFILES: { html: true }, // safe default; adjust allowlist if needed
    }),
  [content]
);
🧰 Tools
🪛 Biome (2.1.2)

[error] 12-12: Avoid passing content using the dangerouslySetInnerHTML prop.

Setting content using code can expose users to cross-site scripting (XSS) attacks

(lint/security/noDangerouslySetInnerHtml)

🤖 Prompt for AI Agents
In mosu-app/src/entities/posts/ui/MarkDown.tsx around line 12, the component is
injecting raw HTML via dangerouslySetInnerHTML using content; sanitize content
first to prevent XSS by importing useMemo and DOMPurify (isomorphic-dompurify),
creating a memoized sanitized variable via DOMPurify.sanitize(content, {
USE_PROFILES: { html: true } }) with [content] as the dependency, and then pass
sanitized to dangerouslySetInnerHTML instead of raw content; also ensure
isomorphic-dompurify is added to package dependencies.

/>
);
Expand Down