Should we sanitize $_FILES['filename']['name']?

后端 未结 3 957
南方客
南方客 2020-12-16 02:43

After the user uploads an image to the server, should we sanitize $_FILES[\'filename\'][\'name\']?

I do check file size/file type etc. But I don\'t chec

3条回答
  •  眼角桃花
    2020-12-16 03:39

    The filename is an arbitrary user supplied string. As a general rule, never trust arbitrary user supplied values.

    You should never use the user supplied filename as the name to save the file under on the server, always create your own filename. The only thing you may want to do with it is to save it as metadata for informational purposes. When outputting that metadata, take the usual precautions like sanitation and escaping.

提交回复
热议问题