r/SpringBoot • • Oct 29 '26

Question how to handle processing and uploading files

working on a feature that will make users able to upload .zip/ CSV files to my app

how do i go about this security wise

i expect a batch of CSVs
so i wanna check for malware, viruses and zip bombs how do i go about this is there a service i need to subscribe to a free option a local solution

8 Upvotes

6 comments sorted by

View all comments

2

u/JournalistNew7510 Oct 30 '26

On top of ClamAV and the size limits, a few things that are specific to CSV.

Check the first bytes of the file instead of trusting the extension or the Content-Type header. A zip starts with PK, and a real CSV should decode cleanly as UTF-8 text. Then parse it as a stream, row by row (Commons CSV with a CSVParser over the InputStream works well), with a maximum row count and a maximum line length, so one huge single-line file can't eat your heap.

If this data is ever exported again and opened in Excel, escape cells that start with an equals sign, plus, minus or at sign, otherwise you have CSV formula injection.

And don't do the work in the request thread. Save the upload to a temp folder, return a job id, and let a background worker scan and import it, so a slow scan never ties up your Tomcat threads.