Skip to content

Commit

Permalink
chore: fix XSS in renderer (#875)
Browse files Browse the repository at this point in the history
chore: fix xss in renderer
  • Loading branch information
boojack committed Dec 29, 2022
1 parent 9169b3f commit 64e5c34
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 11 deletions.
2 changes: 1 addition & 1 deletion web/src/labs/marked/index.ts
Expand Up @@ -47,7 +47,7 @@ export const marked = (markdownStr: string, blockParsers = blockElementParserLis
const matchedLength = matchedStr.length;
const prefixStr = markdownStr.slice(0, matchedIndex);
const suffixStr = markdownStr.slice(matchedIndex + matchedLength);
return prefixStr + matchedInlineParser.renderer(matchedStr) + marked(suffixStr, [], inlineParsers);
return marked(prefixStr, [], inlineParsers) + matchedInlineParser.renderer(matchedStr) + marked(suffixStr, [], inlineParsers);
}
}

Expand Down
3 changes: 1 addition & 2 deletions web/src/labs/marked/parser/Bold.ts
@@ -1,4 +1,3 @@
import { escape } from "lodash";
import { marked } from "..";
import Link from "./Link";

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

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

Expand Down
3 changes: 1 addition & 2 deletions web/src/labs/marked/parser/BoldEmphasis.ts
@@ -1,4 +1,3 @@
import { escape } from "lodash";
import { marked } from "..";
import Link from "./Link";

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

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

Expand Down
3 changes: 1 addition & 2 deletions web/src/labs/marked/parser/Emphasis.ts
@@ -1,4 +1,3 @@
import { escape } from "lodash";
import { marked } from "..";
import Link from "./Link";

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

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

Expand Down
2 changes: 1 addition & 1 deletion web/src/labs/marked/parser/Link.ts
Expand Up @@ -17,7 +17,7 @@ const renderer = (rawStr: string): string => {
if (!matchResult) {
return rawStr;
}
const parsedContent = marked(escape(matchResult[1]), [], [InlineCode, BoldEmphasis, Emphasis, Bold]);
const parsedContent = marked(matchResult[1], [], [InlineCode, BoldEmphasis, Emphasis, Bold]);
return `<a class='link' target='_blank' rel='noreferrer' href='${escape(matchResult[2])}'>${parsedContent}</a>`;
};

Expand Down
5 changes: 2 additions & 3 deletions web/src/labs/marked/parser/Strikethrough.ts
@@ -1,4 +1,4 @@
import { marked } from "..";
import { escape } from "lodash";

export const STRIKETHROUGH_REG = /~~(.+?)~~/;

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

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

export default {
Expand Down

0 comments on commit 64e5c34

Please sign in to comment.