Prompt-to-SQL Injections in LLM-Integrated Web Applications: Risks and Defenses

Large Language Models (LLMs) have found widespread applications in various domains, including web applications with chatbot interfaces. 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. In this paper, we present a comprehensive examination of prompt-to-SQL (<tex xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink">$\mathbf{P}_{2} \mathbf{S Q L}$</tex>) injections targeting web applications based on frameworks such as LangChain and LlamaIndex. We characterize <tex xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink">$\mathrm{P}_{2} \text{SQL}$</tex> injections, exploring their variants and impact on application security through multiple concrete examples. We evaluate seven state-of-the-art LLMs, demonstrating the risks of <tex xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink">$P_{2}$</tex> SQL attacks across language models. By employing both manual and automated methods, we discovered <tex xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink">$\mathrm{P}_{2} \text{SQL}$</tex> vulnerabilities in five real-world applications. Our findings indicate that LLMintegrated applications are highly susceptible to <tex xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink">$\mathrm{P}_{2} \text{SQL}$</tex> 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.

Authors

Institutions

Publication Details

Published
2025-04-26
DOI
https://doi.org/10.1109/icse55347.2025.00007
Citations
11
Primary Topic
Web Application Security Vulnerabilities
Type
article
Field-Weighted Citation Impact
35.71

Funders

Controls
|||
ALL TIME
JAN
FEB
MAR
APR
MAY
JUN
JUL
AUG
SEP
OCT
article

Prompt-to-SQL Injections in LLM-Integrated Web Applications: Risks and Defenses

Nuno Rebelo dos Santos, Miguel E. Coimbra, Paulo Carreira, Daniel Castro et al.
11 citations
Web Application Security Vulnerabilities
35.71
article

Prompt-to-SQL Injections in LLM-Integrated Web Applications: Risks and Defenses

Nuno Rebelo dos Santos, Miguel E. Coimbra, Paulo Carreira, Daniel Castro, Rodrigo Pedro
article en
11 citations

Abstract

Large Language Models (LLMs) have found widespread applications in various domains, including web applications with chatbot interfaces. 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. In this paper, we present a comprehensive examination of prompt-to-SQL (<tex xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink">$\mathbf{P}_{2} \mathbf{S Q L}$</tex>) injections targeting web applications based on frameworks such as LangChain and LlamaIndex. We characterize <tex xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink">$\mathrm{P}_{2} \text{SQL}$</tex> injections, exploring their variants and impact on application security through multiple concrete examples. We evaluate seven state-of-the-art LLMs, demonstrating the risks of <tex xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink">$P_{2}$</tex> SQL attacks across language models. By employing both manual and automated methods, we discovered <tex xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink">$\mathrm{P}_{2} \text{SQL}$</tex> vulnerabilities in five real-world applications. Our findings indicate that LLMintegrated applications are highly susceptible to <tex xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink">$\mathrm{P}_{2} \text{SQL}$</tex> 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.

Instituto de Engenharia de Sistemas e Computadores Investigação e Desenvolvimento (PT), University of Lisbon (PT)
Nuclear Fuel Cycle and Supply Chain
Openalex Percentile: Top 0%
Web Application Security Vulnerabilities
35.71
AI Navigator

Ask Laika to Summarize, Analyze, and Connect papers live on the map.

Summarize Papers & Methodologies

Extract key findings, datasets, and comparative methods across publications.

Benchmark Rankings & Visual Analytics

Rank top research institutions, authors, funders, topics, and journals by Field-Weighted Citation Impact (FWCI) and paper volume with instant charts.

Connect Distant Disciplines

Bridge topological clusters on the map to find hidden collaborative intersections.