TL;DR
This paper introduces Autoregression-based Injection Attacks (AIA), a novel method to exploit vulnerabilities in Text-to-SQL (Text2SQL) models. AIA successfully generates malicious SQL queries that can extract sensitive data or even delete database contents, demonstrating a significant security risk previously underestimated in these models.
What Problem Does This Paper Address?
Web applications increasingly rely on Text-to-SQL (Text2SQL) models to translate natural language queries into SQL, simplifying user interaction with databases. While this technology decouples user input from pre-written SQL, potentially mitigating traditional SQL injection risks, it introduces a new attack surface: the Text2SQL model itself. The core problem this paper addresses is the security vulnerability of Text2SQL models, specifically their susceptibility to generating malicious SQL queries when subjected to adversarial inputs. Researchers previously showed that Text2SQL models could generate SQL with injected payloads, but these attacks were often limited to simple cases or failed to maintain payloads in complex generations. This paper investigates how to effectively attack Text2SQL models to generate specific, harmful SQL outputs.
Methods
The paper proposes a novel attack framework called Autoregression-based Injection Attacks (AIA). AIA consists of two main stages:
- Injection Point Text Construction: This stage aims to create an input text that guides the Text2SQL model to generate a SQL query with a specific injection point. It leverages a common SQL injection pattern ("SELECT ... FROM ... WHERE ... = ...") and adapts it to the Text2SQL context. A key innovation here is a Column Selection method that uses a saliency metric to identify the most suitable column for inserting the adversarial payload, thereby increasing the likelihood of successful generation.
- Autoregression-based Payload Generation: This stage focuses on generating the actual adversarial payload. Since Text2SQL models generate SQL queries token by token (autoregressively), AIA uses an Adversarial Token Generation (ATG) approach. This method optimizes the input tokens iteratively, using gradient backpropagation at each step to ensure the model generates the desired target token. The loss function is carefully designed to maintain the integrity of the generated SQL query while pushing the model towards producing the malicious payload.
Datasets
The paper utilizes a dataset derived from a public SQL injection dataset from Kaggle. This dataset was curated to include both SQL injection and normal samples, resulting in 22,226 samples. The authors further refined this dataset to ensure correct syntax when used with different target models.
Key Insights and Ideas
- Text2SQL models are vulnerable to injection attacks: Contrary to the initial assumption that decoupling user input might eliminate SQL injection risks, this paper demonstrates that Text2SQL models themselves can be exploited to generate malicious SQL.
- Autoregression is key to successful attacks: By mimicking the token-by-token generation process of Text2SQL models, AIA can effectively guide the model to produce specific, harmful SQL outputs, overcoming limitations of previous methods.
- Column selection significantly improves attack success: Identifying the most "salient" column for injection is crucial for ensuring that adversarial payloads are preserved in the generated SQL, rather than being lost or misinterpreted.
- Adversarial payloads can be transferable: Payloads generated for one Text2SQL model can be effective against others, suggesting a broader threat to T5-based models and enabling black-box attacks.
- Attacks can lead to severe database damage: The paper provides concrete examples of AIA successfully extracting user lists and deleting data, highlighting the real-world security implications.
Key Results
- AIA achieved attack success rates of over 70% in most scenarios with 10-20 character payloads.
- The adversarial input generated by AIA showed about 40% transferability between target models.
- AIA successfully demonstrated the ability to make Text2SQL models extract user lists from databases and delete data directly.
- The attack success rate generally decreases with increasing payload length, a common trend in adversarial attacks.
- Ablation studies showed that the loss functions Lp and Lw play crucial roles in controlling the generation of injection point code and minimizing embedding-to-token mapping changes, respectively.
Limitations and Future Work
- Mapping from embedding to token space: The paper acknowledges that mapping adversarial examples from the embedding space back to the token space remains a challenge, particularly for LLM-based models.
- Black-box attacks: While transferability is shown, further research is needed to develop more robust black-box attack strategies.
- LLM-based methods: While AIA shows promise against LLMs, their complex nature and diverse output capabilities present ongoing challenges. The paper suggests further exploration of "Description Attacks" for LLMs.
- Defense mechanisms: The paper briefly mentions potential defenses, such as filtering user input, but notes that developing effective defenses against these sophisticated attacks is an area for future work.
Summary updated