arXiv:2608.28889cs.CRAug 2026

Manuscript Offprint

arXiv:2608.28889

Enhancing Web Application Firewalls with Machine Learning for SQL Injection Detection

Lilliane Linnet Musoke, Atta Badii, Ahmed Ashlam

Abstract

Detecting SQL Injection (SQLi) attacks ranks among the most critical challenges in web application security. This research conducted a systematic literature review to identify the research gaps in this domain and responsively designed and optimised a DistilBERT-Stacked Ensemble pipeline to improve detection efficiency and robustness while reducing false-positive and false-negative rates. Comprehensive pre-processing and tokenisation were performed, DistilBERT embeddings were extracted, and machine-learning and ensemble classifiers were trained and ranked on accuracy, precision, recall and F1-score. The three best performers (Logistic Regression, XGBoost and SVM) were combined through a neural meta-learner to form a stacked ensemble. The ensemble was hardened with adversarial examples generated by the Fast Gradient Sign Method (FGSM) and tuned with Optuna. The optimised ensemble achieved 99.81% across all reported metrics, closely comparable to the strongest single model (DistilBERT-SVM, 99.82%). On the evaluation platform used in this study (Section 3.8), the ensemble classified the full test set in 0.0136s against 1.896s for DistilBERT-SVM, an approximately 140-fold reduction in measured inference latency, while retaining 99.77% accuracy under a single-step FGSM attack. The contribution is the design and validation of a SQLi detector performing with state-of-the-art accuracy at real-time speed and with demonstrated robustness to a single-step FGSM attack, rather than a marginal gain in accuracy. Sensitivity analysis further confirmed the stability of the model. These findings highlight the value of adversarial training and stacked meta-learning in building robust Web Application Firewalls (WAFs) for SQLi detection. For open validation, the dataset, test sets and models are made available at https://github.com/mlily2024/Final-project-SQL-injection-pipeline.

1. Motivation and Contribution

SQLi attacks are among the most damaging web threats: an adversary manipulates database queries to access sensitive data and compromise the underlying system (Amouei et al., 2022). As web applications grow in functionality, transaction volume and data sensitivity, the need for advanced defences becomes critical (Alsobhi & Alshareef, 2020). Web applications rely on rule-based and signature-matching systems as a first line of defence (Toprak & Yavuz, 2022), but these struggle with zero-day and obfuscated SQLi, suffer high false-positive and false-negative rates, add latency, and demand substantial compute (Lakhani et al., 2022).

Machine Learning (ML) has improved the effectiveness of Web Application Firewalls (WAFs) in detecting SQLi (Alghawazi et al., 2023): unlike static rules, ML models can learn from diverse HTTP request patterns and adapt to new threats. Deep learning and NLP models can improve detection accuracy and reduce error rates, yet challenges persist for ML-integrated WAFs (Shaheed & Kurdy, 2022): an evolving attack landscape, the accuracy/error-rate trade-off, high computational cost, interpretability, and susceptibility to adversarial attacks.

Research gap. Prior ML-WAF studies have in the main optimised for raw detection accuracy. They have rarely reported the joint trade-off between accuracy, inference latency and adversarial robustness, the three properties that jointly determine whether a detector is deployable in a real-time WAF.

Contribution. This paper proposes a DistilBERT-Stacked Ensemble that closes that gap. Contextual DistilBERT embeddings are fed into a set of ML classifiers; the top three (Logistic Regression, XGBoost, and SVM) are combined by a neural meta-learner hardened with FGSM adversarial training and tuned with Optuna. The novelty is not a raw accuracy improvement; the ensemble is closely comparable to the best single model, but the demonstration that a stacked, adversarially trained meta-learner matches top accuracy at roughly 140× lower inference latency and with quantified adversarial robustness (99.77%) makes it the more deployable choice for real-time WAFs.