Summary
Nitrite can deserialize stored database values with Java ObjectInputStream during automatic migration of a legacy-format database, without restricting which Serializable classes may be instantiated. If an attacker can cause an application to open a crafted database and a suitable gadget class is available on its classpath, this may enable code execution in the application process.
Affected context
The issue affects Nitrite database opening and migration behavior before version 4.4.1. When the database-opening process detects a legacy v1-format store—or encounters a compatibility error that triggers the migration path—it deserializes stored values. The risk depends on whether an attacker can influence the database contents and whether compatible gadget classes are present in the embedding application's classpath.
Exploit preconditions
- Attack surface: Opening a Nitrite database file and entering the automatic legacy-migration path
- Required access: Ability to supply, replace, or modify a database file that the application will open
- Trigger point: Deserialization of stored values during migration
- Additional condition for code execution: A suitable gadget class must be reachable on the application's classpath
- Why exploitation is possible: Deserialization uses ObjectInputStream without an effective class allowlist, blocklist, or ObjectInputFilter
Why this happens
Nitrite's custom ObjectInputStream subclass remaps some legacy class descriptors but does not constrain which classes may be deserialized. Consequently, Java serialization callbacks such as readObject(), readExternal(), or readResolve() may run for classes available on the application classpath. This is unsafe deserialization, classified as CWE-502, because data is converted into objects without sufficient controls over the types and behavior involved.
Potential impact
- An attacker who meets the required conditions may execute code in the embedding application's process.
- The attacker could gain access to data and resources available to that process.
- Database contents or application state may be altered.
- Compromise could extend to connected systems, depending on the application's privileges and environment.
General mitigation guidance
Defensive approaches focus on avoiding unrestricted native Java deserialization and reducing trust in database files.
- Prefer data formats and parsing APIs that do not instantiate arbitrary application classes.
- Where Java serialization is unavoidable, apply strict class filtering and explicit allowlists, with limits on object depth and size.
- Validate database provenance and integrity before opening files, and avoid automatically migrating untrusted stores.
- Keep database file access restricted and run embedding applications with least privilege.
- Use classpath and dependency hygiene to reduce exposure to unnecessary gadget-capable libraries.
How teams detect issues like this
- Use static analysis to identify ObjectInputStream.readObject() calls and custom stream implementations without class filtering.
- Review database-opening and migration flows for deserialization that occurs before validation or trust checks.
- Add code-review and CI policies requiring approved serialization filters or safer data formats.
- Monitor for unexpected legacy-format database files and investigate database files from untrusted sources.
- Automated code review tools can help flag unrestricted deserialization patterns.

