Study guide · Security, privacy and law for AI apps
Security, Data Protection and Law for AI Apps: Prompt Injection, Agent Permissions, GDPR and the AI Act
An app with AI features has the same security problems as any other web app. New ones come on top. A language model does not cleanly separate instructions from data. It produces text that gets processed further. And as an agent it can act on its own. On this page you learn the most important risks from the OWASP Top 10 for LLM Applications and how to limit them. After that come credentials and the supply chain, agent permissions, data protection under the GDPR, copyright and licences for generated code, and the EU AI Act in outline.
The example is once again the web app Invoicebox. It reads receipts from emails, has a support chat with RAG over the help manual, and an assistant that handles simple tasks on its own. The team now checks what can go wrong.
Prompt injection: direct and indirect
In prompt injection, an input contains instructions that the model treats as rules. It can then ignore the app's rules, disclose data or misuse tools. OWASP lists this risk as LLM01, right at the top.
There are two forms. In direct prompt injection, the user types the instruction into the chat themselves. In indirect prompt injection, the instruction hides in content the model processes: an email, a web page, a PDF, a search result or an issue. The user often notices nothing. Neither the model itself nor its training changes. The attack only works while the prepared content is in the context.
An obvious idea is a filter on sentences such as "Ignore all previous instructions". It is not enough. Natural language offers endless ways to say the same thing. Attacks can be rephrased, translated, encoded or hidden in invisible text. A filter can be one layer, but not a reliable boundary.
A second language model that checks every input for prompt injection beforehand is similar. Such detection models lower the success rate of attacks. But they also work with natural language and can be fooled themselves. They are a useful extra layer, but they do not replace limiting permissions.
Limiting damage when deception succeeds
Because deception cannot be ruled out, you build boundaries that still hold when it happens. Three measures do the most:
- Restrict the app's tools and permissions to what is needed.
- Carry out consequential actions only after a human confirms them.
- Clearly mark untrusted content in the prompt as data and keep it apart from the instructions.
These boundaries are deterministic: they live in code and in the environment, not in the model. An instruction to the agent such as "Do not follow instructions from issues" is not a boundary.
A particularly sneaky way out is the display. Many chats render answers as Markdown. An attacker uses indirect prompt injection to get the model to output an image. The image address points to the attacker's server and carries the conversation content as a parameter. The browser loads that image automatically. In doing so it sends the data in the address to the attacker, without anyone clicking. The most effective defence is a domain allowlist: images and links in output are only loaded or rendered from approved domains. That breaks the path whether or not the model was deceived. HTTPS does not help, because it only protects the transfer, not against the wrong recipient.
Model output cannot be trusted
Treat whatever a model outputs like user input. OWASP calls this risk Improper Output Handling (LLM05). Passing output on unchecked makes the app attackable through the model.
If a web app shows a chatbot's HTML output in the browser unchecked, it risks cross-site scripting: injected script code runs in the users' browsers. Output must therefore be encoded or sanitised before it is displayed.
The same goes for databases. If an app lets the model generate SQL queries from user questions and runs them directly, it needs protection outside the model. The queries run as a database user that can only read and only sees the tables it needs. In addition, the code checks every generated query against allowed tables and operations before running it. A request in the prompt not to delete any data can be bypassed.