I am trying to implement secure file uploads. I need to support various file types, including PDF, XLS, and XSL. I have implemented some basic controls, such as:
- Store files outside the web root
- Check file extension against whitelist
- Generate a new file name on the server
However, I am struggling to validate the file type itself. My thought is that I should not just rely on file extension, because someone might upload definitely-not-an-executable.pdf
.
Question
Is it necessary to check the file type beyond just the extension? If so, what is the best way to do that? Mime type? File signature? Something else?