XSShield: Defending Against Stored XSS Attacks Using LLM-Based Semantic Understanding
Source abstract
Abstract
Cross-site scripting attacks represent one of the major security threats facing web applications, with Stored XSS attacks becoming the predominant form. Compared to reflected XSS, stored XSS attack payloads exhibit temporal and spatial asynchrony between injection and execution, rendering traditional browserside defenses based on request–response differential analysis ineffective. This paper presents XSShield, the first detection framework that leverages a Large Language Model to understand JavaScript semantics to defend against Stored XSS attacks. Through a Prompt Optimizer based on gradient descent and UCB-R selection algorithms, and a Data Adaptor based on program dependence graphs, the framework achieves real-time and fine-grained code processing. Experimental evaluation shows that XSShield achieves 93% accuracy and an F1 score of 0.9266 on the GPT-4 model, improving accuracy by an average of 88.8% compared to existing solutions. The processing time, excluding model communication overhead, averages only 0.205 s, demonstrating practical deployability without significantly impacting user experience.
Source: crossref · Quality: baseline
Research context
OpenAlex topics: Web Application Security Vulnerabilities · Security and Verification in Computing · Digital and Cyber Forensics
SciVX discovery tags are terminology-based. OpenAlex topics are source-provided classifications.
Affiliations
College of Computer Science and Technology, National University of Defense Technology, No.137 Yanwachi Street, Changsha 410073, China
References (64)
Show source-provided references
1. Foundation, O. (2024, December 03). Cross-Site Scripting (XSS). Available online: https://owasp.org/www-community/attacks/xss/.
2. HackerOne (2024, December 03). 8th Annual Hacker-Powered Security Report. Available online: https://hackerpoweredsecurityreport.com/.
3. Project, C. (2024, December 03). cvelistV5. Available online: https://github.com/CVEProject/cvelistV5/.
4. Database, N.V. (2024, December 03). CVE-2023-40000, Available online: https://nvd.nist.gov/vuln/detail/CVE-2023-40000/.
5. Bing, L., and Fengyu, Z. (2013). Study and Design of Stored-XSS Vulnerability Detection. Comput. Appl. Softw., 17–21.
6. Somorovsky, J., Heiderich, M., Jensen, M., Schwenk, J., Gruschka, N., and Lo Iacono, L. (2011, January 21). All your clouds are belong to us: Security analysis of cloud management interfaces. Proceedings of the 3rd ACM Workshop on Cloud Computing Security Workshop (CCSW ‘11), New York, NY, USA.10.1145/2046660.2046664 ↗
7. Cross-Site Scripting (XSS) attacks and defense mechanisms: Classification and state-of-the-art10.1007/s13198-015-0376-0 ↗
8. Barth, A., Jackson, C., and Mitchell, J.C. (2008, January 27–31). Robust defenses for cross-site request forgery. Proceedings of the 15th ACM Conference on Computer and Communications Security, Alexandria, VA, USA.10.1145/1455770.1455782 ↗
9. Heiderich, M., Niemietz, M., Schuster, F., Holz, T., and Schwenk, J. (2012, January 16–18). Scriptless attacks: Stealing the pie without touching the sill. Proceedings of the 2012 ACM Conference on Computer and Communications Security (CCS ‘12), New York, NY, USA.10.1145/2382196.2382276 ↗
10. XSS-SAFE: A Server-Side Approach to Detect and Mitigate Cross-Site Scripting (XSS) Attacks in JavaScript Code10.1007/s13369-015-1891-7 ↗
11. Noever, D. (2023). Can Large Language Models Find and Fix Vulnerable Software?. arXiv.10.5121/ijaia.2023.14301 ↗
12. From ChatGPT to ThreatGPT: Impact of Generative AI in Cybersecurity and Privacy10.1109/ACCESS.2023.3300381 ↗
13. Ganguli, D., Lovitt, L., Kernion, J., Askell, A., Bai, Y., Kadavath, S., Mann, B., Perez, E., Schiefer, N., and Ndousse, K. (2022). Red Teaming Language Models to Reduce Harms: Methods, Scaling Behaviors, and Lessons Learned. arXiv.
14. Security foundation of deep learning: Formalization, verification, and applications10.1145/3554729 ↗
15. Roth, S., Gröber, L., Backes, M., Krombholz, K., and Stock, B. (2021, January 15–19). 12 Angry Developers—A Qualitative Study on Developers’ Struggles with CSP. Proceedings of the 2021 ACM SIGSAC Conference on Computer and Communications Security (CCS ‘21), New York, NY, USA.10.1145/3460120.3484780 ↗
16. JSCSP: A Novel Policy-Based XSS Defense Mechanism for Browsers
17. Pan, X., Cao, Y., Liu, S., Zhou, Y., Chen, Y., and Zhou, T. (2016, January 24–28). CSPAutoGen: Black-box Enforcement of Content Security Policy upon Real-world Websites. Proceedings of the 2016 ACM SIGSAC Conference on Computer and Communications Security (CCS ‘16), New York, NY, USA.10.1145/2976749.2978384 ↗
18. Alhindi, M., and Hallett, J. (2024). Sandboxing Adoption in Open Source Ecosystems. arXiv.10.1145/3643655.3643878 ↗
19. Oren, Y., Kemerlis, V.P., Sethumadhavan, S., and Keromytis, A.D. (2015). The Spy in the Sandbox—Practical Cache Attacks in JavaScript. arXiv.10.1145/2810103.2813708 ↗
20. Zamboni, D. (2008). XSS-GUARD: Precise Dynamic Prevention of Cross-Site Scripting Attacks. Detection of Intrusions and Malware, and Vulnerability Assessment, Springer.10.1007/978-3-540-70542-0 ↗
21. Bates, D., Barth, A., and Jackson, C. (2010, January 26–30). Regular expressions considered harmful in client-side XSS filters. Proceedings of the 19th International Conference on World Wide Web (WWW ‘10), New York, NY, USA.10.1145/1772690.1772701 ↗
22. Pelizzi, R., and Sekar, R. (2012, January 2–4). Protection, usability and improvements in reflected XSS filters. Proceedings of the 7th ACM Symposium on Information, Computer and Communications Security (ASIACCS ‘12), New York, NY, USA.10.1145/2414456.2414458 ↗
23. XSS-immune: A Google chrome extension-based XSS defensive framework for contemporary platforms of web applications10.1002/sec.1579 ↗
24. A Framework for Preserving the Privacy of Online Users Against XSS Worms on Online Social Network10.4018/IJITWE.2019010105 ↗
25. Hunting for DOM-Based XSS vulnerabilities in mobile cloud-based online social network10.1016/j.future.2017.05.038 ↗
26. Rocha, Á., Adeli, H., Reis, L.P., and Costanzo, S. (2018). XSS Attack Detection Approach Based on Scripts Features Analysis. Trends and Advances in Information Systems and Technologies, Springer.
27. XSS-secure as a service for the platforms of online social network-based multimedia web applications in cloud10.1007/s11042-016-3735-1 ↗
28. Aurore54F (2024, December 03). static-pdg-js; Licensed Under AGPL-3.0. Available online: https://github.com/Aurore54F/static-pdg-js.
29. Fast unfolding of communities in large networks10.1088/1742-5468/2008/10/P10008 ↗
30. Microsoft (2024, December 03). LMOps; Licensed Under MIT. Available online: https://github.com/microsoft/LMOps.
31. beefproject (2025, March 10). beef. Available online: https://github.com/beefproject/beef.
32. (2025, March 10). JavaScript-obfuscator. Available online: https://github.com/JavaScript-obfuscator/JavaScript-obfuscator.
33. Learning programs from noisy data10.1145/2914770.2837671 ↗
34. (2025, March 10). VirusTotal. Available online: https://www.virustotal.com/gui/home/upload.
35. HynekPetrak (2025, March 10). JavaScript Malware Collection. Available online: https://github.com/HynekPetrak/JavaScript-malware-collection.
36. geeksonsecurity (2025, March 10). Malicious JavaScript Dataset. Available online: https://github.com/geeksonsecurity/js-malicious-dataset.
37. Romano, A., Lehmann, D., Pradel, M., and Wang, W. (2022, January 22–26). Wobfuscator: Obfuscating JavaScript Malware via Opportunistic Translation to WebAssembly. Proceedings of the 2022 IEEE Symposium on Security and Privacy (SP), San Francisco, CA, USA.10.1109/SP46214.2022.9833626 ↗
38. Rieck, K., Krueger, T., and Dewald, A. (2010, January 6–10). CUJO: Efficient detection and prevention of drive-by-download attacks. Proceedings of the 26th Annual Computer Security Applications Conference, Austin, TX, USA.10.1145/1920261.1920267 ↗
39. Aurore54F (2025, March 10). lexical-jsdetector. Available online: https://github.com/Aurore54F/lexical-jsdetector.
40. Curtsinger, C., Livshits, B., Zorn, B., and Seifert, C. (2011, January 10–12). ZOZZLE: Fast and Precise In-Browser JavaScript Malware Detection. Proceedings of the USENIX Security Symposium, USENIX Security Symposium, San Francisco, CA, USA.
41. Aurore54F (2025, March 10). syntactic-jsdetector. Available online: https://github.com/Aurore54F/syntactic-jsdetector.
42. Fass, A., Backes, M., and Stock, B. (2019, January 9–13). JStap: A Static Pre-Filter for Malicious JavaScript Detection. Proceedings of the 35th Annual Computer Security Applications Conference, San Juan, Puerto Rico.10.1145/3359789.3359813 ↗
43. Aurore54F (2025, March 10). JStap. Available online: https://github.com/Aurore54F/JStap.
44. Dehghantanha, A., Yazdinejad, A., and Parizi, R.M. (2024, January 14–18). Autonomous Cybersecurity: Evolving Challenges, Emerging Opportunities, and Future Research Trajectories. Proceedings of the Workshop on Autonomous Cybersecurity (AutonomousCyber ‘24), New York, NY, USA.10.1145/3689933.3690832 ↗
45. A Robust Privacy-Preserving Federated Learning Model Against Model Poisoning Attacks10.1109/TIFS.2024.3420126 ↗
46. Jim, T., Swamy, N., and Hicks, M. (2007, January 8–12). Defeating script injection attacks with browser-enforced embedded policies. Proceedings of the 16th International Conference on World Wide Web (WWW ‘07), New York, NY, USA.10.1145/1242572.1242654 ↗
47. Gundy, M.V., and Chen, H. (2009, January 8–11). Noncespaces: Using Randomization to Enforce Information Flow Tracking and Thwart Cross-Site Scripting Attacks. Proceedings of the Network and Distributed System Security Symposium, San Diego, CA, USA.
48. Stock, B., Lekies, S., Mueller, T., Spiegel, P., and Johns, M. (2014, January 9–11). Precise client-side protection against DOM-based cross-site scripting. Proceedings of the 23rd USENIX Conference on Security Symposium (SEC’14), Anaheim, CA, USA.
49. Samuel, M., Saxena, P., and Song, D. (2011, January 17–21). Context-sensitive auto-sanitization in web templating languages using type qualifiers. Proceedings of the 18th ACM Conference on Computer and Communications Security, New York, NY, USA.10.1145/2046707.2046775 ↗
50. Atluri, V., and Diaz, C. (2011). A Systematic Analysis of XSS Sanitization in Web Application Frameworks. Computer Security—ESORICS 2011, Springer.10.1007/978-3-642-23822-2 ↗
51. Melicher, W., Das, A., Sharif, M., Bauer, L., and Jia, L. (2018, January 18–21). Riding out DOMsday: Towards Detecting and Preventing DOM Cross-Site Scripting. Proceedings of the Network and Distributed System Security Symposium, San Diego, CA, USA.10.14722/ndss.2018.23309 ↗
52. West Mike, A.B., and Veditz, D. (2025, March 09). Content Security Policy Level 2. Available online: https://www.w3.org/TR/CSP2/.
53. Agten, P., Acker, S.V., Brondsema, Y., Phung, P.H., Desmet, L., and Piessens, F. (2012, January 28–31). JSand: Complete client-side sandboxing of third-party JavaScript without browser modifications. Proceedings of the Asia-Pacific Computer Systems Architecture Conference, Matsue, Japan.10.1145/2420950.2420952 ↗
54. Kolbitsch, C., Livshits, B., Zorn, B., and Seifert, C. (2012, January 20–23). Rozzle: De-cloaking Internet Malware. Proceedings of the 2012 IEEE Symposium on Security and Privacy, San Francisco, CA, USA.10.1109/SP.2012.48 ↗
55. Giuffrida, C., Bardin, S., and Blanc, G. (2018). JaSt: Fully Syntactic Detection of Malicious (Obfuscated) JavaScript. Detection of Intrusions and Malware, and Vulnerability Assessment, Springer.10.1007/978-3-319-93411-2 ↗
56. A deep learning approach for detecting malicious JavaScript code10.1002/sec.1441 ↗
57. A machine learning approach to detection of JavaScript-based attacks using AST features and paragraph vectors10.1016/j.asoc.2019.105721 ↗
58. Shin, T., Razeghi, Y., Logan, R.L., Wallace, E., and Singh, S. (2020). AutoPrompt: Eliciting Knowledge from Language Models with Automatically Generated Prompts. arXiv.10.18653/v1/2020.emnlp-main.346 ↗
59. Gao, T., Fisch, A., and Chen, D. (2021). Making Pre-trained Language Models Better Few-shot Learners. arXiv.10.18653/v1/2021.acl-long.295 ↗
60. Schick, T., and Schütze, H. (2021). Exploiting Cloze Questions for Few Shot Text Classification and Natural Language Inference. arXiv.10.18653/v1/2021.eacl-main.20 ↗
61. Li, X.L., and Liang, P. (2021). Prefix-Tuning: Optimizing Continuous Prompts for Generation. arXiv.10.18653/v1/2021.acl-long.353 ↗
62. Brown, T.B., Mann, B., Ryder, N., Subbiah, M., Kaplan, J., Dhariwal, P., Neelakantan, A., Shyam, P., Sastry, G., and Askell, A. (2020). Language Models are Few-Shot Learners. arXiv.
63. Wu, G., Wu, W., Liu, X., Xu, K., Wan, T., and Wang, W. (2023, January 10–14). Cheap-Fake Detection with LLM Using Prompt Engineering. Proceedings of the 2023 IEEE International Conference on Multimedia and Expo Workshops (ICMEW), Brisbane, Australia.10.1109/ICMEW59549.2023.00025 ↗
64. Wang, E., Chen, J., Xie, W., Wang, C., Gao, Y., Wang, Z., Duan, H., Liu, Y., and Wang, B. (2024, January 19–23). Where URLs Become Weapons: Automated Discovery of SSRF Vulnerabilities in Web Applications. Proceedings of the 2024 IEEE Symposium on Security and Privacy (SP), San Francisco, CA, USA.10.1109/SP54263.2024.00198 ↗