Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.
Go dockerfossgomarkdownmemomicroblognote-takingnotesopen-sourceown-your-datareactself-hostedsqlitetimeline
chore: add escape to prevent XSS (#833)
boojack65cc19c12efa
diff --git a/web/src/components/SearchBar.tsx b/web/src/components/SearchBar.tsxindex 818fc6190..18bfc3792 100644--- a/web/src/components/SearchBar.tsx+++ b/web/src/components/SearchBar.tsx@@ -38,7 +38,7 @@ const SearchBar = () => {useEffect(() => {const text = locationStore.getState().query.text;setQueryText(text === undefined ? "" : text);- }, [locationStore.getState().query.text]);+ }, [locationStore.state.query.text]);const handleMemoTypeItemClick = (type: MemoSpecType | undefined) => {const { type: prevType } = locationStore.getState().query ?? {};diff --git a/web/src/labs/highlighter/index.ts b/web/src/labs/highlighter/index.tsindex 985f8ac7d..d18e6cb15 100644--- a/web/src/labs/highlighter/index.ts+++ b/web/src/labs/highlighter/index.ts@@ -1,6 +1,4 @@-const escapeRegExp = (str: string): string => {- return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");-};+import { escape } from "lodash";const walkthroughNodeWithKeyword = (node: HTMLElement, keyword: string) => {if (node.nodeType === 3) {@@ -19,8 +17,8 @@ export const highlightWithWord = (html: string, keyword?: string): string => {if (!keyword) {return html;}- keyword = escapeRegExp(keyword);+ keyword = escape(keyword);const wrap = document.createElement("div");- wrap.innerHTML = html;+ wrap.innerHTML = escape(html);return walkthroughNodeWithKeyword(wrap, keyword);};diff --git a/web/src/labs/marked/parser/Bold.ts b/web/src/labs/marked/parser/Bold.tsindex 578a6ed48..041640f21 100644--- a/web/src/labs/marked/parser/Bold.ts+++ b/web/src/labs/marked/parser/Bold.ts@@ -1,3 +1,4 @@+import { escape } from "lodash";import { marked } from "..";import Link from "./Link";@@ -14,7 +15,7 @@ const renderer = (rawStr: string): string => {return rawStr;}- const parsedContent = marked(matchResult[1], [], [Link]);+ const parsedContent = marked(escape(matchResult[1]), [], [Link]);return `<strong>${parsedContent}</strong>`;};diff --git a/web/src/labs/marked/parser/BoldEmphasis.ts b/web/src/labs/marked/parser/BoldEmphasis.tsindex 0fdf37ebb..f434da584 100644--- a/web/src/labs/marked/parser/BoldEmphasis.ts+++ b/web/src/labs/marked/parser/BoldEmphasis.ts@@ -1,3 +1,4 @@+import { escape } from "lodash";import { marked } from "..";import Link from "./Link";@@ -14,7 +15,7 @@ const renderer = (rawStr: string): string => {return rawStr;}- const parsedContent = marked(matchResult[1], [], [Link]);+ const parsedContent = marked(escape(matchResult[1]), [], [Link]);return `<strong><em>${parsedContent}</em></strong>`;};diff --git a/web/src/labs/marked/parser/Emphasis.ts b/web/src/labs/marked/parser/Emphasis.tsindex e339bf3a1..7dd12df1a 100644--- a/web/src/labs/marked/parser/Emphasis.ts+++ b/web/src/labs/marked/parser/Emphasis.ts@@ -1,3 +1,4 @@+import { escape } from "lodash";import { marked } from "..";import Link from "./Link";@@ -14,7 +15,7 @@ const renderer = (rawStr: string): string => {return rawStr;}- const parsedContent = marked(matchResult[1], [], [Link]);+ const parsedContent = marked(escape(matchResult[1]), [], [Link]);return `<em>${parsedContent}</em>`;};diff --git a/web/src/labs/marked/parser/Link.ts b/web/src/labs/marked/parser/Link.tsindex 7b9ac4fc7..6bfc0f8a5 100644--- a/web/src/labs/marked/parser/Link.ts+++ b/web/src/labs/marked/parser/Link.ts@@ -17,7 +17,7 @@ const renderer = (rawStr: string): string => {if (!matchResult) {return rawStr;}- const parsedContent = marked(matchResult[1], [], [InlineCode, BoldEmphasis, Emphasis, Bold]);+ const parsedContent = marked(escape(matchResult[1]), [], [InlineCode, BoldEmphasis, Emphasis, Bold]);return `<a class='link' target='_blank' rel='noreferrer' href='${escape(matchResult[2])}'>${parsedContent}</a>`;};