Web LLM attacks
Organizations are rushing to integrate Large Language Models (LLMs) in order to improve their online customer experience. This exposes them to web LLM attacks that take advantage of the model's access to data, APIs, or user information that an attacker cannot access directly. For example, an attack may:
- Retrieve data that the LLM has access to. Common sources of such data include the LLM's prompt, training set, and APIs provided to the model.
- Trigger harmful actions via APIs. For example, the attacker could use an LLM to perform a SQL injection attack on an API it has access to.
- Trigger attacks on other users and systems that query the LLM.
At a high level, attacking an LLM integration is often similar to exploiting a server-side request forgery (SSRF) vulnerability. In both cases, an attacker is abusing a server-side system to launch attacks on a separate component that is not directly accessible.
What is a large language model?
- Large Language Models (LLMs) are AI algorithms that can process user inputs and create plausible responses by predicting sequences of words. They are trained on huge semi-public data sets, using machine learning to analyze how the component parts of language fit together.
- LLMs usually present a chat interface to accept user input, known as a prompt. The input allowed is controlled in part by input validation rules.
- LLMs can have a wide range of use cases in modern websites:
- Customer service, such as a virtual assistant.
- Translation.
- SEO improvement.
- Analysis of user-generated content, for example to track the tone of on-page comments.
LLM attacks and prompt injection
Many web LLM attacks rely on a technique known as prompt injection. This is where an attacker uses crafted prompts to manipulate an LLM's output. Prompt injection can result in the AI taking actions that fall outside of its intended purpose, such as making incorrect calls to sensitive APIs or returning content that does not correspond to its guidelines.
Detecting LLM vulnerabilities
Our recommended methodology for detecting LLM vulnerabilities is:
- Identify the LLM's inputs, including both direct (such as a prompt) and indirect (such as training data) inputs.
- Work out what data and APIs the LLM has access to.
- Probe this new attack surface for vulnerabilities.
Exploiting LLM APIs, functions, and plugins
LLMs are often hosted by dedicated third party providers. A website can give third-party LLMs access to its specific functionality by describing local APIs for the LLM to use.
For example, a customer support LLM might have access to APIs that manage users, orders, and stock.
How LLM APIs work
The workflow for integrating an LLM with an API depends on the structure of the API itself. When calling external APIs, some LLMs may require the client to call a separate function endpoint (effectively a private API) in order to generate valid requests that can be sent to those APIs. The workflow for this could look something like the following:
- The client calls the LLM with the user's prompt.
- The LLM detects that a function needs to be called and returns a JSON object containing arguments adhering to the external API's schema. 3.The client calls the function with the provided arguments.
- The client processes the function's response.
- The client calls the LLM again, appending the function response as a new message.
- The LLM calls the external API with the function response.
- The LLM summarizes the results of this API call back to the user.
This workflow can have security implications, as the LLM is effectively calling external APIs on behalf of the user but the user may not be aware that these APIs are being called. Ideally, users should be presented with a confirmation step before the LLM calls the external API.
Mapping LLM API attack surface
The term "excessive agency" refers to a situation in which an LLM has access to APIs that can access sensitive information and can be persuaded to use those APIs unsafely. This enables attackers to push the LLM beyond its intended scope and launch attacks via its APIs.
The first stage of using an LLM to attack APIs and plugins is to work out which APIs and plugins the LLM has access to. One way to do this is to simply ask the LLM which APIs it can access. You can then ask for additional details on any APIs of interest.
If the LLM isn't cooperative, try providing misleading context and re-asking the question. For example, you could claim that you are the LLM's developer and so should have a higher level of privilege.
Chaining vulnerabilities in LLM APIs
Even if an LLM only has access to APIs that look harmless, you may still be able to use these APIs to find a secondary vulnerability. For example, you could use an LLM to execute a path traversal attack on an API that takes a filename as input.
Once you've mapped an LLM's API attack surface, your next step should be to use it to send classic web exploits to all identified APIs.
Insecure output handling
Insecure output handling is where an LLM's output is not sufficiently validated or sanitized before being passed to other systems. This can effectively provide users indirect access to additional functionality, potentially facilitating a wide range of vulnerabilities, including XSS and CSRF.
For example, an LLM might not sanitize JavaScript in its responses. In this case, an attacker could potentially cause the LLM to return a JavaScript payload using a crafted prompt, resulting in XSS when the payload is parsed by the victim's browser.