// Metabase Exploit Tooling with Bun · Part 3

The Vulnerability

Walk CVE-2023-38646 end to end — why a readable setup-token plus Metabase's embedded H2 database turns a "validate my connection" request into code execution.

TypeScriptMetabaseRCEH2
3 min read

Parts 1 and 2 gathered two facts from one unauthenticated endpoint: the version is in range, and the setup-token is readable. This part is the “why” — no new code, just the chain that makes those two facts add up to command execution. Part 4 turns it into a request.

What the token unlocks

Before Metabase has an admin user, it exposes a short setup API so the first visitor can finish configuration. One of those endpoints, /api/setup/validate, takes a database connection and checks that Metabase can actually open it — a convenience so you catch a typo before saving.

That endpoint trusts the setup-token as proof you’re the legitimate first-time admin. Part 2 showed the token is handed to anyone, so “legitimate first-time admin” is really “anyone who read the JSON.” The gate is already open.

Metabase speaks H2

Metabase ships with H2, an embedded Java SQL database, and will happily open an H2 connection when you ask it to validate one. H2 connection strings accept parameters beyond the database name — and one of them, INIT, runs SQL the moment the connection opens:

jdbc:h2:mem:;INIT=<SQL that runs as the connection is established>

So “validate this connection” quietly means “open it, and run whatever INIT says.” We control the connection string, so we control that SQL.

From SQL to a command

The last link is that H2 lets a SQL object — a function or trigger — carry a body written in Java or JavaScript, which H2 compiles and runs inside the JVM. Code running in the JVM can reach java.lang.Runtime, and Runtime runs operating-system commands.

Chain it together and the INIT SQL:

  1. defines a trigger whose body is a few lines of source, and
  2. fires it,

with the body shelling out to the OS. Metabase, doing nothing but “validating” the connection we handed it, opens it, runs the INIT SQL, compiles the body, and the command executes — as the Metabase process, with no login beyond the leaked token. That’s CVE-2023-38646.

Why it’s pre-auth

Nothing here required a session. The only secret involved is the setup-token, and that’s readable by anyone while setup is unfinished — exactly the state a fresh deployment, or the Analytics box, sits in. Patched builds (0.46.6.1 and later on the open-source line) close the validate endpoint to this; our lab runs an earlier one, so it’s open.

Next

We have the token and we understand the mechanism. Part 4 builds the H2 connection string in TypeScript, sends it to /api/setup/validate, and confirms the injection against the lab with a harmless SQL marker — proof the primitive works, without going any further than that.

← All parts