← Back to Library

From Prompt Injections to SQL Injection Attacks: How Protected is Your LLM-Integrated Web Application?

Authors: Rodrigo Pedro, Daniel Castro, Paulo Carreira, Nuno Santos

Published: 2023-08-03

arXiv ID: 2308.01990v4

Added to Library: 2025-11-11 14:08 UTC

Red Teaming

📄 Abstract

Large Language Models (LLMs) have found widespread applications in various domains, including web applications, where they facilitate human interaction via chatbots with natural language interfaces. Internally, aided by an LLM-integration middleware such as Langchain, user prompts are translated into SQL queries used by the LLM to provide meaningful responses to users. However, unsanitized user prompts can lead to SQL injection attacks, potentially compromising the security of the database. Despite the growing interest in prompt injection vulnerabilities targeting LLMs, the specific risks of generating SQL injection attacks through prompt injections have not been extensively studied. In this paper, we present a comprehensive examination of prompt-to-SQL (P$_2$SQL) injections targeting web applications based on the Langchain framework. Using Langchain as our case study, we characterize P$_2$SQL injections, exploring their variants and impact on application security through multiple concrete examples. Furthermore, we evaluate 7 state-of-the-art LLMs, demonstrating the pervasiveness of P$_2$SQL attacks across language models. Our findings indicate that LLM-integrated applications based on Langchain are highly susceptible to P$_2$SQL injection attacks, warranting the adoption of robust defenses. To counter these attacks, we propose four effective defense techniques that can be integrated as extensions to the Langchain framework. We validate the defenses through an experimental evaluation with a real-world use case application.

🔍 Key Points

  • The paper introduces the concept of prompt-to-SQL (P$_2$SQL) injections as a specific type of vulnerability affecting LLM-integrated web applications, particularly within the Langchain framework.
  • It presents a comprehensive characterization of P$_2$SQL injections, detailing their variants and potential impact through concrete examples.
  • The authors evaluate the susceptibility of 7 state-of-the-art LLMs to P$_2$SQL attacks, highlighting the widespread nature of this security threat across different models.
  • Four robust defense techniques are proposed to mitigate the risks associated with P$_2$SQL injections, validated through experimentation with a real-world application context.

💡 Why This Paper Matters

This paper is crucial in addressing the emerging security challenges associated with LLM-integrated web applications, specifically concerning how unsanitized user inputs can lead to SQL injection vulnerabilities. By identifying and characterizing P$_2$SQL attacks, the authors provide valuable insights into the potential risks and propose practical defenses, which can significantly contribute to the safe deployment of AI technologies in web environments.

🎯 Why It's Interesting for AI Security Researchers

This paper is highly relevant to AI security researchers as it uncovers a new dimension of vulnerabilities linked to large language models and their integration into web applications. The novel findings regarding P$_2$SQL injections and the proposed defense mechanisms provide a foundation for further research and development in AI safety, encouraging the creation of more resilient systems against adversarial exploitation.

📚 Read the Full Paper