apoorv-2204

apoorv-2204

How to fix Insecure File Uploads in Elixir

Hi,
I want to fix the issue in my codebase where I can upload any binary or executable file in live view or in general file api input in Phoenix.

I have already added restrictions to only accept files like PDFs, PNGs, and JPEGs.

I also want to perform an antivirus scan. What should I do? Is there a library in Elixir for it?

Most Liked

kip

kip

ex_cldr Core Team

If your focus is primarily image file types then Image safely opens those files and errors if they aren’t valid image files (irrespective of the suffix). This is because libvips, which does all the work, is very conservative and security conscious about what it considers a valid image file.

Exadra37

Exadra37

While I don’t know of any lib to do virus scanning I want to call your attention to the fact that if your restrictions to the file type are based on the extension, then they can be bypassed. Instead, a better approach is to perform this check based on the mime type of the file, but not based on the one passed in the request headers, you need to do it yourself on your application.

Another thing to have in mind is that, before processing it in your application, you may want to copy the uploaded file to a temporary path with a random name. If you expose the uploaded file to the public, then you should use a different name from the one given by the client.

More best pratices can be found at File Upload - OWASP Cheat Sheet Series.

Zurga

Zurga

I do not know of any Elixir library that will do virus scanning, but using the System.cmd function you can call an external virus scanner to scan the uploaded file.

Last Post!

apoorv-2204

apoorv-2204

https://github.com/ramortegui/clamxir

Is virus scan will be enought? or do we need to do something else also.
can we use clamav in prod servers/

Where Next?

Popular in Questions Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

Other popular topics Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New

We're in Beta

About us Mission Statement