Skip to content

Commit

Permalink
Potential fix for code scanning alert no. 116: DOM text reinterpreted…
Browse files Browse the repository at this point in the history
… as HTML (ohcnetwork#10754)
  • Loading branch information
rithviknishad authored and ashwinpraveengo committed Feb 26, 2025
1 parent 22ca3e7 commit 9b9cc77
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/components/Common/AvatarEditModal.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import DOMPurify from "dompurify";
import React, {
ChangeEventHandler,
useCallback,
Expand Down Expand Up @@ -135,11 +136,12 @@ const AvatarEditModal = ({
setSelectedFile(undefined);
return;
}
if (!isImageFile(e.target.files[0])) {
const file = e.target.files[0];
if (!isImageFile(file)) {
toast.warning(t("please_upload_an_image_file"));
return;
}
setSelectedFile(e.target.files[0]);
setSelectedFile(file);
};

const uploadAvatar = async () => {
Expand Down Expand Up @@ -231,7 +233,11 @@ const AvatarEditModal = ({
<>
<div className="flex flex-1 items-center justify-center rounded-lg">
<img
src={preview || imageUrl}
src={
preview && preview.startsWith("blob:")
? DOMPurify.sanitize(preview)
: imageUrl
}
alt="cover-photo"
className="h-full w-full object-cover"
/>
Expand Down

0 comments on commit 9b9cc77

Please sign in to comment.