From 3c6f3f08e1dc106c9dd6e136afe51c7ed8b2ee07 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Tue, 4 Feb 2025 15:25:35 -0800 Subject: [PATCH] Add base64 verification, retrun null if not shouldRender --- Client/src/Components/Image/index.jsx | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Client/src/Components/Image/index.jsx b/Client/src/Components/Image/index.jsx index 98d8b7707..778675f92 100644 --- a/Client/src/Components/Image/index.jsx +++ b/Client/src/Components/Image/index.jsx @@ -1,14 +1,32 @@ import { Box } from "@mui/material"; import PropTypes from "prop-types"; +const isValidBase64Image = (data) => { + return /^[A-Za-z0-9+/=]+$/.test(data); +}; + const Image = ({ + shouldRender = true, src, alt, width = "auto", height = "auto", maxWidth = "auto", maxHeight = "auto", + base64, }) => { + if (shouldRender === false) { + return null; + } + + if (typeof src !== "undefined" && typeof base64 !== "undefined") { + console.warn("base64 takes precedence over src and overwrites it"); + } + + if (typeof base64 !== "undefined" && isValidBase64Image(base64)) { + src = `data:image/png;base64,${base64}`; + } + return (