appsmithorg / appsmith

Platform to build admin panels, internal tools, and dashboards. Integrates with 25+ databases and any API.
https://www.appsmith.com
Apache License 2.0
34.42k stars 3.72k forks source link

[Bug]: workspace settings, upload logo API fails when uploading .svg file #34329

Open somangshu opened 4 months ago

somangshu commented 4 months ago

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

  1. go to workspace settings
  2. upload svg logo
  3. see the network error.

Public Sample App

No response

Environment

Production

Severity

Medium (Frustrating UX)

Issue video log

No response

Version

Cloud

raushan3737 commented 4 months ago

Hi @somangshu , @Nikhil-Nandagopal i would like to work on this ticket. Can i pick this issue.

Nikhil-Nandagopal commented 4 months ago

@raushan3737 sure you can give it a try

raushan3737 commented 4 months ago

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

  1. Identify Controllers and Services.

  2. Validate Image Formats:

    • Ensure the application correctly identifies and processes supported image formats (JPEG, PNG, ICO, SVG).
    • Special attention should be given to SVG files due to their potential to contain malicious code.
  3. SVG Validation and Sanitization:

    • Use a library for sanitizing SVG content to ensure it does not contain malicious HTML/JavaScript.
    • Consider using OWASP Java HTML Sanitizer , which provides configurable policies to specify allowable content within SVG files & ensure removal of any malicious content in sanitization process. Also, this library is maintain by OWASP team which is the more reputed organization who define & follow the security policy in cyber domain so, we can go with this as we can get future updates also from them.

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): image

Backend Code Snippet: Screenshot from 2024-07-09 12-43-43 Screenshot from 2024-07-09 12-44-42 Screenshot from 2024-07-09 12-45-28 Screenshot from 2024-07-09 12-47-16

raushan3737 commented 3 months ago

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:

Snapshot:

Method to validate the svg: image

image