Scrivio Interview library
ScenarioIntermediate7 min read · updated 12 November 2026

Users upload Excel files to your service. What security and resource risks does this bring and how do you mitigate them?

An uploaded .xlsx is a ZIP archive of XML files, so it can carry zip bombs and XML attacks, and even a valid file can be huge enough to exhaust memory and CPU. We keep POI's ZipSecureFile limits enabled, cap the upload size and row count, parse in a bounded executor with timeouts, never evaluate formulas, external links or macros from untrusted files, and keep POI patched. We also treat the content itself as untrusted, including values that would become formulas when we export them again.

Why this question is asked

Accepting Excel uploads feels like a normal feature: users fill in a template, we read it and import the rows. But from a security point of view, we are letting anyone send us a compressed archive that a complex parser will expand inside our service. Interviewers ask this scenario to see whether we think about files as attack input and about resource limits, not only about parsing. In this answer, we will look at what an .xlsx really is, go through the attacks that come from that structure, then the resource risks, the risks in formulas and macros, and finally the content itself and how it can hurt the next person who opens our exports.

1What an .xlsx File Really Is

An .xlsx file is a ZIP archive. If we rename it to .zip and open it, we find folders of XML documents: one per sheet, one for shared strings (the table of all text values, which cells point to by index), one for styles, and some for relationships between the parts. A .xlsm file is the same with a binary VBA macro project inside.

When POI opens the file, it unzips these entries and parses the XML. So every risk of ZIP files and every risk of XML parsers applies to our upload endpoint. The small file the user sends tells us nothing about how much work we will do once we expand it.

Step throughWhat POI unpacks from an upload
  1. HTTP multipart uploadsize limited by the server
  2. ZIP archiveentries compressed; ratio and entry size checked
  3. XML partssheets, shared strings, styles; parsed by POI
  4. Cell valuestext, numbers, formulas, links
  5. Our import logicvalidation, database writes

5 layers, from the top down. Step through them one at a time.

Each layer can be abused, so each one needs its own limit.

2Zip Bombs and XML Attacks

A zip bomb is a small archive that expands to an enormous size: a few hundred kilobytes that become gigabytes of XML, because highly repetitive data compresses extremely well. Without limits, the parser reads it into memory and the service runs out of memory or disk.

POI defends against this with ZipSecureFile. It checks the inflate ratio, the compressed size divided by the expanded size, while reading each entry, and refuses an entry that expands too much: the default minimum ratio is 0.01, so an entry may grow to about 100 times its compressed size. It also limits the size of a single expanded entry. When a limit is hit, POI throws an IOException that says a zip bomb was detected. The important rule is to keep these checks enabled. Code that calls ZipSecureFile.setMinInflateRatio(0) to make one large legitimate file work turns the protection off for every upload in the JVM, because the setting is global.

The XML layer has its own attacks. XXE, XML external entities, makes a parser fetch a file or URL named in the document, which can leak server files. Entity expansion attacks, such as billion laughs, define entities that expand into each other until memory is gone. POI configures its XML parsers to refuse external entities and limit expansion, and several past POI vulnerabilities were exactly in this area, which is one reason to keep the library current.

Java
ZipSecureFile.setMinInflateRatio(0.01); // the default: keep it, never set it to 0
ZipSecureFile.setMaxEntrySize(200L * 1024 * 1024); // tighter than the default for our use
try (Workbook wb = WorkbookFactory.create(in)) { ... }
// java.io.IOException: Zip bomb detected! The file would exceed the max. ratio ...

3Limiting Size, Rows and Time

Even a perfectly valid file can hurt us. XSSFWorkbook loads the whole workbook into memory, often many times the size of the file, so ten users uploading 40 MB files at the same moment can take a service with a 2 GB heap down. The defence is a set of limits at every layer.

First, the HTTP layer: in Spring Boot, spring.servlet.multipart.max-file-size and max-request-size reject anything above, say, 10 MB before our code sees it. Second, the content: we check that the file really is an OOXML ZIP (POI's FileMagic can detect the type from the first bytes) instead of trusting the file name, and we reject .xlsm if we do not need macros. Third, the rows: we stop reading after a fixed number, such as 50,000, and tell the user to split the file. For files near the limit, POI's streaming event API reads row by row with little memory.

Finally, we do the parsing off the request thread, in an executor with a fixed number of threads and a bounded queue, so ten simultaneous uploads use at most, say, four parsers at once, and we give each parse a timeout. A file that takes too long is abandoned and reported, instead of holding a thread forever.

Java
spring.servlet.multipart.max-file-size=10MB
spring.servlet.multipart.max-request-size=11MB
ExecutorService parsers = new ThreadPoolExecutor(4, 4, 0, TimeUnit.SECONDS,
new ArrayBlockingQueue<>(20), new ThreadPoolExecutor.AbortPolicy()); // reject when full
Future<ImportResult> f = parsers.submit(() -> importer.read(path));
ImportResult result = f.get(60, TimeUnit.SECONDS); // TimeoutException after a minute
// (cancel the future on timeout, and make the reader check for interruption)

4Formulas, External Links and Macros

POI never runs VBA macros; it only stores them. Our risk with macros is passing them on: if we accept a .xlsm and later serve it to other users, their Excel might run the macro. So we reject macro-enabled files unless there is a real need, and never re-serve an uploaded file as it is.

Formulas are different, because POI can evaluate them. Evaluation of untrusted formulas costs CPU (a sheet can contain thousands of complex formulas that refer to each other) and some formulas refer to other workbooks through external links. For imports we normally do not need evaluation at all: we read the cached results that Excel stored, or we reject formula cells in columns that must hold plain values. If we do evaluate, we do it without setting up external workbook references, so a link to another file simply fails.

5Treating the Content as Untrusted

After parsing, the values themselves are user input, like any form field. A name can contain SQL or HTML, so we use parameterised queries and escape output as usual. A file can also be infected with malware that targets desktop users, so organisations often scan uploads with an antivirus engine before processing and store the original only in quarantine.

One risk is easy to miss: re-exporting. If a customer name in the upload is =HYPERLINK("http://evil.example","Click"), and we later export names to CSV, a colleague who opens that CSV in Excel sees a live formula. This is CSV injection, also called formula injection. When we write such values to CSV we prefix values that start with =, +, -, @, tab or carriage return with a single quote, and when we write .xlsx we set them as string cells, which Excel never evaluates.

Upload risks and mitigations
RiskMitigation
Zip bombKeep ZipSecureFile ratio and entry size limits on
XXE, entity expansionPOI's hardened parsers; keep POI patched
Huge but valid fileUpload size limit, row limit, streaming reader
Slow parse, many uploadsBounded executor, timeouts
Formulas, external linksRead cached values; do not evaluate untrusted files
MacrosReject .xlsm; never re-serve uploads as-is
Malicious values on exportEscape formula-like values; string cells

6Follow-up questions

Why is relaxing ZipSecureFile dangerous even for one trusted file?

The settings are static and apply to the whole JVM. Setting the minimum inflate ratio to zero for one large internal report disables zip bomb protection for every user upload in the same service. If a trusted file needs higher limits, it should be processed in a separate service or with limits raised only modestly.

Is it enough to check the file extension?

No. The extension and the content type header are chosen by the client. We check the actual bytes, for example with POI's FileMagic, and then rely on the parser's limits, because a file can be a real ZIP and still be malicious.

How do you keep POI patched in practice?

Through dependency scanning in CI, such as OWASP Dependency-Check or the scanner built into the repository platform, and a platform BOM that the team updates regularly. Parser libraries get security fixes from time to time, so falling several versions behind is a real risk.

7Conclusion

In this answer, we saw that an uploaded .xlsx is a ZIP of XML, which exposes us to zip bombs and XML attacks; POI's ZipSecureFile limits and hardened parsers protect us as long as we keep them enabled and POI up to date. We limited upload size and rows, parsed in a bounded executor with timeouts, avoided evaluating formulas and external links, rejected macros, and treated every value as untrusted, including formula-like values that would become live when we export them again.

What to say in the interviewAbout 80 seconds aloud

Open with

I start from the fact that an .xlsx is a ZIP archive of XML parts, so an upload is untrusted compressed input for a complex parser. The first risks are zip bombs and XML attacks like XXE and entity expansion.

Then, if they want more

POI has ZipSecureFile, which checks the inflate ratio and the maximum entry size; I keep those on and never set the ratio to zero, because the setting is global for the JVM. POI also hardens its XML parsing, which is one reason I keep it patched through dependency scanning.

Then resources: XSSFWorkbook can need many times the file size in memory, so I limit the upload size in Spring's multipart settings, check the real file type from its bytes, cap the number of rows, use the streaming reader for big files, and parse in a bounded executor with a timeout so many uploads cannot exhaust the service.

I don't evaluate formulas from untrusted files; I read cached values, and I never set up external workbook links. I reject .xlsm because macros could reach other users. Finally the values are user input, so I validate them, scan files if the organisation requires it, and escape formula-like values when we export them again, to avoid CSV injection.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Users upload Excel files to your service. What security and resource risks does this...": https://scrivio-interview-library.netlify.app/java/document-libraries/993a9e1e88/