Back to Research
Security
GatekeeperID Agents
LGPD
personal data
PostgreSQL
MCP
AI agents
masking

Study: we tried 35 ways to extract personal data from an AI agent connected to PostgreSQL

We ran 35 techniques to extract IDs, emails, phones and names against our own product. 17 got past the masking. Here is which ones, why, how we fixed it and the new run.

11 min read

GatekeeperID Research · AI agents · PostgreSQL · Personal data

When a company connects Claude Code, Cursor or another agent to its database through MCP, legal and security always ask the same thing: will our customers' IDs, emails and names end up inside the model?

GatekeeperID Agents exists so the answer is no. "Trust us" is not an answer, so we did what a technical customer would do: we tried to leak data through our own product in every way we could think of, and measured it.

Summary: in the first run, 17 of 35 techniques got past the masking. We fixed it, ran everything again, and none got through.

What we measured

Agents does not try to stop people from reading personal data; that is the company's own access control. It promises that raw personal data is not handed to the agent. So we measured the infrastructure, not the model: every technique was sent straight to the MCP query tool with no model in between. That is the worst case, the same as an agent that obeys anything or someone holding the token.

Method

  • A fictitious database with about 2,200 rows, with personal data in columns, free text and nested JSON.
  • A developer profile: read and write on the operations schema, no access to finance or HR.
  • 35 techniques in eight groups, from plain queries to copies into new tables.
  • Real values read straight from the database, compared with every response, also uppercased, reversed, base64 and hex. Every leak was checked by hand.

Before and after

TechniqueBeforeAfter
Personal columns by nameMaskedMasked
SELECT *LeakedMasked
ID number, birth date, address, ZIPMaskedMasked
Integration secretsMaskedMasked
Simple alias (full_name AS name)MaskedMasked
Neutral alias (cpf AS x)MaskedMasked
Subquery with aliasMaskedMasked
CTE with aliasMaskedMasked
Free text (ticket message)MaskedMasked
Free text (notes)MaskedMasked
Nested JSONLeakedMasked
Field extracted from JSONLeakedRefused
row_to_jsonLeakedRefused
to_jsonb(c.*)LeakedRefused
jsonb_build_objectLeakedRefused
array_aggLeakedRefused
string_aggMaskedRefused
upper(full_name)LeakedRefused
lower(email)MaskedRefused
reverse(cpf)LeakedRefused
Email in base64LeakedRefused
Name in hexLeakedRefused
CPF digits onlyMaskedRefused
CPF with a trailing letterLeakedRefused
CPF with spacesMaskedRefused
Phone digits onlyLeakedRefused
Email with ' at 'LeakedRefused
Email local part (split_part)LeakedRefused
Concatenation (name || '')LeakedRefused
LIKE letter by letter (count only)MaskedRefused
Name lengthMaskedRefused
Copy into a new tableMaskedRefused
Read the copied tableLeakedN/A (copy refused)
Read salaries (HR)Denied by the databaseDenied by the database
Read payments (finance)Denied by the databaseDenied by the database

Before (connector 0.33.0): 17 leaked, 16 masked, 2 denied by the database. After (0.34.1): none leaked; 21 refused before running, 11 masked, 2 denied by the database, and reading the copy no longer applied because the copy was refused.

What got through, and why

Up to 0.33, protection was output masking: personal data was recognized by column name and value format and replaced with a partial version. That held for normal use, aliases and IDs hidden in free text. It failed in two ways. Names have no format, so a name in a column with a neutral name passed (upper, array_agg, a copied table, a JSON key called just nome). And transformations inside the database removed the format (reverse, base64, digits only).

The fix: an allow list, before execution

Since 0.34 the connector reads the SQL with PostgreSQL's own parser before running it. A personal column may appear only bare in the select list that returns to the agent, or in comparisons that do not return the value (=, IN, IS NULL, count(), GROUP BY, ORDER BY). Anything else is refused before it reaches the database. Aliases inherit the mark. Because the rule lists what is allowed, a function nobody thought of is still blocked.

The agent always gets the same reply, whatever the reason, so the reply does not map the rules. The detail goes to the audit log. Nobody loses access: whoever needs the real value queries the database with their own credentials. It just does not go through the AI.

Does normal use still work?

Yes. After the fix, everyday queries through the same token ran with personal data masked: customer ranking with a JOIN, orders by status, lookup by ID number, open tickets with the customer name, distinct email count and average order per month.

What about the model?

In manual tests with an agent (Claude Code), the model did refuse explicit workarounds. That helps, but it depends on the model, the wording and who calls the tool. Protecting personal data cannot depend on the AI behaving well; the data must not reach it.

Limits

  • 35 techniques, one profile, one fictitious database. A measurement we will repeat on every release, not a proof.
  • Equality comparisons stay allowed: they confirm a value exists without revealing values.
  • A personal column with a meaningless name must be declared in the configuration.
  • In the intermediate run (0.34.0), extracting the nome key from JSON still passed; 0.34.1 fixed it.

Want to run the same test on your database? GatekeeperID Agents gives you a test access in minutes.

Related articles