chore: fix XSS in renderer (#875)

chore: fix xss in renderer
pull/876/head
boojack 2 years ago committed by GitHub
parent 9169b3f2cd
commit 64e5c343c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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);
}
}

@ -1,4 +1,3 @@
import { escape } from "lodash";
import { marked } from "..";
import Link from "./Link";
@ -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>`;
};

@ -1,4 +1,3 @@
import { escape } from "lodash";
import { marked } from "..";
import Link from "./Link";
@ -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>`;
};

@ -1,4 +1,3 @@
import { escape } from "lodash";
import { marked } from "..";
import Link from "./Link";
@ -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>`;
};

@ -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>`;
};

@ -1,4 +1,4 @@
import { marked } from "..";
import { escape } from "lodash";
export const STRIKETHROUGH_REG = /~~(.+?)~~/;
@ -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 {

Loading…
Cancel
Save