Sanitize user attached image in chat message input pane of web app

This commit is contained in:
Debanjum Singh Solanky
2024-09-11 17:50:58 -07:00
parent de60ad7da6
commit b61d825cbc

View File

@@ -1,9 +1,7 @@
import styles from "./chatInputArea.module.css"; import styles from "./chatInputArea.module.css";
import React, { useEffect, useRef, useState } from "react"; import React, { useEffect, useRef, useState } from "react";
import { uploadDataForIndexing } from "../../common/chatFunctions"; import DOMPurify from "dompurify";
import { Progress } from "@/components/ui/progress";
import "katex/dist/katex.min.css"; import "katex/dist/katex.min.css";
import { import {
ArrowRight, ArrowRight,
@@ -33,8 +31,6 @@ import {
CommandSeparator, CommandSeparator,
} from "@/components/ui/command"; } from "@/components/ui/command";
import { Textarea } from "@/components/ui/textarea";
import { Button } from "@/components/ui/button";
import { import {
AlertDialog, AlertDialog,
AlertDialogAction, AlertDialogAction,
@@ -43,13 +39,18 @@ import {
AlertDialogHeader, AlertDialogHeader,
AlertDialogTitle, AlertDialogTitle,
} from "@/components/ui/alert-dialog"; } from "@/components/ui/alert-dialog";
import { Button } from "@/components/ui/button";
import { Progress } from "@/components/ui/progress";
import { Popover, PopoverContent } from "@/components/ui/popover"; import { Popover, PopoverContent } from "@/components/ui/popover";
import { PopoverTrigger } from "@radix-ui/react-popover"; import { PopoverTrigger } from "@radix-ui/react-popover";
import LoginPrompt from "../loginPrompt/loginPrompt"; import { Textarea } from "@/components/ui/textarea";
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip"; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";
import { InlineLoading } from "../loading/loading";
import { convertToBGClass } from "@/app/common/colorUtils"; import { convertToBGClass } from "@/app/common/colorUtils";
import LoginPrompt from "../loginPrompt/loginPrompt";
import { uploadDataForIndexing } from "../../common/chatFunctions";
import { InlineLoading } from "../loading/loading";
export interface ChatOptions { export interface ChatOptions {
[key: string]: string; [key: string]: string;
} }
@@ -177,7 +178,7 @@ export default function ChatInputArea(props: ChatInputProps) {
const file_extension = file.name.split(".").pop(); const file_extension = file.name.split(".").pop();
if (image_endings.includes(file_extension || "")) { if (image_endings.includes(file_extension || "")) {
setImageUploaded(true); setImageUploaded(true);
setImagePath(URL.createObjectURL(file)); setImagePath(DOMPurify.sanitize(URL.createObjectURL(file)));
return; return;
} }
} }