Skip to content

Commit

Permalink
chore: fix XSS in renderer (#880)
Browse files Browse the repository at this point in the history
  • Loading branch information
boojack committed Dec 31, 2022
1 parent 65e9fde commit 7670c95
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion web/src/labs/marked/parser/Bold.ts
@@ -1,5 +1,6 @@
import { marked } from "..";
import Link from "./Link";
import PlainText from "./PlainText";

export const BOLD_REG = /\*\*(.+?)\*\*/;

Expand All @@ -14,7 +15,7 @@ const renderer = (rawStr: string): string => {
return rawStr;
}

const parsedContent = marked(matchResult[1], [], [Link]);
const parsedContent = marked(matchResult[1], [], [Link, PlainText]);
return `<strong>${parsedContent}</strong>`;
};

Expand Down
3 changes: 2 additions & 1 deletion web/src/labs/marked/parser/BoldEmphasis.ts
@@ -1,5 +1,6 @@
import { marked } from "..";
import Link from "./Link";
import PlainText from "./PlainText";

export const BOLD_EMPHASIS_REG = /\*\*\*(.+?)\*\*\*/;

Expand All @@ -14,7 +15,7 @@ const renderer = (rawStr: string): string => {
return rawStr;
}

const parsedContent = marked(matchResult[1], [], [Link]);
const parsedContent = marked(matchResult[1], [], [Link, PlainText]);
return `<strong><em>${parsedContent}</em></strong>`;
};

Expand Down
3 changes: 2 additions & 1 deletion web/src/labs/marked/parser/Emphasis.ts
@@ -1,5 +1,6 @@
import { marked } from "..";
import Link from "./Link";
import PlainText from "./PlainText";

export const EMPHASIS_REG = /\*(.+?)\*/;

Expand All @@ -14,7 +15,7 @@ const renderer = (rawStr: string): string => {
return rawStr;
}

const parsedContent = marked(matchResult[1], [], [Link]);
const parsedContent = marked(matchResult[1], [], [Link, PlainText]);
return `<em>${parsedContent}</em>`;
};

Expand Down
3 changes: 2 additions & 1 deletion web/src/labs/marked/parser/Link.ts
Expand Up @@ -4,6 +4,7 @@ import Bold from "./Bold";
import { marked } from "..";
import InlineCode from "./InlineCode";
import BoldEmphasis from "./BoldEmphasis";
import PlainText from "./PlainText";

export const LINK_REG = /\[(.*?)\]\((.+?)\)+/;

Expand All @@ -17,7 +18,7 @@ const renderer = (rawStr: string): string => {
if (!matchResult) {
return rawStr;
}
const parsedContent = marked(matchResult[1], [], [InlineCode, BoldEmphasis, Emphasis, Bold]);
const parsedContent = marked(matchResult[1], [], [InlineCode, BoldEmphasis, Emphasis, Bold, PlainText]);
return `<a class='link' target='_blank' rel='noreferrer' href='${escape(matchResult[2])}'>${parsedContent}</a>`;
};

Expand Down

0 comments on commit 7670c95

Please sign in to comment.