Better security for file uploads
(cherry picked from commit ca643a9)