A Two-Stage Privacy-Aware SQL Anomaly Detector for Inline Database Defense
Abstract
Inline database defenses require mechanisms to intercept malicious attacks and performance anomalies. Conventional lexical filters lack awareness of query execution costs, while machine learning models trained on operational logs risk exposing sensitive proprietary data. This paper presents a privacy-aware SQL anomaly detector utilizing a two-phase architecture. The first phase employs deterministic screening to filter explicit SQL injection signatures and tautological constructs. For queries bypassing this phase, dynamic execution plan signals are first generated by the database optimizer. Subsequently, a deterministic pseudonymization protocol masks literal values and schema identifiers for secure telemetry and off-site analysis. The second phase utilizes an eXtreme Gradient Boosting (XGBoost) classifier operating on an 11-dimensional bipartite feature space, combining the dynamic metrics with static structural features extracted from the pseudonymized text. Experimental evaluation on a hybrid dataset of 10,972 queries demonstrates that the proposed classifier achieves an F1 score of 0.9318 and a Matthews Correlation Coefficient of 0.8609. Performance profiling indicates an algorithmic inference latency of 1.471 μs and an integrated pipeline processing time of 2.692 ms. The integration of syntax analysis and execution plan metrics provides accurate anomaly detection within the strict latency constraints required for operational database firewalls. The source code and datasets are available at https://github.com/td-aiops-research-lab/PASAD