Semi-supervised method for anomaly detection in HTTP traffic

Malki Ishara Wasundara, Junwei Zhou, Yanchao Yang, Dongdong Zhao, Jianwen XiangEURASIP 2025

TL;DR

This paper introduces a semi-supervised framework that combines the contextual power of BERT with the anomaly-detection capabilities of autoencoders to secure web traffic. By training exclusively on benign HTTP requests, the model learns to identify malicious activity through reconstruction errors, achieving high detection accuracy (0.96 AUC) while providing "attention-based" insights into why a specific request was flagged.

What Problem Does This Paper Address?

Detecting malicious activity in HTTP traffic is a constant cat-and-mouse game. Traditional security measures usually fall into two camps: manual rules (like WAF signatures), which are efficient but fail to catch novel "zero-day" attacks, and supervised machine learning, which requires massive amounts of perfectly labeled data—a luxury most security teams don't have.

Furthermore, network environments suffer from concept drift, where "normal" traffic patterns evolve over time, rendering static models obsolete. The authors aim to bridge these gaps by creating a system that is:

  1. Semi-supervised: It only needs "normal" data to learn.
  2. Context-aware: It understands the semantic relationship between different parts of an HTTP request.
  3. Interpretable: It doesn't just say "this is bad"; it shows which tokens (like OR, --, or <script>) triggered the alarm.

Methods

The authors propose a two-pronged pipeline:

  1. Contextual Vectorization (BERT): Instead of using simple word counts (TF-IDF) or static embeddings (Word2Vec), they use a fine-tuned BERT model. BERT’s bidirectional nature allows it to understand the context of a token within the entire HTTP request (headers, URL, and payload). They fine-tune bert-base-uncased using a Masked Language Modeling (MLM) objective on benign traffic.
  2. Anomaly Detection (Autoencoder): The high-dimensional BERT embeddings are fed into an Autoencoder (AE). Because the AE is trained only on benign data, it becomes very good at compressing and reconstructing "normal" requests. When it encounters a malicious request (e.g., an SQL injection), the reconstruction error spikes.
  3. Sequence Reconstruction (Alternative): They also explored a lightweight Transformer encoder-decoder that attempts to reconstruct the original token sequence directly, using cross-entropy loss as the anomaly score.

To make the system production-ready, they utilized DistilBERT and FP16 quantization, which significantly reduced inference latency.

Datasets

The model was evaluated on a mix of classic and modern benchmarks:

  • CSIC2010 & UNSW-NB15: Standard datasets for web traffic and network intrusion.
  • Malicious URL & ISCX-URL-2016: Focused on lexical threats like phishing and malware links.
  • CIC-IDS2022 & AdversarialHTTP: Used to test robustness against modern API exploits and GPT-4 generated synthetic attacks.

Key Insights and Ideas

  • Context is King: Traditional models treat tokens independently. The authors found that BERT’s ability to see the "whole sentence" of an HTTP request allowed it to detect obfuscated attacks that Word2Vec missed by over 16%.
  • The "Aha" Moment of Attention: One of the most compelling features is the use of BERT’s attention heatmaps. By visualizing which token pairs the model focuses on, security analysts can see the model "zeroing in" on attack signatures like admin'-- or <script>, transforming a black-box model into a transparent tool.
  • Efficiency vs. Accuracy: The paper highlights a practical trade-off. While the full BERT-AE model is the most accurate, a DistilBERT variant with quantization offers a "sweet spot" for edge deployments, cutting latency by 40% while maintaining a 94% F1-score.

Key Results

  • Detection Performance: The model achieved an F1-score of 0.92 and an AUC of 0.96 across diverse datasets. On the CSIC2010 dataset, it reached a near-perfect 1.00 F1-score, significantly outperforming LSTM and CNN baselines.
  • Speed: Through optimization (batch inference), the system achieved a per-request latency of just 2.1 ms, making it viable for real-time network monitoring.
  • Zero-Day Robustness: In tests against emerging threats (CIC-IDS2022), the model detected 87.3% of API attacks despite never having seen them during training.

Limitations and Future Work

The authors identify a few "chinks in the armor":

  • Tokenization Gaps: The BERT tokenizer struggled with highly fragmented payloads or random Unicode characters, leading to a 15% miss rate in some adversarial scenarios.
  • Temporal Drift: While the model is resilient, it still requires periodic retraining to keep up with shifting "benign" baselines (e.g., slow-rate DDoS attacks mimicking normal users).
  • Future Directions: The team plans to investigate online learning (updating the model incrementally without full retraining) and adversarial training to better defend against attackers who specifically try to "fool" the BERT embeddings.

Summary updated

Abstract

Anomaly detection in HTTP traffic is critical for securing web applications against evolving cyber threats. We propose a semi-supervised method that combines domain-specific language modeling with sequence reconstruction to identify anomalies in HTTP requests. Our approach leverages only benign traffic for training and uses reconstruction errors for detecting malicious activity. It achieves a strong balance between precision and recall while maintaining low computational requirements, making it suitable for real-time and edge deployments. Extensive evaluations on three public HTTP datasets show that our method outperforms traditional baselines and fine-tuned BERT models, with an F1-score of 0.92 and AUC of 0.96. We also introduce a simple interpretability mechanism by attributing anomalies to token-level reconstruction errors, providing insights into detected threats. The proposed solution is scalable, lightweight, and effective across diverse attack scenarios without requiring large labeled datasets.
BibTeX
@inproceedings{wasundara2025semi,
  author = {Malki Ishara Wasundara and Junwei Zhou and Yanchao Yang and Dongdong Zhao and Jianwen Xiang},
  title = {{Semi-supervised method for anomaly detection in HTTP traffic}},
  booktitle = {EURASIP},
  year = {2025},
  doi = {10.1186/s13635-025-00210-w},
}
Figure