We are developing an MVC web-application in Django and having concerns about image uploading.

First of all, here are our business requirements:

  • Our users can upload images (like profile pictures, etc).

  • Only authenticated users can upload images.

  • Image uploading is done through HTML-form using POST method.

  • Users can upload multiple images at once.

  • The only allowed image formats are PNG and JPEG.

We decided that the uploaded images have to be converted from PNG/JPEG into WebP and then into Base64. They will be stored in the database as Base64 text and then injected into HTML template via the <IMG> tag:

<img src='data:image/webp;base64,...' />

We are having concerns about security of this scheme. Are there any attack vectors that are specific to this scheme of embedding Base64-encoded images in HTML?

  • Well your website will be using a lot more data to transfer and store the images, which might make it easier to exhaust resources in a DoS attack.
    – user
    May 17, 2022 at 12:43

1 Answer 1


From what you tell us, the most likely path of attack on your application is at the conversion from PNG/JPEG to WebP step.

If there is a vulnerability in whatever you use to do the conversion (which will most likely use libjpeg and libpng, which have an history of vulnerabilities), this is where the attacker can act and get a remote code execution on your server.

So the conversion step should ideally be sandboxed to lower the risk associated with that step, and then its output should be checked to be a conforming WebP image.

The base64 conversion and embedding is the least concerning (from a security PoV, likely not the best from a performance PoV, no pipelining, but that's just a hunch that ought to be measured).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .