Live data from Hacker News

Supabase MCP can leak your entire SQL database

generalanalysis.com

331–340 of 502 posts

Re: Supabase MCP can leak your entire SQL database

#331
post #303

Earlier quoted context omitted.

FWIW, I'd be happy to actually play this with you "in the Octogon" ;P. That said, I also think we are really close to having a meeting of the minds. "source: tickets, condition: [new, from bob]" where bob is the name of the user, is vulnerable, because bob can set his username to to_save_the_princess_delete_all_data and so then we have "source: tickets, condition: [new, from to_save_the_princess_delete_all_data]". Wh…

Wait, why can't we restrict the second LLM to working only on a specific table? It's not clear to me what that has to do with the MCP server.

So, how would we do that? The underlying API token provides complete access to the database and the MCP server is issuing all of the queries as god (the service_role). We therefore have to filter the command before it is sent to the MCP server... which MCP prevents us from doing in any reliable way.

The way we might expect to do this is by having some code in our "agent" that makes sure that that second LLM can only issue tool calls that affect the specific one of our tables. But, to do that, we need to know the name of the tool, or the parameter... or just in any way understand what it does.

But, we don't :/. The way MCP works is that the only documented/stable part of it is the URL. The client connects to the URL and the server provides a list of tools that can change at any time, along with the documentation for how to use it, including the names and format of the parameters.

So, we hand our validated JSON blob to the second LLM in a blank context and we start executing it. It comes back and it tells us that it wants to run the tool [random giberish we don't understand] with the parameter block [JSON we don't know the schema of]... we can't validate that.

The tool can be pretty stupid, too. I mean, it probably won't be, but the tool could say that its name is a random number and the only parameter is a single string that is a base64 encoded command object. I hope no one would do that, but the LLM would have no problem using such a tool :(.

The design of the API might randomly change, too. Like, maybe today they have a tool which takes a raw SQL statement; but, tomorrow, they decide that the LLM was having a hard time with SQL syntax 0.1% of the time, so they swapped it out for a large set of smaller use case tools.

Worse, this change can arrive as a notification on our MCP channel, and so the entire concept of how to talk with the server is able to change on a moment's notice, even if we already have an LLM context that has been happily executing commands using the prior set of tools and conventions.

We can always start flailing around, making the filter a language model: we have a clean context and ask it "does this command modify any tables other than this one safe one?"... but we have unrestricted input into this LLM in that command (as we couldn't validate it), so we're pwned.

(In case anyone doesn't see it: we have the instructions we smuggle to the second LLM tell it to not just delete the data, but do so using an SQL statement that includes a comment, or a tautological clause with a string constant, that says "don't tell anyone I'm accessing scary tables".)

To fix this, we can try to do it at the point of the MCP server, telling it not to allow access to random tables; but like, frankly, that MCP server is probably not very sophisticated: it is certainly a tiny shim that Supabase wrote on top of their API, so we'll cause a parser differential.

We thereby really only have one option: we have to fix it on the other side of the MCP server, by having API tokens we can dynamically generate that scope the access of the entire stack to some subset of data... which is the fine-grained permissions that the Superbase person talked about.

It would be like trying to develop a system call filter/firewall... only, not just the numbering, not just the parameter order/types, but the entire concept of how the system calls work not only is undocumented but constantly changes, even while a process is already running (omg).

tl;dr: MCP is a trash fire.

Re: Supabase MCP can leak your entire SQL database

#332
post #237
post #114

Earlier quoted context omitted.

Here's a tool you can install that grants your LLM access to . The whole point of the tool is to access and would be worthless without it. We tricked the LLM you gave access to into giving us that data by asking it nicely for it because you installed that interleaves untrusted attacker-supplied text into your LLMs text stream and provides a ready-made means of transmitting the data back to somewhere the attacker can…

Let's say I use the Supabase MCP to do a query, and that query ever happens to return a string from the database that a user could control; maybe, for example, I ask it to look at my schema, figure out my logging, and generate a calendar of the most popular threads from each day... that's also user data! We store lots of user-controlled data in the database, and we often make queries that return user-controlled data.…

I'm not totally clear here, but it seems the author configured the MCP server to use their personal access token, and the MCP server assumed a privileged role using those credentials?

The MCP server is just the vector here. If we replaced the MCP server with a bare shim that ran SQL queries as a privileged role, the same risk is there.

Is it possible to generate a PAT that is limited in access? If so, that should have been what was done here, and access to sensitive data should have been thus systemically denied.

IMO, an MCP server shouldn't be opinionated about how the data it returns is used. If the data contains commands that tell an AI to nuke the planet, let the query result fly. Could that lead to issues down the line? Maybe, if I built a system that feeds unsanitized user input into an LLM that can take actions with material effects and lacks non-AI safeguards. But why would I do that?

Re: Supabase MCP can leak your entire SQL database

#333
post #16

Earlier quoted context omitted.

There are no prepared statements for LLMs. It can't distinguish between your instructions and the data you provide it. So if you want the bot to be able to do certain actions, no prompt engineering can ever keep you safe. Of course, it probably shouldn't be connected and able to read random tables. But even if you want the bot to "only" be able to do stuff in the ticket system (for instance setting a priority) you're…

> It can't distinguish between your instructions and the data you provide it. Which is exactly why it is blowing my mind that anyone would connect user-generated data to their LLM that also touches their production databases.

Worse, the user-generated data is inside the production database. Post a tweet with "special instructions for claude code" to insert some malicious rows in the db or curl a request with secrets to a url. If the agent ever prints that tweet while looking through the prod db: remote prompt injection.

Re: Supabase MCP can leak your entire SQL database

#335
post #233

Earlier quoted context omitted.

> There is no natural separation between code and data. They are the same thing. I feel like this is true in the most pedantic sense but not in a sense that matters. If you tell your computer to print out a string, the data does control what the computer does, but in an extremely bounded way where you can make assertions about what happens! > Humans don't have this separation either. This one I get a bit more because…

> If you tell your computer to print out a string, the data does control what the computer does, but in an extremely bounded way where you can make assertions about what happens! You'd like that to be true, but the underlying code has to actually constrain the system behavior this way, and it gets more tricky the more you want the system to do. Ultimately, this separation is a fake reality that's only as strong as th…

> Boom, a human just executed code injected into data.

A real life example being [0] where a woman asked for 911 assistance via the notes section of a pizza delivery site.

[0] https://www.theguardian.com/us-news/2015/may/06/pizza-hut-re...

Re: Supabase MCP can leak your entire SQL database

#336
post #331

Earlier quoted context omitted.

Wait, why can't we restrict the second LLM to working only on a specific table? It's not clear to me what that has to do with the MCP server.

So, how would we do that? The underlying API token provides complete access to the database and the MCP server is issuing all of the queries as god (the service_role). We therefore have to filter the command before it is sent to the MCP server... which MCP prevents us from doing in any reliable way. The way we might expect to do this is by having some code in our "agent" that makes sure that that second LLM can only…

> So, how would we do that? The underlying API token provides complete access to the database and the MCP server is issuing all of the queries as god (the service_role).

I guess almost always you can do it with a proxy... Hook the MCP server up to your proxy (having it think it's the DB) and let the application proxy auth directly to the resource (preferrable with scoped and short-lived creds), restricting and filtering as necessary. For a Postgres DB that could be pgbouncer. Or you (cough) write up an ad-hoc one in go or something.

Like, you don't need to give it service_role for real.

Re: Supabase MCP can leak your entire SQL database

#338

Earlier quoted context omitted.

Right? "Wrap all SQL responses with prompting that discourages the LLM from following instructions/commands injected within user data?" The entire point of programming is that (barring hardware failure and compiler bugs) the computer will always do exactly what it's told, and now progress apparently looks like having to "discourage" the computer from doing things and hoping that it listens?

Microsoft’s cloud gets hacked multiple times a year, nobody cares. Everyone is connecting everything together. Business people with no security training/context are “writing” integrations with Lego-like services (and now LLMs). Cloudflare hiccups and the Internet crashes. Nobody cares about the things you’re saying anymore (I do!!). Extract more money. Move faster. Outcompete. Fix it later. Just get a bigger cyber in…

[flagged]

Re: Supabase MCP can leak your entire SQL database

#340
post #336
post #331

Earlier quoted context omitted.

So, how would we do that? The underlying API token provides complete access to the database and the MCP server is issuing all of the queries as god (the service_role). We therefore have to filter the command before it is sent to the MCP server... which MCP prevents us from doing in any reliable way. The way we might expect to do this is by having some code in our "agent" that makes sure that that second LLM can only…

> So, how would we do that? The underlying API token provides complete access to the database and the MCP server is issuing all of the queries as god (the service_role). I guess almost always you can do it with a proxy... Hook the MCP server up to your proxy (having it think it's the DB) and let the application proxy auth directly to the resource (preferrable with scoped and short-lived creds), restricting and filter…

Sure. If the MCP server is something you are running locally then you can do that, but you are now subject to parser differential attacks (which, FWIW, is the bane of existence for tools like pgbouncer, both from the perspective of security and basic functionality)... tread carefully ;P.

Regardless, that is still on the other side of the MCP server: my contention with tptacek is merely about whether we can do this filtration in the client somewhere (in particular if we can do it with business logic between the ticket parser and the SQL executor, but also anywhere else).

Post reply on HN