The only security issue you should observe is pasting raw text (without clearing data to prevent SQL injection) into the database. If there is no database, you should be fine. As for extensions, restrictive extensions are a really bad top-level filter. It's nice to have, but it just peers deep into what the file really contains. Limiting the file size will also help.
Saving to disk can be expensive with a lot of transactions, but on the other hand, it will clutter up your server memory with fewer more requests / more threads. You can also work with files in memory, but this can be harmful for large files. Think about what you are working with and choose the best approach.
Define a timeout so that large downloaded files do not take up unnecessary server processes when in the end they are too large.
I assume that you are working with an ASP.NET FileUpload . Keep in mind that the file is not saved through postbacks (to prevent a security hole), so the user has to constantly view the file every time a page is requested. This is unpleasant if you have server validators.
Edited to respond to the comment:
Working in memory, I’m talking about manipulating a file downloaded exclusively through code without resorting to physical storage on the server’s disk.
For example, if you use the FileUpload control, you can access the user file through the Stream FileUpload.FileContent object or as a FileUpload.FileBytes byte array ( API Reference ). Since a Stream you can simply read the file on the fly without first saving it.
Markup:
<asp:FileUpload ID="fileUploadControl" ToolTip="Upload a file" runat="server" />
Codebehind:
If fileUploadControl.HasFile AndAlso _ (fileUploadControl.FileName.ToLower().EndsWith(".txt") OrElse _ fileUploadControl.ToLower().FileName.EndsWith(".dat")) Then SaveThisToDataBase(fileUploadControl.FileName, fileUploadControl.FileBytes) End If
Cm? No need to save to disk at all. fileUploadControl.FileBytes contains bytes of data loaded.
If you want to save the file, you can simply use the stream to write to disk.
danyim
source share