Abstract
As Cross-Site Scripting (XSS) remains one of the top web security risks, people keep exploring ways to detect such attacks efficiently. So far, existing solutions only focus on the payload in a web request or a response, a single stage of a web transaction. This work proposes a new approach that integrates evidences from both a web request and its response in order to better characterize XSS attacks and separate them from normal web transactions. We first collect complete payloads of XSS and normal web transactions from two databases and extract features from them using the Word2vec technique. Next, we train two Gaussian mixture models (GMM) with these features, one for XSS transaction and one for normal web transactions. These two models can generate two probability scores for a new web transaction, which indicate how similar this web transaction is to XSS and normal traffics respectively. Finally, we put together these two GMM models in classification by combining these two probabilities to further improve detection accuracy.
1. Introduction
Cross-Site Scripting (XSS) is a persistent and severe vulnerability in web applications. Attackers exploit these vulnerabilities to inject malicious scripts into pages viewed by other users, leading to session hijacking, data theft, or site defacement. Traditional detection mechanisms, such as signature-based filters in Web Application Firewalls (WAFs), often operate on a single-stage basis—inspecting either the incoming HTTP request or the outgoing server response in isolation. However, sophisticated attacks often utilize encoding and obfuscation that may only be fully decodable or identifiable when the request and response are analyzed together as a single transaction.
2. Methodology
The proposed detection framework leverages Natural Language Processing (NLP) techniques and statistical modeling to identify XSS patterns across multiple stages of a web transaction.
2.1 Feature Extraction via Word2vec
The system treats HTML and JavaScript components as tokens in a language. Using the Word2vec Continuous Bag-of-Words (CBOW) model, these tokens are mapped into a high-dimensional vector space. This semantic mapping allows the model to recognize the functional relationships between different script elements, even when they are separated by benign text or obfuscated.
2.2 Multi-Stage Integration and GMM Modeling
The core of the approach is the integration of request and response data. By concatenating these two stages, the system creates a comprehensive "evidence chain." This data is then used to train two distinct Gaussian Mixture Models (GMMs):
- XSS Model: Focused on misuse detection by learning the patterns of known attack payloads.
- Normal Model: Focused on anomaly detection by learning the characteristics of legitimate web traffic.
Classification is performed by calculating the log-likelihood ratio of the two models: $C = \log P_{XSS} - \log P_{Normal}$. This dual-modeling approach allows the system to balance the detection of known threats with the identification of novel anomalies.
3. Experimental Setup
The researchers utilized the XSSed database (containing 45,884 attack transactions) and the Web09 dataset (containing 34,561 normal transactions) for training. Evaluation was conducted on a balanced test set of 20,000 transactions.
4. Results and Analysis
The integrated multi-stage approach significantly outperformed single-stage baselines. While models focusing solely on requests often struggled with low detection rates or high false positives, the combined model achieved near-optimal performance.
As shown in the Receiver Operating Characteristic (ROC) analysis, the system achieved an AUC of 0.994. This high level of accuracy demonstrates the effectiveness of combining request-response context with the multimodal modeling capabilities of GMMs.
5. Conclusion
This research demonstrates that integrating evidence from multiple stages of a web transaction provides a more robust defense against XSS than traditional single-stage methods. By applying NLP-based feature extraction and dual GMM classification, the system can effectively distinguish complex attacks from legitimate traffic. Future work will focus on optimizing the pipeline for real-time deployment and updating the models with contemporary attack data to address the evolving landscape of web security threats.
Summary updated