Manuscript Offprint
arXiv:2608.27172X-WAD: eXplainable Web Anomaly Detection
This is the author's version of an article accepted for publication at the 2026 International Conference on Artificial Intelligence Models and Systems (iAIMS 2026). The source code associated with this project is available at https://github.com/mattebit/x-wad.
X-WAD: eXplainable Web Anomaly Detection
Matteo Bitussi, Roberto Doriguzzi-Corin
Center for Cybersecurity, Fondazione Bruno Kessler, Italy
Abstract—The rapid growth of web-based services, particularly API-driven architectures, reflects an increasing reliance on distributed systems, exposing sensitive data to security risks and making the adoption of automated defensive mechanisms essential. In this context, where benign traffic predominates in real-world settings, modern defenses increasingly model normal behavior, relying on semi-supervised approaches trained on only normal data. However, ensuring the complete absence of anomalous instances in such training data is inherently difficult in practice, and mislabeled or contaminated attack samples can introduce backdoors into the learned defense, causing the model to silently misclassify certain attack patterns as normal behavior. This paper investigates the effectiveness of Transformer-based Language Models (TLMs) in detecting anomalies in HTTP requests, focusing on providing detailed explanations for the detected anomalies. The study employs token-level logit-based surprisal mapping to provide both an anomaly score and a direct, detailed explanation via a heatmap-like highlighting. The effectiveness of the proposed explainability approach is demonstrated by the discovery of labeling inconsistencies in a popular public dataset, revealing how anomalous contamination in the training data had induced backdoor-like failures in the detection models.
Index Terms—Explainability, Anomaly Detection, Web Security, Transformer Language Models
Recent work has explored the use of Transformer-based Language Models (TLMs) for anomaly detection in HTTP data. These approaches can be broadly categorized into four groups: feature extraction [2], classification [3], prediction-or reconstruction-based methods [4], [5], and prompting [6]. Among these, prediction- and reconstruction-based approaches are particularly aligned with the normality modeling paradigm, as they learn the distribution of benign traffic and identify deviations through token-level probabilities. Although TLM-based methods have proven effective, their complexity limits interpretability, which is crucial for practical deployment in security contexts, where analysts must understand the rationale behind detections to effectively investigate and respond to misclassifications, including backdoor-like behaviors.
To improve interpretability, we propose X-WAD (eXplainable Web Anomaly Detection), an explainability tool that leverages token-level scores derived from output logits of TLM-based anomaly detectors to provide fine-grained explanations of anomalous inputs. X-WAD has been conceived to support security analysts in investigating flagged inputs by highlighting the specific parts of a request that contribute most to its classification, thereby improving transparency and trust in the detection outcomes.
In this work, we first assess the effectiveness of semi-supervised TLMs for anomaly detection in HTTP requests. We compare two architectural paradigms: unidirectional models (Causal Language Modeling (CLM) with SmolLM2 model with 360 million parameters (SmolLM2-360M) [7]) for prediction-based detection, and bidirectional models (Masked Language Modeling (MLM) with ModernBERT model (ModernBERT-large) [8]) for reconstruction-based detection. Evaluation is conducted on the SR-BH2020 dataset (SR-BH2020) [9] dataset. SR-BH2020 is one of the few available datasets specifically dedicated to HTTP attack detection on a single server. It is widely recognized in the literature and frequently employed as a benchmark across various studies [10]–[15]. While both paradigms achieve strong anomaly detection performance, their complexity limits interpretability, making it difficult to understand the rationale behind their decisions, particularly in cases of misclassification.
X-WAD overcomes this limitation by mapping output logits to token-level surprisal scores, quantifying how unexpected each token is under the learned distribution of normal data. This enables a heatmap-like visualization that highlights the parts of a request contributing most to its classification.
This explainability mechanism enables deeper inspection of model behavior and reveals an important practical issue: contamination in training data. In particular, our analysis uncovers labeling inconsistencies in the SR-BH2020 dataset, showing how anomalous samples included in the training set can induce backdoor-like failures in detection models. We assess these inconsistencies and provide a corrected version of the dataset. The list of identified inconsistencies in SR-BH2020 and the source code of X-WAD are publicly available to facilitate further research and ensure reproducibility [16].
© 2026 IEEE. Personal use of this material is permitted. Permission from IEEE must be obtained for all other uses, in any current or future media, including reprinting/republishing this material for advertising or promotional purposes, creating new collective works, for resale or redistribution to servers or lists, or reuse of any copyrighted component of this work in other works
This is the author's version of an article accepted for publication at the 2026 International Conference on Artificial Intelligence Models and Systems (iAIMS 2026). The source code associated with this project is available at https://github.com/mattebit/x-wad.
II. RELATED WORK
Given the scale and complexity of TLMs and other deep learning models, interpreting their predictions remains a significant challenge. The task of understanding how a model reaches a specific decision for a given input is commonly referred to as Explainable Artificial Intelligence (XAI). Explainability plays a critical role in practical deployments: it enhances trust in model outputs, supports error analysis and model refinement, and facilitates the identification and mitigation of potential biases. Consequently, XAI has emerged as a highly active research area, encompassing a wide range of methodological approaches [17]. The most prominent categories are summarized below.
• Feature attribution methods: These approaches adopt a black-box perspective by systematically perturbing the input—e.g., masking or removing tokens—and observing the resulting changes in model output. The magnitude of these changes is used to assign importance scores to input components. A widely used method is SHapley Additive exPlanations (SHAP), which leverages concepts from cooperative game theory to estimate feature contributions. While model-agnostic and broadly applicable to TLMs, these methods are often computationally intensive due to the large number of required evaluations. [18], [19] Moreover, recent studies have raised concerns about the reliability of SHAP explanations, particularly in the context of anomaly detection, where the model's sensitivity to input changes may not accurately reflect its internal reasoning [20], [21].
• Attention-based methods: These techniques follow a white-box approach by exploiting the internal structure of transformer models. Specifically, they analyze attention weights, which quantify the interactions between tokens within a sequence. Visualization through attention heatmaps provides intuitive insights into token relationships during processing. However, it has been argued that attention weights do not always faithfully reflect the model's underlying decision-making process [22].
• Self-explaining methods: These approaches generate natural language explanations to justify model predictions. A prominent example is Chain-of-Thought (CoT) prompting, where the model produces step-by-step reasoning prior to the final output. Although such explanations are highly interpretable for humans, they may suffer from unfaithfulness, whereby the generated reasoning does not accurately correspond to the model's internal computations [23].
In the context of explainable anomaly detection, a few recent works have explored the application of TLMs with a focus on XAI; all of the following works fall into the feature-attribution category.
Sec2vec [2] addresses anomaly detection in HTTP traffic by comparing Robustly Optimized BERT Pretraining Approach (RoBERTa) with alternative vectorization techniques for feature extraction from textual request representations. A random forest classifier is then trained exclusively on normal samples. For explainability, the authors employ SHAP to estimate token-level importance.
HTTP2vec [24] systematically removes individual tokens, generates new embeddings for the altered request, and compares the resulting anomaly scores against the original to isolate each token's influence. By removing tokens, there is a risk of creating malformed requests, causing the model trained on structurally correct data to potentially mislead the removal for a structural anomaly. Furthermore, removing only one token may leave a sufficient subset of the malicious syntax intact, keeping the anomaly score high. Consequently, the method underestimates the contribution of individual tokens that are part of a correlated structure, which may lead to incorrect feature importance scores.
ADALog [25] operates directly on unstructured log data, capturing intra-log contextual relationships and applying adaptive thresholding to normal samples. The method employs a transformer-based bidirectional encoder trained with MLM and fine-tuned on benign logs. Anomalies are identified via token-level reconstruction probabilities, while interpretability is achieved through token-position analysis. Although its explainability approach is similar to that of this paper, ADALog proposes a dataset-level heatmap by aggregating patterns across many logs to show macroscopic trends in anomaly positions. However, this does not provide fine-grained explainability for a single sample to explain why it was flagged as anomalous.
Our method falls under the feature-attribution category; however, because we frame the anomaly detection task such that the output logits directly reflect model confidence, we can leverage these precalculated values for the input sample to obtain an explanation. Unlike HTTP2vec or SHAP-based methods (Sec2Vec), X-WAD's approach incurs virtually no additional computational cost, as the output logits used for explainability are already computed when deriving the anomaly score.
III. Threat Model
The threat model considered in this work assumes a web application exposed to the Internet, where adversaries interact with the system exclusively through HTTP requests. Attackers are modeled as external entities capable of crafting arbitrary request payloads to exploit input-validation weaknesses and application-logic flaws. The threat landscape includes a wide range of web-based attacks, such as injection attacks (e.g., SQL, command, and code injection), dictionary-based attacks, and path traversal. The model assumes that attacks are embedded within otherwise legitimate-looking traffic and may exhibit significant variability, including previously unseen (zero-day) patterns. Consequently, the detection approach must rely on learning the normal behavior of HTTP requests and identifying deviations from it, rather than depending on predefined signatures.
© 2026 IEEE. Personal use of this material is permitted. Permission from IEEE must be obtained for all other uses, in any current or future media, including reprinting/republishing this material for advertising or promotional purposes, creating new collective works, for resale or redistribution to servers or lists, or reuse of any copyrighted component of this work in other works
This is the author's version of an article accepted for publication at the 2026 International Conference on Artificial Intelligence Models and Systems (iAIMS 2026). The source code associated with this project is available at https://github.com/mattebit/x-wad.

Fig. 1. Inference pipeline.
IV. METHODOLOGY
The scale and high dimensionality of TLMs make their predictions inherently difficult to interpret. The methods implemented in X-WAD assign anomaly scores at the token level by highlighting segments of an HTTP request according to their contribution to the model's decision. Anomalous tokens are visually distinguished from normal ones through a color-encoded representation, enabling intuitive and fine-grained inspection of the model's behavior. Notably, the proposed method is derived directly from the output logit distributions, thereby avoiding the need for additional inference steps that are usually required when using SHAP [2] or other feature attribution methods [24].
The workflow of X-WAD is illustrated in Figure 1. The diagram depicts the inference process, assuming a TLM Anomaly Detection Model that has been trained exclusively on benign data. The key idea is that the model learns the distribution of normal HTTP requests during training; consequently, any significant deviation from this learned distribution at inference time is flagged as anomalous. As represented in the figure, the output logits produced by the TLM are directly leveraged to implement the Explainability Process.
A. Inference
The inference process varies depending on the model and its underlying task.
The CLM generates text in an autoregressive manner, meaning that each token is predicted based only on the tokens that precede it. This is implemented in a single forward pass using the same computations as during training, but without updating the model parameters. A causal (lower-triangular) attention mask ensures that each position can attend only to earlier tokens, enforcing the left-to-right dependency structure. Concretely, the model is given an input sequence and produces, for each position, a probability distribution over the next token. During training, the target sequence is defined as the input shifted by one position, so that each token prediction is aligned with its true next token. The prediction quality is measured at the token level using the cross-entropy between the predicted distributions and the corresponding target tokens.
In contrast, MLM operates by masking one or more tokens within the input sequence and training the model to reconstruct them. Thanks to bidirectional attention, the model can use both left and right context to predict each masked token. At inference time, the process mirrors training: the model takes a tokenized input with masked positions and outputs probability distributions over the masked tokens, which can be compared to the true values using cross-entropy.
However, estimating token likelihoods is less straightforward than in autoregressive models. Since each token must be predicted without seeing itself, it needs to be masked at least once. To achieve this efficiently, a strided masking strategy is used: multiple inference passes are performed on the same input, each time masking a different subset of tokens. The stride parameter s controls how token masking is distributed across multiple inference passes. Instead of masking one token at a time (which would be computationally expensive), the sequence is processed s times, each time masking a different subset of tokens spaced s positions apart. In this way, multiple tokens are predicted in parallel during each pass, while ensuring that every token is masked, and therefore evaluated, exactly once across all passes. The value of s determines the trade-off between efficiency and accuracy: smaller values allow more tokens to be processed per pass (faster computation), while larger values reduce interactions between masked tokens (more precise estimates). In this work, s = 5 is used as a practical compromise between speed and precision.
Regardless of the task used, the model ultimately produces output logits for each token (step (1) in the figure), which X-WAD uses to provide explanations by highlighting anomalous tokens and to calculate the anomaly score by averaging the per-token loss values.
© 2026 IEEE. Personal use of this material is permitted. Permission from IEEE must be obtained for all other uses, in any current or future media, including reprinting/republishing this material for advertising or promotional purposes, creating new collective works, for resale or redistribution to servers or lists, or reuse of any copyrighted component of this work in other works
This is the author's version of an article accepted for publication at the 2026 International Conference on Artificial Intelligence Models and Systems (iAIMS 2026). The source code associated with this project is available at https://github.com/mattebit/x-wad.
B. Explainability
The per-token loss is calculated from the output logits using the cross-entropy loss function (step (2)). The model's assigned probability for each target token is then recovered using the relationship (step (3)). The resulting per-token probability list is what is used to color the original sample tokens. A low predicted probability, correlated to a high cross-entropy loss, means that a specific token is unexpected within the given context based on the underlying (benign) data distribution learned during training. Therefore, the model interprets the presence of this token as an anomaly. The visualization employs a color gradient to represent probability levels, ranging from lowest (purple) to highest (no color) (step (5)). The probability value of each token is mapped to a color intensity value that ranges from 0 to 255. This approach adapts to the specific probability distribution of each model and sample, highlighting rare events relative to their context.
GET /blog/index.php/wp-json/oembed/1.0/embed?format=xml& url=http%3A%2F%2Ftest-site.com%2Fblog%2Findex.php%2F vitae-dolores-quidem-possimus-aut-voluptatibus%2F HTTP /1.1[r][n]Host: test-site.com[r][n]User-Agent: Mozilla /5.0 (X11; Linux x86_64; rv:70.0) Gecko/20100101 Firefox/70.0[r][n]Referer: .../.../.../.../.../... .../.../.../.../.../.../.../etc/passwd[r][n]Cookie: wordpress_test_cookie=WP+Cookie+check; wordpress_ logged_in_laefbe2f76edd740f8e362f39da3353b=rafael%7C15 95188528%7ClHi7YVFypQtuJVAqG6B4FOpz224r5frl1PP0w4JBwKX %7C05eff642e7638456de705bca89de40119bc343cb09e3b0c5737 2fe30717543b0[r][n]
Fig. 2. SR-BH2020 sample 27884 (anom.) explained with SmolLM2-360M.
An example of the result can be seen in Figure 2, where an anomalous sample is highlighted according to the per-token probabilities.
The sample is classified as anomalous primarily due to the presence of the path traversal pattern ..../etc/passwd. The anomalous nature of this observation is further supported by the pattern's location within the Referer header, representing a highly atypical placement. This visual explanation allows analysts to quickly identify the specific components of the request that contribute to its anomalous classification.
C. Anomaly Score Calculation
The anomaly score of a request is calculated using the model's output logits (step (6)). This is done by computing the average of the per-token loss values previously used for explainability: , where is the loss value of the -th token. The resulting anomaly score is compared to a precomputed threshold: if it exceeds the threshold, the request is classified as anomalous; otherwise, it is considered benign.
V. EXPERIMENTAL SETUP
A. Models
The TLMs employed in this work are ModernBERT-large [8] and SmolLM2-360M [7], which utilize MLM and CLM objectives, respectively, thereby covering both reconstructive and predictive paradigms. The two models have a comparable number of parameters (approximately 400M) and both employ a Byte-level Byte Pair Encoding tokenizer (BPE).
ModernBERT-large represents an architectural evolution of the original BERT framework [26]. It retains the MLM objective while extending the native context window to 8192 tokens. To reduce memory consumption, it incorporates rotary positional embeddings and adopts an alternating attention mechanism that combines global attention with local sliding-window attention. These design choices enable the model to achieve state-of-the-art performance while improving computational efficiency. The model comprises approximately 395 million parameters, with 28 transformer layers, a hidden size of 1024, and 16 attention heads. The maximum supported context length is 8192 tokens.
SmolLM2-360M belongs to the second generation of the SmolLM series [7]. It is a decoder-only transformer architecture comprising 32 transformer layers and a hidden size of 960. The model is available in three configurations with 135M, 360M, and 1.7B parameters. In this work, we consider the 360M-parameter variant. The maximum context window supported by SmolLM2-360M is 2048 tokens.
B. SR-BH2020 dataset
The SR-BH2020 dataset from the work of Riera et al. [9] is a collection of HTTP requests gathered from a WordPress web server exposed to the internet. It is one of the few available datasets specifically dedicated to HTTP attack detection on a single server. It is widely recognized in the literature and frequently employed as a benchmark across various studies [10]–[15]. The researchers manually and semi-automatically reviewed the tagging performed by a ModSecurity Web Application Firewall (WAF) that was installed alongside the web server, eventually correcting incorrectly labeled entries. The dataset is provided as a CSV file containing 525K normal and 382K anomalous HTTP requests, along with a binary label (benign/anomalous) and the Common Attack Pattern Enumeration and Classification (CAPEC) class for anomalous requests. A complete overview of the classes of the anomalous samples in the dataset can be found in Table I.
As shown in the table, the dataset is unbalanced, with the majority of samples belonging to the normal class. The anomalous samples are distributed across 11 different classes, with varying frequencies. The dataset is also highly unbalanced in terms of the number of samples per class, with some classes having significantly more samples than others.
In the CSV file, each HTTP request is split into different components, such as the method, path, headers, and body (along with other less relevant fields). For the purposes of this work, we concatenate these components into a single string representing the entire HTTP request, which is then used as input to the models.
Although the dataset contains the response code and message generated by the web server for each HTTP request, we excluded this information from the training data to avoid introducing bias into the model.
© 2026 IEEE. Personal use of this material is permitted. Permission from IEEE must be obtained for all other uses, in any current or future media, including reprinting/republishing this material for advertising or promotional purposes, creating new collective works, for resale or redistribution to servers or lists, or reuse of any copyrighted component of this work in other works
This is the author's version of an article accepted for publication at the 2026 International Conference on Artificial Intelligence Models and Systems (iAIMS 2026). The source code associated with this project is available at https://github.com/matthebit/x-wad.
TABLE I SR-BH2020 CAPEC CLASS SAMPLE DISTRIBUTION.
| CAPEC class | Description | Samples | % |
|---|---|---|---|
| Normal | Benign HTTP requests | 525,193 | 57.85 |
| 66 - SQL Injection | Injection of crafted input into SQL queries to execute unintended database operations | 249,100 | 27.44 |
| 194 - Fake the Source of Data | The attacker spoofs request origin (e.g., via headers) to appear as a trusted source | 55,983 | 6.17 |
| 34 - HTTP Response Splitting | Injection of control chars to split one HTTP response into multiple malicious responses | 19,668 | 2.17 |
| 126 - Path Traversal | Access to restricted files by exploiting poor input validation (e.g., using „./”) | 17,762 | 1.96 |
| 242 - Code Injection | Injection of malicious code into the application | 15,805 | 1.74 |
| 272 - Protocol Manipulation | The attacker manipulates the protocol to achieve unauthorized access | 9,153 | 1.01 |
| 88 - OS Command Injection | Execution of malicious code on the server leveraging input validation flaws | 6,150 | 0.68 |
| 274 - HTTP Verb Tampering | Modification of HTTP methods to bypass access controls | 4,055 | 0.45 |
| 310 - Scanning for Vulnerable SW | The attacker probes the server to identify software versions and known vulnerabilities | 2,415 | 0.27 |
| 153 - Input Data Manipulation | Alteration of input structure or format to exploit system weaknesses | 1,387 | 0.15 |
| 16 - Dictionary-based Password Attack | Brute-force login attempts using common password lists | 1,142 | 0.13 |
C. Training
The training and validation sets are composed exclusively of normal samples, accounting for 70% and 20% of the normal data, respectively. The test set consists of the remaining 10% of normal samples combined with all anomalous samples. A batch size of 50 is used for ModernBERT-large and 12 for SmolLM2-360M, with values chosen to maximize the utilization of the available VRAM on an NVIDIA RTX 3090 GPU. Due to memory constraints, gradient accumulation steps are employed to stabilize the training process. Early stopping is applied based on validation loss, halting training when performance on the validation set begins to degrade.
Additional implementation details differ across experiments but do not impact the explainability analysis. A complete specification of all training parameters is provided in the accompanying code repository [16].
D. Anomaly threshold tuning
As described in Section IV-C, samples whose anomaly score exceeds a threshold are classified as anomalous. The threshold is estimated using a Z-score approach, defined as , where and are the mean and standard deviation of the anomaly scores computed on the validation set, respectively, while k is a tuning parameter used to calibrate the threshold according to the characteristics of the dataset.

Fig. 3. FPR on the validation set at different values of .
The optimal value of is determined by evaluating the False Positive Rate (FPR) on the validation set (only benign samples) over a range of candidate values (Figure 3). Experimental results show that corresponds to the point at which the FPR begins to stabilize, providing a balanced operating point between sensitivity and robustness. In particular, larger values of would further reduce the FPR, but at the cost of increasing the False Negative Rate (FNR) at runtime, potentially causing malicious samples to remain undetected.
Figure 4 shows the anomaly threshold applied to the PDF obtained with the two models on the validation set.

Fig. 4. PDFs of the loss values on the original Validation Set.
E. Evaluation
The two TLM models are evaluated on the test set of SR-BH2020 using the estimated anomaly detection threshold. The evaluation is performed on unseen data, i.e., data not used during training or validation, to ensure an unbiased assessment of the models' generalization capabilities. The test set includes both benign (negative class) and anomalous samples (positive class), and is unbalanced toward the positive class, as it
© 2026 IEEE. Personal use of this material is permitted. Permission from IEEE must be obtained for all other uses, in any current or future media, including reprinting/republishing this material for advertising or promotional purposes, creating new collective works, for resale or redistribution to servers or lists, or reuse of any copyrighted component of this work in other works
This is the author's version of an article accepted for publication at the 2026 International Conference on Artificial Intelligence Models and Systems (iAIMS 2026). The source code associated with this project is available at https://github.com/matthebit/x-wad.
contains all the anomalous samples of the dataset (382K) and only a fraction of the benign samples (around 52K).
The model is evaluated using the following metrics:
False Positive Rate (FPR) or False Alarm Rate: The proportion of benign samples that are incorrectly classified as malicious.
False Negative Rate (FNR) or Miss Rate: The proportion of malicious samples that are incorrectly classified as benign.
Recall (True Positive Rate (TPR) or Sensitivity): The proportion of samples that have been correctly classified as malicious over all the samples that are actually malicious. TPR is useful when dealing with unbalanced datasets where the positive samples are fewer than the negative ones, as it focuses only on them.
Precision (Positive Predictive Value (PPV)): The proportion of samples correctly classified as malicious among all samples classified as positive, including both correct and incorrect positive predictions. Precision is particularly important in scenarios where the cost of false positives is high, as it measures the accuracy of the positive predictions made by the model. In the context of anomaly detection, a high precision indicates that when the model flags a request as anomalous, it is likely to be correct, which is crucial for minimizing false alarms and ensuring that security analysts can focus on genuine threats.
F1 score: F1 score is the harmonic mean of Precision and Recall. It can be expressed as:
The F1 score is a key metric when dealing with unbalanced datasets, as it provides a single measure that balances the trade-off between Precision and Recall. A high F1 score indicates that the model is effective at identifying true positives while minimizing false alarms.
VI. RESULTS
This section presents the experimental workflow adopted to evaluate X-WAD and analyze the impact of training data quality on anomaly detection performance. We begin by training and evaluating two TLM models (SmolLM2-360M and ModernBERT-large) on the original SR-BH2020 dataset, defining a statistically grounded decision threshold based on the distribution of validation losses, and highlighting limitations through test-time performance. We then leverage X-WAD to investigate model failures, revealing labeling inconsistencies and anomalous contamination in the training data.
A. Model evaluation on the SR-BH2020 dataset
The models are then evaluated on the test set using the thresholding procedure described in Section V, and the resulting performance metrics are summarized in Table II. Both models show an unexpectedly high FNR: 23.96% for ModernBERT-large and 14.82% for SmolLM2-360M. Such values indicate that a portion of malicious requests remains undetected, undermining the practical reliability of both approaches. Extensive tuning of the training hyperparameters, including learning rates, batch sizes, and regularization strategies, did not yield meaningful reductions in the FNR.
TABLE II TEST SET PERFORMANCE ON THE ORIGINAL DATASET.
| Model | F1 | FNR | FPR |
|---|---|---|---|
| ModernBERT-large | 86.16% | 23.96% | 1.68% |
| SmolLM2-360M | 91.31% | 14.82% | 5.05% |
B. Explainability and dataset fixing
To investigate the causes of the high misclassification rate, we applied X-WAD to analyze the false negative samples. The resulting explanations revealed that the models systematically failed to identify clear attack patterns as anomalous.
A representative example is sample 298021, whose explanations are reported in Figure 5. Both models, particularly ModernBERT-large, assign low (close to zero) anomaly scores to the substring %7C%7Ccat+%2Fetc%2Fpasswd, despite it being a well-known indicator of a command injection attack attempt, albeit in a malformed form given its position in the URI path.
GET /blog%7C%7Ccat+%2Fetc%2Fpasswd/wp-login.php?loggedout= → true HTTP/1.1[r][n]Host: test-site.com[r][n]User-Agent → : Mozilla/5.0 (X11; Linux x86_64; rv:70.0) Gecko/201 → 00101 Firefox/70.0[r][n
GET /blog%7C%7Ccat+%2Fetc%2Fpasswd/wp-login.php?loggedout= → true HTTP/1.1[r][n]Host: test-site.com[r][n]User-Agent → : Mozilla/5.0 (X11; Linux x86_64; rv:70.0) Gecko/20100 → 101 Firefox/70.0[r][n]
Fig. 5. Sample 298021 explained by ModernBERT-large (top) and SmolLM2-360M (bottom), both fine-tuned on SR-BH2020.
This behavior suggests that such patterns have been incorporated into the learned notion of normality. A plausible explanation is that similar attack patterns are present in the training data labeled as benign. To verify this hypothesis, we searched for these patterns within the dataset and found that they appear not only in anomalous samples but also in a substantial number of samples labeled as normal. This observation indicates the presence of labeling inconsistencies.
Building on this insight, we systematically identified attack patterns from false negative samples using our explainability tool and searched for their occurrences within the subset of samples labeled as normal. This analysis revealed that approximately 13.8% of the dataset is mislabeled, confirming that contamination in the training data significantly contributed to the observed degradation in detection performance.
Based on these findings, we created a revised version of the dataset with corrected labels, denoted as Fixed SR-BH2020 dataset (SR-BH2020-fix). The correction procedure involved reclassifying normal samples as anomalous if they exhibited the identified attack patterns.
To ensure the validity of this approach, a subset of the modified samples was manually inspected; however, due to the large scale of the dataset, exhaustive verification was not feasible. Consequently, some benign samples may have been
© 2026 IEEE. Personal use of this material is permitted. Permission from IEEE must be obtained for all other uses, in any current or future media, including reprinting/republishing this material for advertising or promotional purposes, creating new collective works, for resale or redistribution to servers or lists, or reuse of any copyrighted component of this work in other works
This is the author's version of an article accepted for publication at the 2026 International Conference on Artificial Intelligence Models and Systems (iAIMS 2026). The source code associated with this project is available at https://github.com/matthebit/x-wad.

Fig. 6. PDFs of the loss values on the fixed Validation Set.
incorrectly relabeled as anomalous. This may increase the number of false positives produced by the anomaly detector; however, unlike false negatives, which can introduce subtle backdoor-like behaviors in the model, such errors are explicitly exposed to the operator and can be further analyzed. These samples can be corrected and incorporated into subsequent training iterations, enabling iterative refinement of the model.
The resulting SR-BH2020-fix dataset was used to retrain the two models using the same method described above. The distribution of the predictions on the validation set from the fixed dataset is shown in Figure 6. The distribution of prediction losses on the normal validation set reveals a clear contrast in model behavior before and after dataset correction, particularly for ModernBERT-large, where the model trained on the mislabeled dataset had a long convergence time (18 hours) and produced a PDF with an anomalous concentration of near-zero losses. This behavior suggests that the model overfit to the training distribution, memorizing specific data points to overcome the contradictory signals introduced by mislabeling. In contrast, training on SR-BH2020-fix required only 4 hours and 30 minutes, resulting in a loss PDF characterized by a wider, more continuous spread. This reduced training time prevents the model from overfitting to individual samples, allowing it to capture the underlying, generalizable patterns in the data. Consequently, the broader dispersion of losses in the corrected model more accurately reflects the natural variance expected within the normal class, confirming a shift from detrimental memorization to healthy generalization.
C. Model evaluation on fixed dataset
The results on the revised dataset are reported in Table III. Both models show a substantial improvement in detection performance, as reflected by the increase in F1 score and the marked reduction in FNR. In particular, the F1 score reaches 98.29% for ModernBERT-large and 98.84% for SmolLM2-360M, while the FNR decreases from around 24% and 15% on the original dataset to 3.02% and 2.12%, respectively.
TABLE III TEST SET PERFORMANCE ON THE REVISED DATASET.
| Model | F1 | FNR | FPR |
|---|---|---|---|
| ModernBERT-large | 98.29% | 3.02% | 2.29% |
| SmolLM2-360M | 98.84% | 2.12% | 1.10% |
Figure 7 further illustrates the reduction in FNR across 10 of the 11 CAPEC classes, namely those that exhibited a non-zero FNR in the original dataset for both models. The comparison between the original and fixed datasets highlights consistent improvements across all categories. The only exception is the “Protocol Manipulation” class, whose residual FNR suggests that some attack patterns within this class may not have been fully captured during the dataset refinement process.

Fig. 7. FNR on SR-BH2020 and SR-BH2020-fix.
To confirm these findings, we reevaluate sample 298021 using models trained on the SR-BH2020-fix dataset. The results are presented in Figure 8.
Both models correctly identify the pattern as anomalous, assigning high loss values to these tokens relative to their context.
While SmolLM2-360M highlights the entire anomalous sequence in solid purple, it is also more aggressive, flagging some benign tokens as anomalous. In contrast, ModernBERT-large is more selective; although it leaves parts of the anomalous pattern unhighlighted, it produces significantly fewer false positives among normal tokens. These variations are partly driven by the different tokenization vocabularies, which determine the granularity and scope of
© 2026 IEEE. Personal use of this material is permitted. Permission from IEEE must be obtained for all other uses, in any current or future media, including reprinting/republishing this material for advertising or promotional purposes, creating new collective works, for resale or redistribution to servers or lists, or reuse of any copyrighted component of this work in other works
This is the author's version of an article accepted for publication at the 2026 International Conference on Artificial Intelligence Models and Systems (iAIMS 2026). The source code associated with this project is available at https://github.com/mattebit/x-wad.
GET /blog%7C%7Ccat+%2Fetc%2Fpasswd/wp-login.php?loggedout= → true HTTP/1.1[r][n]Host: test-site.com[r][n]User-Agent → : Mozilla/5.0 (X11; Linux x86_64; rv:70.0) Gecko/ → 20100101 Firefox/70.0[r][n]
GET /blog%7C%7Ccat+%2Fetc%2Fpasswd/wp-login.php?loggedout= → true HTTP/1.1[r][n]Host: test-site.com[r][n]User-Agent → : Mozilla/5.0 (X11; Linux x86_64; rv:70.0) Gecko/ → 20100101 Firefox/70.0[r][n]
Fig. 8. Sample 298021 explained by ModernBERT-large (top) and SmolLM2-360M (bottom), both fine-tuned on SR-BH2020-fix.
the highlighted segments, and partly by differences in the underlying architectures of the models (masked and causal).
VII. Conclusions
The high FNR observed on SR-BH2020 highlights the well-known sensitivity of anomaly detection approaches based on normality modeling to contamination in the training data. Given the scale of modern datasets and the inherent difficulty of exhaustive manual verification, it is crucial to assess whether a trained model captures the intended notion of normal behavior. If such contamination remains undetected in real-world deployments, it may introduce backdoor-like behaviors into the model, whereby specific attack patterns are systematically misclassified as benign and evade detection.
X-WAD enables the interpretation of model decisions by providing insight into why a given sample is classified as anomalous or benign, thereby allowing verification of whether the model behaves as intended. As demonstrated on SR-BH2020, this facilitates the analysis of model outputs to assess whether well-known attack patterns are correctly identified as anomalous.
In our evaluation, the availability of a labeled test set allowed us to explicitly quantify performance metrics such as FNR and FPR, a condition that is not always met in real-world deployments. Nevertheless, we argue that similar validation can be achieved by applying the explainability method to randomly sampled benign-classified inputs during operation.
Although this work focused specifically on the explainability of HTTP requests, the proposed approach is generalizable to other forms of textual data. As future work, we plan to apply X-WAD to other data types, such as system logs or API calls, which are also commonly analyzed for anomaly detection. This would help verify the generalizability of the approach and potentially uncover similar issues in other datasets. Additionally, applying the tool in a real-world scenario would provide insights into its practical applicability and effectiveness in operational settings.
ACKNOWLEDGMENT
This work was supported by Ministero delle Imprese e del Made in Italy (IPCEI Cloud DM 27 giugno 2022 - IPCEI-CL-0000007) and European Union (Next Generation EU).
REFERENCES
[1] Akamai Technologies, “Digital fortresses under siege: Threats to modern application architectures,” Tech. Rep., July 2024, Accessed: January 21, 2026. [Online]. Available: https://www.akamai.com/lp/soti/securing-apps-report-2024
[2] M. Gniewkowski et al., “Sec2vec: Anomaly Detection in HTTP Traffic and Malicious URLs,” in Proc. of the 38th ACM/SIGAPP Symposium on Applied Computing, 2023.
[3] Y. E. Seyyar, A. G. Yavuz, and H. M. Ünver, “An attack detection framework based on bert and deep learning,” IEEE Access, vol. 10, pp. 68 633–68 644, 2022.
[4] H. Guo et al., “Logbert: Log anomaly detection via bert,” in Proc. of IJCNN, 2021, pp. 1–8.
[5] C.-P. Tsai et al., “AnoLLM: Large Language Models for Tabular Anomaly Detection,” in Proc. of the 13th International Conference on Learning Representations, 2025.
[6] Y. Liu et al., “Interpretable online log analysis using large language models with prompt strategies,” in Proc. of the 32nd IEEE/ACM International Conference on Program Comprehension, 2024.
[7] L. B. Allal et al., “SmolLM2: When Smol Goes Big – Data-Centric Training of a Small Language Model,” preprint arXiv:2502.02737, 2025.
[8] B. Warner et al., “Smarter, Better, Faster, Longer: A Modern Bidirectional Encoder for Fast, Memory Efficient, and Long Context Finetuning and Inference,” 2024.
[9] T. Sureda Riera et al., “SR-BH 2020 multi-label dataset,” 2022.
[10] A. Riverol et al., “Capturing the security expert knowledge in feature selection for web application attack detection,” in Proc. of the 13th Latin-American Symposium on Dependable and Secure Computing, 2024.
[11] M. T. Anh Nguyen et al., “Deep Learning in NLP for Anomalous HTTP Requests Detection,” in Proc. of CNSM, 2023.
[12] L. P. Hung et al., “IncWAD: An Incremental Learning Approach for Web Attack Detection using MLOps,” in Proc. of International Conference on Advanced Technologies for Communications (ATC), 2023.
[13] M. T. A. Nguyen et al., “Zero Trust: Deep Learning and NLP for HTTP Anomaly Detection in IDS,” IEEE JSAC, vol. 43, no. 6, pp. 2215–2229, 2025.
[14] L. Zhou et al., “E-webguard: Enhanced neural architectures for precision web attack detection,” Computers & Security, vol. 148, p. 104127, 2025.
[15] M.-H. Tran-Thi et al., “An effective unsupervised cyber attack detection on web applications using gaussian mixture model,” in Proc. of the 13th Conference on Information Technology and Its Applications, 2024.
[16] M. Bitussi, “X-wad: explainable web anomaly detection,” 2026. [Online]. Available: https://github.com/mattebit/x-wad
[17] N. Calderon et al., “On behalf of the stakeholders: Trends in nlp model interpretability in the era of llms,” in Proc. of Conference of the Nations of the Americas Chapter of the Association for Computational Linguistics: Human Language Technologies, 2025.
[18] Y. Wang, “A comparative analysis of model agnostic techniques for explainable artificial intelligence,” Research Reports on Computer Science, pp. 25–33, 2024.
[19] H. Wang et al., “Feature selection strategies: a comparative analysis of shap-value and importance-based methods,” Journal of Big Data, vol. 11, no. 1, p. 44, 2024.
[20] I. E. Kumar et al., “Problems with shapley-value-based explanations as feature importance measures,” in ICML, 2020.
[21] X. Huang et al., “The inadequacy of shapley values for explainability,” preprint arXiv:2302.08160, 2023.
[22] S. Jain et al., “Attention is not explanation,” in Proc. of Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1, 2019.
[23] F. Barez et al., “Chain-of-thought is not explainability,” Preprint, alphaXiv, p. v1, 2025.
[24] M. Gniewkowski et al., “HTTP2vec: Embedding of HTTP Requests for Detection of Anomalous Traffic,” preprint arXiv:2108.01763, 2021.
[25] P. Pospieszny et al., “ADALog: Adaptive Unsupervised Anomaly detection in Logs with Self-attention Masked Language Model,” in Proc. of ICMLT, 2025.
[26] J. Devlin et al., “Bert: Pre-training of deep bidirectional transformers for language understanding,” in Proc. of conference of the North American chapter of the association for computational linguistics: human language technologies, 2019.
© 2026 IEEE. Personal use of this material is permitted. Permission from IEEE must be obtained for all other uses, in any current or future media, including reprinting/republishing this material for advertising or promotional purposes, creating new collective works, for resale or redistribution to servers or lists, or reuse of any copyrighted component of this work in other works