# XSShield: Defending Against Stored XSS Attacks Using LLM-Based Semantic Understanding
## 3 XSShield Design
### Data Adaptor
#### 3.2.1 PDG Generator
\begin{tabular}{l l} XSS & Cross Site Scripting \\ LLM & Large Language Model \\ PDG & Program Dependence Graph \\ AST & Abstract Syntax Tree \\ CFG & Control Flow Graph \\ MCC & Matthews Correlation Coefficient \\ CSP & Content Security Policy \\ UCB & Upper Confidence Bound Bandits \\ UCB-R & Upper Confidence Bound Bandits with Weighted Randomization \\ \end{tabular} 

## Appendix A Attack Vector Calsification

**Information-Gathering Modules. ** These modules are designed to collect crucial data about the target environment, including browser fingerprints, host system details, and network configurations. Such information forms the foundation for subsequent targeted attacks and exploit customization. **Exploit Modules. ** This category focuses on leveraging known vulnerabilities in browsers, extensions, and systems to gain unauthorized access or execute arbitrary code. The integration with Metasploit enhances BeEF's exploit capabilities, allowing for more sophisticated attack chains. **Mobile and Cross-Platform Modules. ** These modules target mobile applications developed using PhoneGap (Apache Cordova), addressing the growing importance of mobile security in the current digital landscape. They enable testing of hybrid mobile applications across different platforms. **Persistence and Social Engineering Modules. ** This category combines techniques for maintaining long-term access to compromised systems with methods for manipulating users into performing actions that may compromise security. These modules highlight the critical role of human factors in cybersecurity. **Auxiliary and Support Modules. ** These modules provide supplementary functionalities that aid in the development, testing, and customization of BeEF operations. They enhance the framework's flexibility and support more complex attack scenarios. **Inter-Protocol Communication Modules. ** These modules focus on exploiting interactions between different protocols, enabling more sophisticated attack vectors that leverage the complexities of modern networked systems. ## Appendix B Prompt Template in Prompt Expander

In the Prompt Expander phase (using gradient descent method), the framework first uses initial prompts to guide the LLM in performing sequential predictions on the code in the training set (as shown in Figure 10(a)). By comparing prediction results with labels, the framework filters out code samples with discrepant predictions to form an error sample set. Subsequently, incorrectly predicted code examples are randomly extracted from the error sample set and combined with current prompts to serve as {error_string} in Figure 10(b) for generating error reasons. The framework then inputs these prompts and corresponding {[reasons]} into the framework shown in Figure 10(c), guiding the LLM to generate improved new prompts based on these inputs. Finally, both the newly generated prompts and original prompts are input into the Prompt Selector phase. Figure 11: Prompt templates in Prompt Expander. (**a**) Template for prompt evaluation. For LLM predictions, insert prompts into {[prompt]} and code into {[text]}; the LLM’s output {[predict]} will be used directly as the prediction result. (**b**) Template for gradient generation. For identifying error reasons in LLMs’ input and output, {[prompt]} is the currently used prompt, {[error_string]} is the code where prediction results do not match the labels; the output {[reason]} explains why the current prompt predicted this code incorrectly. (**c**) Template for prompt updating. For updating prompts in LLMs’ input and output, {[prompt]} is the current prompt used for prediction, {[reason]} is the reason for prediction error, {[number_of_new_prompts]} is the number of new prompts that need to be generated from this prompt; the output {[new_prompts]} represents the newly generated prompts after improving the current prompt’s errors. ## References

* (1) Foundation, O. Cross-Site Scripting (XSS). 2021.