You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by "QiuYucheng2003 (via GitHub)" <gi...@apache.org> on 2026/02/20 07:18:29 UTC
[I] [Security/Bug] Clear-text Password Leak in Server Environments via Unmanaged ThreadLocal in Biff8EncryptionKey [poi]
QiuYucheng2003 opened a new issue, #1015:
URL: https://github.com/apache/poi/issues/1015
**Bug Description**
In `org.apache.poi.hssf.record.crypto.Biff8EncryptionKey`, a static `ThreadLocal<String> _userPasswordTLS` is used to store the BIFF8 encryption/decryption password. As explicitly acknowledged in the Javadoc, this was implemented as a design compromise to avoid *"further overloading the various public APIs"*.
While this approach works in single-threaded or desktop applications, it introduces a severe **Credential Leak Vulnerability (Type I Security Risk)** when Apache POI is integrated into modern, thread-pool-based web server environments (e.g., Spring Boot, Tomcat).
**Root Cause & Reproduction Scenario**
Web containers use persistent, pooled worker threads. When an application sets a password to read an encrypted Excel file but fails to explicitly clear it (which is extremely common since there is no forced `try-with-resources` or `finally` enforcement at the API level), the clear-text password becomes a "zombie" object residing indefinitely in the thread's `ThreadLocalMap`.
```java
// Typical vulnerable usage in a Spring Boot Controller
@PostMapping("/upload-encrypted-xls")
public void processExcel(@RequestParam String password, @RequestParam MultipartFile file) {
// 1. Password set on the Tomcat Worker Thread
Biff8EncryptionKey.setCurrentUserPassword(password);
// 2. Process the file...
HSSFWorkbook workbook = new HSSFWorkbook(file.getInputStream());
// 3. If an exception occurs here, or the developer simply forgets to call:
// Biff8EncryptionKey.setCurrentUserPassword(null);
// The password permanently leaks into the ThreadLocalMap of this Tomcat worker thread.
}
Security Impact
1. Memory Residency: A history of user passwords will gradually accumulate and persist in the server's heap memory. Any heap dump (OOM generated or malicious) will expose these clear-text passwords.
2. String Immutability: Because the password is stored as an immutable String rather than a char[], it cannot be overwritten in memory even if remove() is called, keeping it vulnerable until unpredictable Garbage Collection occurs.
3. Cross-Request Contamination: If a subsequent request is processed by the same tainted thread, it might unintentionally gain access to the decrypted contents of a file without the user explicitly providing the password.
Suggested Fixes
Since fundamentally changing the API signatures across HSSFWorkbook is highly disruptive, consider introducing a structured concurrency approach (Closure/Scope) to enforce lifecycle safety without altering existing signatures:
1. Introduce a try-with-resources Scope:
public static AutoCloseable withPassword(String password) {
setCurrentUserPassword(password);
return () -> setCurrentUserPassword(null); // Or better, _userPasswordTLS.remove()
}
Usage:
try (AutoCloseable ignored = Biff8EncryptionKey.withPassword(password)) {
HSSFWorkbook workbook = new HSSFWorkbook(stream);
} // Safely and automatically removed here
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
Re: [I] [Security/Bug] Clear-text Password Leak in Server Environments via Unmanaged ThreadLocal in Biff8EncryptionKey [poi]
Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on issue #1015:
URL: https://github.com/apache/poi/issues/1015#issuecomment-3933005314
This is not how you raise security bugs. They should be reported privately. See https://github.com/apache/poi?tab=security-ov-file#readme
In this case, I don't agree that this is a security bug but it would be nice to improve the code.
POI's trunk branch is for developing 6.0.0 and in that branch, we can add new methods.
Unfortunately, passwords as Strings is widespread in POI code and it will take a lot of work to support using char arrays as well or instead. I don't think we can just remove the API methods that take passwords as Strings without deprecating them and waiting to remove them - but we can add new char array based methods.
It would be nice to be able to work with HSSFWorkbooks that are password protected without having to use Biff8EncryptionKey - again new API methods.
Would you be interested in working on PRs?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
Re: [I] [Security/Bug] Clear-text Password Leak in Server Environments via Unmanaged ThreadLocal in Biff8EncryptionKey [poi]
Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on issue #1015:
URL: https://github.com/apache/poi/issues/1015#issuecomment-3935214754
I merged #1016. A lot more can be done but that change adds new APIs that allow HSSF users avoid using Biff8EncryptionKey.
There is already an API to clear ThreadLocal data added by POI. https://keikai.io/javadoc/latest/org/apache/poi/util/ThreadLocalUtil.html
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
Re: [I] [Security/Bug] Clear-text Password Leak in Server Environments via Unmanaged ThreadLocal in Biff8EncryptionKey [poi]
Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on issue #1015:
URL: https://github.com/apache/poi/issues/1015#issuecomment-3935230612
Your example could easily use a try with a finally that sets the password back to null. That's what the POI tests do.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
Re: [I] [Security/Bug] Clear-text Password Leak in Server Environments via Unmanaged ThreadLocal in Biff8EncryptionKey [poi]
Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning closed issue #1015: [Security/Bug] Clear-text Password Leak in Server Environments via Unmanaged ThreadLocal in Biff8EncryptionKey
URL: https://github.com/apache/poi/issues/1015
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org