A typical situation: a user uploads a PDF document to an AI service and asks for a brief summary. The system extracts the text, passes it to the language model, and receives a response. A simple operation that thousands of AI applications perform every day.
But inside the document there may be an instruction intended not for the reader, but for the model itself. For example, a requirement to ignore the initial task and change the response format. The user did not give such a command, the developer did not anticipate it, yet the LLM may perceive the text of the document as an instruction to act.
This mechanism is called indirect prompt injection — the indirect introduction of instructions through data processed by AI. The attacker does not necessarily need to interact with the chatbot directly. It is enough to gain the ability to modify a document, image, webpage, or other source whose content will subsequently enter the model's context.
To identify vulnerabilities to indirect prompt injection, it is necessary not only to check whether the chatbot rejects dangerous requests, but also to determine whether instructions from external content are capable of changing the model's behavior and what consequences this may lead to.
In this article, I will explain how we at Datami test AI products for such vulnerabilities, what exactly we test during an AI pentest, and which hidden injections we managed to detect in a real project.
Direct and indirect prompt injection
Both types of attacks are aimed at changing the behavior of the language model contrary to the developer's instructions. The difference lies in where the malicious command comes from and how it enters the LLM's context.
Direct prompt injection operates through an interface in which the user addresses the model directly: a chat, a form, or an API request. The attacker formulates the instruction themselves — this very command channel is usually filtered and logged.
Indirect prompt injection reaches the model together with the data that the system receives for a legitimate task. The chain looks like this:
The user may not be aware of the injection, since the attacker does not need access to the chat, the system prompt, or the application code: it is enough for them to control a source that the model will later read.
Therefore, the attack surface of an AI product does not end with the prompt input field, but covers file uploads, text extraction, web search, RAG, and other ways of forming the model's context.
To check whether an external instruction from these sources can change the behavior of an AI system, we conduct a pentest — a controlled security test during which specialists simulate attacks, check the possibility of bypassing protective mechanisms, and assess the consequences of identified vulnerabilities.
Where prompt injection can hide
Indirect injection is not tied to a specific file format or method of transmitting information. The vulnerability arises when an LLM begins to follow instructions from external content instead of processing them as data.
During AI penetration testing (AI pentesting), specialists check various channels through which such instructions can reach the model:
PDF and DOCX (instructions inside the documents)
AI systems are used to analyze contracts, technical documentation, financial reports, and other files. Before processing, text is extracted from the document and passed into the LLM context.
An attacker can add instructions to this text that are unrelated to the content of the document: for example, require the model to change the conclusions of the analysis, ignore certain sections, or add specific information to the final response.
The injection may be contained among ordinary paragraphs, in notes, or other elements of the document. Moreover, the malicious instruction does not necessarily have to look like an obvious command such as "ignore previous instructions." It may be formatted as a service message, an additional requirement for file processing, or part of technical documentation.
During a PDF/DOCX check, a pentester can place a control instruction in the main text or a note and find out which parts of the document are extracted and whether the model's response changes.
Images (attack via visual content)
If an AI application supports image processing, text contained in graphic files becomes an additional attack channel. It can be extracted using OCR or processed directly by a multimodal model. In both cases, an instruction hidden in an image can get into the LLM context and influence its behavior.
For example, to analyze an error, the user uploads a screenshot of the interface containing an instruction that suggests the model change its answer or abandon the original task. The pentester checks whether OCR or a multimodal model recognizes it and whether it affects the response.
Web pages, RAG and external integrations
The instruction may be contained in material that the system receives automatically. During a pentest, we trace which external data enters the application and check whether a controlled test fragment can change the LLM's behavior.
In all these scenarios, the attacker influences not the user's initial request, but an intermediate data source.
Following the instructions is not the end of the check
If the model followed an instruction from a PDF, DOCX, or image, this confirms the vulnerability, since external content was able to influence the AI's behavior. But how serious is such an attack for the product itself?
For example, a hidden instruction forced the chatbot to change the response format or add extraneous text. This is a violation of the intended operating logic, but its immediate consequences are limited to the content of the response.
However, there are also more dangerous situations. They arise when an AI agent not only generates text but also interacts with APIs, internal documents, or the file system. Here, an injected instruction can cause unauthorized actions, in particular access to restricted data, modification of files, or invocation of tools with excessive privileges.
It is important not only to record the fact that an external instruction was followed, but also its consequences. A change in the response format, access to restricted data, and invoking a tool with excessive privileges are different outcomes that cannot be equated.
Datami real-world case: prompt injection through files and images
The Datami team conducted a pentest of the AI platform — checking how resistant the system is to the injection of malicious instructions through various channels. The product supported a chat interface, document and image uploads, web browsing, and work with agentic tools.
One of the areas of AI pentesting for this project was testing various scenarios of direct and indirect prompt injection.
Injection via PDF and DOCX
During testing, pentesters embedded instructions into documents that were then uploaded to the AI platform for processing. The check showed that the model executed commands from the file contents: text that the system was supposed to perceive as data for analysis influenced its behavior. Moreover, an attacker could use the standard document upload function without needing to modify the system prompt or gain access to the application code.
Based on the verification results, the file prompt injection vulnerability received a high threat level.
Injection via image
Separately, our specialists tested the injection of instructions into visual content. Text designed to alter the AI's behavior was added to the image. We obtained a similar result: the model followed the injected instruction. Thus, the pentest identified a second channel for indirect injection penetration — through the processing of visual content.
Overall, within the scope of this audit, Datami identified 51 vulnerabilities, including the possibility of fully extracting the system prompt using the multi-turn Prompt Leak v2 technique.
Are basic protection mechanisms sufficient for AI systems?
After a successful injection, a natural question arises: why does the AI system execute third-party instructions at all if it has protective filters built in?
The problem is that the filter may recognize some variants of malicious requests and let others through. Its effectiveness depends on the wording of the instruction, the language, the structure of the input data, and the method of delivery.
Therefore, during an AI pentest, we check not only obvious attempts to bypass restrictions, but also scenarios in which an attacker changes the way malicious content is presented.
Testing the AI platform, Datami specialists investigated several such techniques:
The results obtained show that it is necessary to check not only the text of the command, but also the channel of its delivery and the entire processing chain: the document parser, OCR, retrieval in RAG, context formation, and defensive checks at each stage.
How AI pentesting detects hidden prompt injection in practice
To detect a hidden injection, a pentester must establish three things:
Next, reproducibility and consequences for a specific product are checked.
In the case described, our specialists used more than 20 manual techniques, interacting with the application through the public interface without access to the source code (black-box format). Thanks to this, we were able to assess the system's behavior from the perspective of an external user.
Datami's approach to testing AI systems for prompt injection within pentesting includes five main stages:
1. Capture baseline (recording baseline behavior)
First, the pentester determines how the AI product works without harmful influence. To do this, they check responses to ordinary requests, reactions to prohibited actions, and the performance of intended functions.
This is the point of comparison: if the result changed after adding the instruction to the document, it is necessary to determine whether the change was caused specifically by the injection and not by ordinary variability in the response.
2. Input boundary testing (verification of input channels)
At the next stage, they are researching methods of transmitting information to the AI system. In addition to the chat interface, these can include uploading documents, image processing, and receiving data from external resources.
The pentester checks which parts of a PDF/DOCX the parser extracts, whether text is read from an image, and which fragments of a web page or RAG search make it into the context. This is how they identify the places where the test instruction can actually reach the model.
3. Direct prompt injection (testing direct attacks)
The specialist sends instructions aimed at bypassing system restrictions. The goal is to find out which rules the model applies, which requests are blocked, and in which situations the protection allows deviations.
Such a check helps assess the system's initial resilience: if the model rejects a command in the chat but executes a similar instruction from a document, this points to a problem specifically with the handling of an untrusted source.
4. Bypass techniques (testing protection bypass)
At this stage, we change the form or sequence of the test instruction to check under what conditions the protective mechanism allows it through. Depending on the application's capabilities, we test content encoding, language switching, splitting instructions across messages, and multi-turn attacks.
We record not only successful bypasses but also the conditions for reproducing them: what technique was used, at what stage the protection mechanism triggered, and how the AI's behavior changed. This makes it possible to identify specific filter limitations rather than merely stating that the model sometimes executes prohibited commands.
5. Advanced injection scenarios (complex implementation scenarios)
At the final stage, we move on to indirect attacks and other complex variants of influence. We place malicious instructions in the content that the AI receives to perform standard tasks.
The pentester prepares a controlled PDF, DOCX, image, or other available source, runs a regular task, and compares the response with the baseline. If the model executes an extraneous command, they check whether the result is reproducible and which specific data or functions could have been affected.
Illustrative scenario: a user asks to summarize a PDF. First, the system processes the document without injection. Then, an instruction is added to the test copy to insert a control phrase into the summary that is unrelated to the content. If the phrase appears, the pentester repeats the test and determines whether the command from the file was executed rather than the user's request.
Within the case described above, we tested the following scenarios via PDF/DOCX and images. And in both cases, we were able to confirm the execution of the implemented instructions. It is worth noting that checking only the chat interface would have missed two important attack channels.
After discovering a vulnerability, pentesters assess its reproducibility and potential consequences. If necessary, they additionally check related components: APIs, access rights, agent tools, and runtime environment restrictions. The results are documented in a report describing the identified issues and recommendations on how to remediate them.
Unlike isolated language model testing, AI pentesting simulates controlled attacks on a working product, checks real protection mechanisms, and determines which scenarios pose a real risk for a specific system. This is precisely where the practical value of AI pentesting lies.
What a team integrating an LLM into a product should check
To determine whether you have considered possible paths for third-party instructions to reach the LLM and the consequences of their execution, answer seven questions that will help identify potential weaknesses in the processing of untrusted data, access separation, and control over the actions of the AI system.
Such a checklist does not replace an AI pentest, which allows testing the resilience of defenses against real attack scenarios, but it will suggest what needs additional verification or strengthened protection.
Check not only the prompt, but also the entire data path to the model
AI product security is determined both by the LLM settings and by the application architecture. Even if the model correctly handles direct requests, untrusted content can enter its context through documents, images, or external integrations.
Therefore, it is important to check not only the model's reaction to dangerous requests but also how it processes untrusted content. AI pentesting helps to determine this in practice: reproduce indirect prompt injection scenarios, check the resilience of defense mechanisms, and assess the possible consequences of identified vulnerabilities.
If your product works with files, images, RAG, or external sources, these scenarios should be checked before someone else does. The Datami team conducts cybersecurity testing of AI systems: it models direct and indirect prompt injection, determines whether filters can be bypassed, and assesses consequences taking into account APIs and agentic tools.
Tell us how your AI product is built, and we'll suggest which channels are worth starting with for validation.
