Open somangshu opened 4 months ago
Hi @somangshu , @Nikhil-Nandagopal i would like to work on this ticket. Can i pick this issue.
@raushan3737 sure you can give it a try
Hi @Nikhil-Nandagopal , @somangshu ,
In order to fix the bug, We have to ensure secure handling of SVG files in the application, we need a comprehensive approach to validate and sanitize SVG content to prevent any cyber attack like(Malicious code injection,Phishing etc).
Below are the approaches and detailed steps to achieve this:
Approach 1: Regex Testing for Malicious Content Pros: Simple implementation. Cons: May miss edge cases, leaving potential vulnerabilities as it will not be possible to check all the scenario to prevent malicious script. Also, there will be a chance to get the wrongly formatted svg during sanitization using regex which might not be svg to render.
Approach 2: Comprehensive Validation and Sanitization
Identify Controllers and Services.
Validate Image Formats:
SVG Validation and Sanitization:
I feel second approach is more secure way to fix this bug, Should we proceed with approach 2 to use external library for sanitization?
Validation logic file: URL
Sanitization Method(Thinking to use like this):
Backend Code Snippet:
Hi @Nikhil-Nandagopal , @somangshu ,
While going through above approaches and testing them with multiple svg i found the below observations:
In Approach 2:
In Approach 1:
Instead of doing the sanitization we can just validate the svg if it passes the validation criteria we will allow that to upload on the server, else we can throw the AppsmithValidationException as please provide the valid svg file.
By this, we are not allowing user to upload malicious svg also, this implementation will not have much complexity as we are validating through regex pattern.
Snapshot:
Method to validate the svg:
Is there an existing issue for this?
Description
backend API
logo
returns the error (400). The validation error is returned by the API it self with the message that the file format can only be.svg... etc
despite the file extension being.svg
Steps To Reproduce
Public Sample App
No response
Environment
Production
Severity
Medium (Frustrating UX)
Issue video log
No response
Version
Cloud