Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

fix: update markdown service to avoid malicious redirects (#774)

Mohamed ELBARCHANY6ad67ff65073
diff --git a/public/services/markdown.spec.ts b/public/services/markdown.spec.ts
index bab7d10ff..04085d2fc 100644
--- a/public/services/markdown.spec.ts
+++ b/public/services/markdown.spec.ts
@@ -3,8 +3,8 @@ import * as markdown from "./markdown";
const testCases = [
{
input: "Visit [GitHub](https://github.com) to learn more.",
- expectedFull: '<p>Visit <a target="_blank" href="https://github.com">GitHub</a> to learn more.</p>',
- expectedSimple: '<p>Visit <a target="_blank" href="https://github.com">GitHub</a> to learn more.</p>'
+ expectedFull: '<p>Visit <a target="_blank" rel="noopener" href="https://github.com">GitHub</a> to learn more.</p>',
+ expectedSimple: '<p>Visit <a target="_blank" rel="noopener" href="https://github.com">GitHub</a> to learn more.</p>'
},
{
input: "My Picture ![](http://demo.dev.fider.io:3000/images/100/28)",
diff --git a/public/services/markdown.ts b/public/services/markdown.ts
index 3982e88f9..77745b9ee 100644
--- a/public/services/markdown.ts
+++ b/public/services/markdown.ts
@@ -15,7 +15,7 @@ DOMPurify.setConfig({
const link = (href: string, title: string, text: string) => {
const titleAttr = title ? ` title=${title}` : "";
- return `<a href="${href}"${titleAttr} target="_blank">${text}</a>`;
+ return `<a href="${href}"${titleAttr} rel="noopener" target="_blank">${text}</a>`;
};
const simpleRenderer = new marked.Renderer();