# XSShield: Defending Against Stored XSS Attacks Using LLM-Based Semantic Understanding
## 3 XSShield Design
### Data Adaptor
#### 3.2.1 PDG Generator
\begin{table}
\begin{tabular}{l l l l l l} \hline \hline  & \multicolumn{4}{c}{**Non-Adaptor**} & \multicolumn{2}{c}{**Adaptor**} \\ \hline  & & **Correct/Total** & **Accuracy** & **Correct/Total** & **Accuracy** \\ \hline \multirow{2}{*}{Non-selector} & Malicious & 132/305 & \multirow{2}{*}{58.36\%} & 231/305 & \multirow{2}{*}{73.11\%} \\  & Benign & 224/305 & & 215/305 & \\ \hline \multirow{2}{*}{UCB} & Malicious & 163/305 & \multirow{2}{*}{59.67\%} & 224/305 & \multirow{2}{*}{77.87\%} \\  & Benign & 201/305 & & 251/305 & \\ \hline \multirow{2}{*}{UCB-R} & Malicious & 208/305 & \multirow{2}{*}{71.97\%} & 257/305 & \multirow{2}{*}{86.07\%} \\  & Benign & 231/305 & & 296/305 & \\ \hline \hline \end{tabular}
\end{table} 
Table 4: Component-wise detection accuracy analysis of the XSShield on evaluation sets. \begin{table}
\begin{tabular}{c c c c} \hline \hline  & **GPT-3.5-Turbo** & **GPT-4** & **Gemini Pro** \\ \hline Malicious & 257/305 & 272/305 & 52/305 \\ Benign & 296/305 & 295/305 & 170/305 \\ F1-score & 0.9001 & 0.9266 & 0.2112 \\ \hline \hline \end{tabular}
\end{table} 
Table 5: Performance comparison of different evaluation models within XSShield. ResultsAccording to Table 6 data, while XSShield's time overhead is not optimal, it remains within acceptable ranges and does not significantly impact users' normal browsing experience. When processing non-obfuscated malicious scripts, XSShield's performance surpasses some existing technologies and remains comparable to other similar technologies. For obfuscated malicious scripts, although XSShield's processing time slightly increases, it still outperforms some existing technologies. Regarding average processing time per file, while XSShield is not the fastest, it remains competitive compared to mainstream technologies. Considering that actual application network latency (\(\Delta\)) may be small, XSShield's practical performance may be closer to these technologies. In summary, while XSShield's processing time is slightly higher than some existing technologies in specific scenarios, its overall performance does not notably impact user experience. Given that XSShield provides stronger security guarantees and LLM-based flexibility, this slight performance trade-off is acceptable. ## 5 Discussion

### Why Choose Prompt Optimization over Fine-Tuning and Retrieval-Augmented Generation? Modern language models can be enhanced through three main approaches: fine-tuning adapts model parameters for specific tasks through additional training; Retrieval-Augmented Generation enhances model outputs by incorporating external knowledge; and prompt optimization explores semantic space through input engineering. While fine-tuning excels in specialized tasks and can achieve state-of-the-art performance, it requires significant computational resources and frequent updates to maintain effectiveness. This makes it less ideal for dynamic security environments requiring rapid adaptation. RAG systems provide comprehensive knowledge integration but may face challenges in scenarios requiring real-time reasoning beyond their knowledge base, particularly when confronting novel security threats. Prompt optimization offers distinct advantages in security contexts. First, it enables rapid adaptation to new threats without architectural modifications or extensive retraining. Second, its lightweight nature ensures low latency response while maintaining detection effectiveness. Third, it can be dynamically adjusted based on emerging threat patterns, making it particularly suitable for resource-constrained environments requiring real-time threat response. Empirical evidence suggests that well-designed prompts can achieve comparable performance to fine-tuned models in many security applications while significantly reducing computational overhead. ### Why Is Network Latency Not a Key Bottleneck for XSShield Deployment? XSShield currently performs inference by calling external LLM service APIs, which does introduce some network latency.