Don't Show What They Can't See: Authorization-First Schema Context for Secure Text-to-SQL
This paper proposes an authorization-first framework that enforces fine-grained access control during schema retrieval to prevent unauthorized database metadata exposure in LLM-based text-to-SQL systems, achieving zero unauthorized object leakage while maintaining retrieval utility and significantly reducing unauthorized SQL references.
Original paper licensed under CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer
Imagine a librarian who can instantly translate your spoken questions into precise library commands, finding exactly the books you need from millions of shelves. This is the promise of modern artificial intelligence systems that turn natural language into database queries. These systems rely on a detailed map of the library's contents—a list of every table, column, and connection between them—to understand what you are asking. In a secure environment, however, not every part of that map should be visible to every person. Just as a bank teller cannot see the vault codes for every account, a user should only see the parts of the database they are allowed to access. The danger arises when the system accidentally shows the entire map to the translator before it even begins to work. If the translator is tricked or manipulated, it might reveal the existence of secret tables or sensitive columns, giving an attacker a blueprint for a targeted attack, even if they never see a single actual record.
Researchers at Guangzhou University and Xidian University have developed a new way to handle this problem, ensuring that the translator only ever sees the parts of the map the user is allowed to see. Their approach flips the traditional order of operations. Instead of gathering all the information, filtering out the forbidden parts, and then asking the artificial intelligence to write the query, they first check the user's permissions. They build a small, safe version of the database map that contains only the tables and columns the user is authorized to touch. Only this safe, limited map is then shown to the AI system. This prevents the AI from ever knowing about the forbidden sections, so even if a malicious actor tries to trick the system into revealing secrets, there are no secrets in the context to reveal.
The team tested this method on a collection of 20 different databases containing 240 specific questions paired with different user roles. In the standard approach, where the system sees the full database map before filtering, the AI was exposed to an average of 35.5 unauthorized objects—like secret tables or hidden columns—every single time it processed a request. With the new "authorization-first" method, that number dropped to zero. The system successfully kept all unauthorized information out of the AI's view before it even started thinking. Crucially, this security did not come at the cost of performance. The system was just as good at finding the right tables and columns for the user's actual questions as the old method was. The researchers found that the only reason the old method sometimes failed to produce the right answer was that it had to work with a much larger, cluttered set of information, whereas the new method worked with a clean, relevant subset.
A key discovery in their work was understanding where mistakes still happen. Even with the new security, the AI occasionally wrote queries that mentioned things it shouldn't have. However, the researchers traced these errors and found they were not caused by the system leaking information. Instead, the AI was simply guessing or "hallucinating" the names of forbidden columns, inventing them out of thin air. This distinction is vital: it proves that hiding the forbidden information from the AI stops the direct leakage of secrets, but it does not stop the AI from making up names. Therefore, the new method works best when combined with a final check that validates the query before it runs, creating two layers of defense. One layer stops the AI from seeing the secrets, and the second layer stops the AI from accidentally using a made-up secret.
The study also looked at how the system handles confusing or abbreviated names often found in real-world business databases, where "customer risk score" might be written as "cust_rsk_scr." When the database names were clear and descriptive, the new system performed just as well as the old one. But when the names were shortened and cryptic, the system used a special technique to add plain-language descriptions to the safe map. This helped the AI understand what the short codes meant, improving its ability to find the right data by 11.5 percent compared to a system without those descriptions. This improvement only happened when the names were hard to guess, showing that the extra help is only needed when the map is difficult to read.
To ensure the system was truly secure, the researchers simulated attacks where a user tried to trick the AI into listing all the secret tables. In the old system, these attacks succeeded about half the time, revealing a significant portion of the hidden database structure. In the new system, the attacks failed completely. The AI, having never seen the secret tables, could not list them. The only information that leaked was common words that happened to appear in the system's general instructions, not the actual database secrets. This confirmed that the new method effectively blocks the path an attacker would use to map out a database.
The researchers acknowledge that their solution is a powerful step forward but not a complete cure-all. It prevents the AI from seeing secrets it shouldn't, but it cannot stop an attacker from guessing secrets based on public knowledge or from inferring hidden data from error messages. For this reason, the new method is designed to work alongside existing security checks, not replace them. By ensuring that the AI never sees the forbidden parts of the database in the first place, the system removes a major vulnerability. It creates a boundary where the AI can only work with what the user is allowed to see, making the entire process of turning questions into database commands much safer for organizations that need to protect sensitive information.
Drowning in papers in your field?
Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.