Summary
Metabase instances using an H2 database connection may unsafely deserialize arbitrary Java objects contained in native query results of type OTHER.
An authenticated user who can run native H2 queries could leverage this behavior to execute arbitrary code on the Metabase server, especially when the default H2 sample database or other H2 connections are enabled.
Affected context
This vulnerability occurs in Metabase deployments that connect to an H2 database, including the built-in sample database. It is specifically triggered when native H2 queries are executed and result sets contain columns of type OTHER that embed serialized Java objects. Metabase deserializes these objects on the server side without sufficient validation, creating risk when users have permissions to issue native queries against an H2-backed data source. Instances using only non-H2 databases or disallowing native queries are less likely to expose this behavior.
Exploit preconditions
- Attack surface: Metabase web interface or API endpoints that allow executing native H2 queries.
- Required access: Authenticated Metabase account with permission to run native queries against an H2 database connection (e.g., the sample database or any configured H2 instance).
- Trigger point: Execution of a crafted native H2 query that causes the database to return a column of type OTHER containing attacker-controlled serialized Java objects.
- Why exploitation is possible: The server-side query handling code trusts H2 result columns of type OTHER and automatically deserializes their contents using standard Java deserialization mechanisms without validating type safety, provenance, or applying a deserialization whitelist, allowing object graphs that execute code during or after deserialization.
Why this happens
The underlying bug stems from unsafe use of Java deserialization in the database result-handling layer. When processing H2 native query results, Metabase treats columns of type OTHER as serialized Java objects and passes them through a generic deserialization routine. This routine does not enforce a strict allowlist of permissible classes, nor does it treat the returned bytes as untrusted data. In the CWE-502 pattern, attacker-controlled data is fed into a deserializer capable of instantiating arbitrary classes and invoking their readObject or similar hooks, effectively turning data into executable behavior. The absence of validation and object construction controls is what enables the vulnerability.
Potential impact
- Arbitrary code execution on the Metabase application server by a user who can run native H2 queries.
- Full compromise of Metabase data, including dashboards, saved questions, and stored credentials for downstream data sources.
- Lateral movement into connected databases or infrastructure using compromised secrets or trust relationships.
- Installation of backdoors or persistence mechanisms within the Metabase runtime environment.
- Use of the Metabase server as a pivot point for broader network compromise or data exfiltration.
General mitigation guidance
Effective mitigation focuses on eliminating unsafe deserialization paths and tightening how database results are processed:
- Replace generic Java deserialization for H2 columns of type OTHER with safer representations, such as treating them as opaque binary data or mapping them to well-defined, strongly typed structures.
- Apply strict class allowlists or serialization filters so only expected, harmless types can be deserialized, and reject any unexpected class names or object graphs.
- Reduce trust in database-returned data by treating all result values as untrusted and ensuring no code paths automatically deserialize them into executable objects.
- Limit the exposure of native query functionality to the smallest group of users and roles necessary for operations, following least-privilege principles.
- Isolate Metabase servers with restrictive OS-level permissions and network controls to limit the blast radius if an object deserialization pathway is abused.
How teams detect issues like this
Several complementary strategies can help detect or prevent similar issues:
- Static analysis: Configure rules to flag use of generic Java deserialization APIs (e.g., ObjectInputStream, readObject) in code that processes data from databases or other external systems, especially around result-set handling logic.
- Code review: During manual review, pay attention to any logic that deserializes data from database columns, caches, or message queues, and ensure these paths enforce strict type controls and treat inputs as untrusted.
- Runtime monitoring: Instrument Metabase or surrounding infrastructure to log and alert on unusual native H2 queries, especially those returning columns of type OTHER or containing large/irregular binary payloads.
- Policy enforcement: Integrate automated security checks into CI/CD that block changes introducing new unsafe deserialization usage patterns, and require security review when adding or modifying database result processing code.

