-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SAH-77]: Supplier Inventory Page #167
Conversation
{newImages.map((image, index) => ( | ||
<div key={`new-${index}`} className="relative group"> | ||
<img | ||
src={URL.createObjectURL(image)} |
Check warning
Code scanning / CodeQL
DOM text reinterpreted as HTML Medium
DOM text
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 2 months ago
To fix the problem, we need to ensure that the uploaded image files are properly validated and sanitized before being used. One way to achieve this is by checking the file type and size before creating the object URL. Additionally, we can use a library like DOMPurify
to sanitize any potentially unsafe content.
- Validate the file type and size before creating the object URL.
- Use
DOMPurify
to sanitize the object URL before using it as thesrc
attribute of theimg
element. - Update the
handleImageUpload
function to include these validations and sanitizations.
-
Copy modified line R7 -
Copy modified lines R55-R60 -
Copy modified line R172
@@ -6,2 +6,3 @@ | ||
import { HiMinus, HiPlus } from 'react-icons/hi2'; | ||
import DOMPurify from 'dompurify'; | ||
|
||
@@ -53,3 +54,8 @@ | ||
const filesArray = Array.from(e.target.files); | ||
setNewImages((prevImages) => [...prevImages, ...filesArray]); | ||
const validFiles = filesArray.filter(file => { | ||
const isValidType = file.type.startsWith('image/'); | ||
const isValidSize = file.size <= 5 * 1024 * 1024; // 5MB limit | ||
return isValidType && isValidSize; | ||
}); | ||
setNewImages((prevImages) => [...prevImages, ...validFiles]); | ||
} | ||
@@ -165,3 +171,3 @@ | ||
<img | ||
src={URL.createObjectURL(image)} | ||
src={DOMPurify.sanitize(URL.createObjectURL(image))} | ||
alt={`New product image ${index + 1}`} |
-
Copy modified lines R9-R10
@@ -8,3 +8,4 @@ | ||
"@sahil/configs": "*", | ||
"ui": "*" | ||
"ui": "*", | ||
"dompurify": "^3.2.0" | ||
} |
Package | Version | Security advisories |
dompurify (npm) | 3.2.0 | None |
No description provided.