From b3fff43542727c035f42f0ec7d2d72b13898108c Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Tue, 22 Oct 2024 19:13:54 -0700 Subject: [PATCH] Sanitize user attached images. Constrain chat input width on home page Set max combined images size to 20mb to allow multiple photos to be shared --- .../web/app/components/chatMessage/chatMessage.tsx | 11 +++++++---- src/interface/web/app/page.tsx | 2 +- src/khoj/routers/api_chat.py | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/interface/web/app/components/chatMessage/chatMessage.tsx b/src/interface/web/app/components/chatMessage/chatMessage.tsx index a725bdaa..77eaf64a 100644 --- a/src/interface/web/app/components/chatMessage/chatMessage.tsx +++ b/src/interface/web/app/components/chatMessage/chatMessage.tsx @@ -343,10 +343,13 @@ const ChatMessage = forwardRef((props, ref) => if (props.chatMessage.images && props.chatMessage.images.length > 0) { const imagesInMd = props.chatMessage.images - .map( - (image, index) => - `
uploaded image ${index + 1}
`, - ) + .map((image, index) => { + const decodedImage = image.startsWith("data%3Aimage") + ? decodeURIComponent(image) + : image; + const sanitizedImage = DOMPurify.sanitize(decodedImage); + return `
uploaded image ${index + 1}
`; + }) .join(""); message = `
${imagesInMd}
${message}`; } diff --git a/src/interface/web/app/page.tsx b/src/interface/web/app/page.tsx index 4bc97bf1..432787e0 100644 --- a/src/interface/web/app/page.tsx +++ b/src/interface/web/app/page.tsx @@ -225,7 +225,7 @@ function ChatBodyData(props: ChatBodyDataProps) { )} -
+
{!props.isMobileWidth && (