{"status":"ok","message-type":"work","message-version":"1.0.0","message":{"indexed":{"date-parts":[[2026,11,18]],"date-time":"2026-11-18T20:14:51Z","timestamp":1795032891658,"version":"4.10.2"},"reference-count":30,"publisher":"Springer Science and Business Media LLC","issue":"2","license":[{"start":{"date-parts":[[2025,12,5]],"date-time":"2025-12-05T00:00:00Z","timestamp":1764892800000},"content-version":"tdm","delay-in-days":0,"URL":"https:\/\/creativecommons.org\/licenses\/by\/4.0"},{"start":{"date-parts":[[2025,12,5]],"date-time":"2025-12-05T00:00:00Z","timestamp":1764892800000},"content-version":"vor","delay-in-days":0,"URL":"https:\/\/creativecommons.org\/licenses\/by\/4.0"}],"funder":[{"DOI":"10.13039\/100030993","name":"Universit\u00e0 della Svizzera italiana","doi-asserted-by":"crossref","id":[{"id":"10.13039\/100030993","id-type":"DOI","asserted-by":"crossref"}]}],"content-domain":{"domain":["link.springer.com"],"crossmark-restriction":false},"short-container-title":["Empir Software Eng"],"published-print":{"date-parts":[[2026,3]]},"abstract":"<jats:title>Abstract<\/jats:title>\n                  <jats:p>\n                    Large Language Models (LLMs) are increasingly used in software development to generate functions, such as\n                    <jats:italic>attack detectors<\/jats:italic>\n                    , that implement security requirements. A key challenge is ensuring the LLMs have enough knowledge to address specific security requirements, such as information about existing attacks. For this, we propose an approach integrating Retrieval Augmented Generation (RAG) and Self-Ranking into the LLM pipeline. RAG enhances the robustness of the output by incorporating external knowledge sources, while the Self-Ranking technique, inspired by the concept of Self-Consistency, generates multiple reasoning paths and creates ranks to select the most robust detector. Our extensive empirical study targets code generated by LLMs to detect two prevalent injection attacks in web security: Cross-Site Scripting (XSS) and SQL injection (SQLi). Results show a significant improvement in detection performance while employing RAG and Self-Ranking, with an increase of up to 71%pt (on average 37%pt) and up to 43%pt (on average 6%pt) in the F2-Score for XSS and SQLi detection, respectively.\n                  <\/jats:p>","DOI":"10.1007\/s10664-025-10743-w","type":"journal-article","created":{"date-parts":[[2025,12,5]],"date-time":"2025-12-05T07:25:24Z","timestamp":1764919524000},"update-policy":"https:\/\/doi.org\/10.1007\/springer_crossmark_policy","source":"Crossref","is-referenced-by-count":3,"title":["Evaluating and improving the robustness of security attack detectors generated by LLMs"],"prefix":"10.1007","volume":"31","author":[{"ORCID":"https:\/\/orcid.org\/0000-0002-7900-3727","authenticated-orcid":false,"given":"Samuele","family":"Pasini","sequence":"first","affiliation":[],"role":[{"vocabulary":"crossref","role":"author"}]},{"given":"Jinhan","family":"Kim","sequence":"additional","affiliation":[],"role":[{"vocabulary":"crossref","role":"author"}]},{"given":"Tommaso","family":"Aiello","sequence":"additional","affiliation":[],"role":[{"vocabulary":"crossref","role":"author"}]},{"given":"Roc\u00edo","family":"Cabrera Lozoya","sequence":"additional","affiliation":[],"role":[{"vocabulary":"crossref","role":"author"}]},{"given":"Antonino","family":"Sabetta","sequence":"additional","affiliation":[],"role":[{"vocabulary":"crossref","role":"author"}]},{"given":"Paolo","family":"Tonella","sequence":"additional","affiliation":[],"role":[{"vocabulary":"crossref","role":"author"}]}],"member":"297","published-online":{"date-parts":[[2025,12,5]]},"reference":[{"key":"10743_CR1","unstructured":"Bhatt M, Chennabasappa S, Li Y, Nikolaidis C, Song D, Wan S, Ahmad F, Aschermann C, Chen Y, Kapil D et al (2024) Cyberseceval 2: A wide-ranging cybersecurity evaluation suite for large language models. arXiv:2404.13161"},{"key":"10743_CR2","doi-asserted-by":"crossref","unstructured":"Ceccato M, Nguyen CD, Appelt D, Briand LC (2016) Sofia: An automated security oracle for black-box testing of SQL-injection vulnerabilities. In: 2016 31st IEEE\/ACM International Conference on Automated Software Engineering (ASE), pp. 167\u2013177","DOI":"10.1145\/2970276.2970343"},{"key":"10743_CR3","doi-asserted-by":"crossref","unstructured":"Chen L, Tang C, He J, Zhao H, Lan X, Li T (2022) Xss adversarial example attacks based on deep reinforcement learning. Computers & Security 120:102831. [Online]. Available: https:\/\/www.sciencedirect.com\/science\/article\/pii\/S0167404822002255","DOI":"10.1016\/j.cose.2022.102831"},{"key":"10743_CR4","unstructured":"Chen M, Tworek J, Jun H, Yuan Q, de Oliveira Pinto HP, Kaplan J, Edwards H, Burda Y, Joseph N, Brockman G, Ray A, Puri R, Krueger G, Petrov M, Khlaaf H, Sastry G, Mishkin P, Chan B, Gray S, Ryder N, Pavlov M, Power A, Kaiser L, Bavarian M, Winter C, Tillet P, Such FP, Cummings D, Plappert M, Chantzis F, Barnes E, Herbert-Voss A, Guss WH, Nichol A, Paino A, Tezak N, Tang J, Babuschkin I, Balaji S, Jain S, Saunders W, Hesse C, Carr AN, Leike J, Achiam J, Misra V, Morikawa E, Radford A, Knight M, Brundage M, Murati M, Mayer K, Welinder P, McGrew B, Amodei D, McCandlish S, Sutskever I, Zaremba W (2021) Evaluating large language models trained on code. [Online]. Available: https:\/\/arxiv.org\/abs\/2107.03374"},{"key":"10743_CR5","unstructured":"Chen M, Tworek J, Jun H, Yuan Q, Pinto HPDO, Kaplan J, Edwards H, Burda Y, Joseph N, Brockman G et al (2021) Evaluating large language models trained on code. arXiv:2107.03374"},{"key":"10743_CR6","unstructured":"Cursorai - the ai code editor (2023) https:\/\/www.cursor.com"},{"key":"10743_CR7","unstructured":"Gao Y, Xiong Y, Gao X, Jia K, Pan J, Bi Y, Dai Y, Sun J, Wang H (2023) Retrieval-augmented generation for large language models: A survey. arXiv:2312.10997"},{"key":"10743_CR8","unstructured":"GitHub (2023) Survey reveals ai\u2019s impact on the developer experience. [Online]. Available: https:\/\/github.blog\/2023-06-13-survey-reveals-ais-impact-on-the-developer-experience\/"},{"key":"10743_CR9","unstructured":"Github copilot - your ai pair programmer (2023) https:\/\/github.com\/features\/copilot"},{"key":"10743_CR10","doi-asserted-by":"crossref","unstructured":"He J, Vechev M (2023) Large language models for code: Security hardening and adversarial testing. In: Proceedings of the 2023 ACM SIGSAC Conference on Computer and Communications Security, ser. CCS \u201923. New York, NY, USA: Association for Computing Machinery, p. 1865\u20131879. [Online]. Available: https:\/\/doi.org\/10.1145\/3576915.3623175","DOI":"10.1145\/3576915.3623175"},{"key":"10743_CR11","doi-asserted-by":"crossref","unstructured":"Hydara I, Sultan ABM, Zulzalil H, Admodisastro N (2015) Current state of research on cross-site scripting (XSS) \u2013 a systematic literature review. Information and Software Technology, vol. 58, pp. 170\u2013186. [Online]. Available: https:\/\/www.sciencedirect.com\/science\/article\/pii\/S0950584914001700","DOI":"10.1016\/j.infsof.2014.07.010"},{"key":"10743_CR12","doi-asserted-by":"crossref","unstructured":"Khoury R, Avila AR, Brunelle J, Camara BM (2023) How secure is code generated by chatgpt?","DOI":"10.1109\/SMC53992.2023.10394237"},{"issue":"1","key":"10743_CR13","first-page":"26","volume":"11","author":"M Lawal","year":"2016","unstructured":"Lawal M, Sultan ABM, Shakiru AO (2016) Systematic literature review on sql injection attack. Int J Soft Comput 11(1):26\u201335","journal-title":"Int J Soft Comput"},{"key":"10743_CR14","unstructured":"Lewis P, Perez E, Piktus A, Petroni F, Karpukhin V, Goyal N, K\u00fcttler H, Lewis M, Yih W-t, Rockt\u00e4schel T, Riedel S, Kiela D (2020) Retrieval-augmented generation for knowledge-intensive nlp tasks. In: Advances in Neural Information Processing Systems, H. Larochelle, M. Ranzato, R. Hadsell, M. Balcan, and H. Lin, Eds., vol. 33. Curran Associates, Inc., pp. 9459\u20139474. [Online]. Available: https:\/\/proceedings.neurips.cc\/paper_files\/paper\/2020\/file\/6b493230205f780e1bc26945df7481e5-Paper.pdf"},{"key":"10743_CR15","doi-asserted-by":"crossref","unstructured":"Li XL, Liang P (2021) Prefix-tuning: Optimizing continuous prompts for generation. In: Proceedings of the 59th Annual Meeting of the Association for Computational Linguistics and the 11th International Joint Conference on Natural Language Processing (Volume 1: Long Papers), 2021, pp. 4582\u20134597","DOI":"10.18653\/v1\/2021.acl-long.353"},{"key":"10743_CR16","doi-asserted-by":"crossref","unstructured":"Liu NF, Lin K, Hewitt J, Paranjape A, Bevilacqua M, Petroni F, Liang P (2024) Lost in the middle: How language models use long contexts. Transactions of the Association for Computational Linguistics 12:157\u2013173. [Online]. Available: https:\/\/aclanthology.org\/2024.tacl-1.9\/","DOI":"10.1162\/tacl_a_00638"},{"key":"10743_CR17","doi-asserted-by":"crossref","unstructured":"Mousavi Z, Islam C, Moore K, Abuadbba A, Babar MA (2024) An investigation into misuse of java security apis by large language models. In: Proceedings of the 19th ACM Asia Conference on Computer and Communications Security, pp. 1299\u20131315","DOI":"10.1145\/3634737.3661134"},{"key":"10743_CR18","doi-asserted-by":"publisher","first-page":"13","DOI":"10.20982\/tqmp.04.1.p013","volume":"4","author":"N Nachar","year":"2008","unstructured":"Nachar N (2008) The mann-whitney u: a test for assessing whether two independent samples come from the same distribution. Tutorials in Quantitative Methods for Psychology 4:13\u201320","journal-title":"Tutorials in Quantitative Methods for Psychology"},{"key":"10743_CR19","unstructured":"Nair M, Sadhukhan R, Mukhopadhyay D (2023) Generating secure hardware using ChatGPT resistant to CWEs. Cryptology ePrint Archive, Paper 2023\/212, https:\/\/eprint.iacr.org\/2023\/212. [Online]. Available: https:\/\/eprint.iacr.org\/2023\/212"},{"key":"10743_CR20","unstructured":"Ouyang S, Zhang JM, Harman M, Wang M (2023) Llm is like a box of chocolates: the non-determinism of chatgpt in code generation. arXiv:2308.02828"},{"key":"10743_CR21","doi-asserted-by":"crossref","unstructured":"Perry N, Srivastava M, Kumar D, Boneh D (2023) Do users write more insecure code with ai assistants?. In: Proceedings of the 2023 ACM SIGSAC Conference on Computer and Communications Security, ser. CCS \u201923. New York, NY, USA: Association for Computing Machinery, p. 2785\u20132799. [Online]. Available: https:\/\/doi.org\/10.1145\/3576915.3623157","DOI":"10.1145\/3576915.3623157"},{"key":"10743_CR22","unstructured":"Rae JW, Borgeaud S, Cai T, Millican K, Hoffmann J, Song F, Aslanides J, Henderson S, Ring R, Young S et al (2021) Scaling language models: Methods, analysis & insights from training gopher. arXiv:2112.11446"},{"key":"10743_CR23","unstructured":"Srivastava A, Rastogi A, Rao A, Shoeb AM, Abid A, Fisch A, Brown AR, Santoro A, Gupta A, Garriga-Alonso A et al (2022) Beyond the imitation game: Quantifying and extrapolating the capabilities of language models. arXiv:2206.04615"},{"key":"10743_CR24","doi-asserted-by":"crossref","unstructured":"Stanovich KE (2012) On the distinction between rationality and intelligence: Implications for understanding individual differences in reasoning. The Oxford handbook of thinking and reasoning, pp. 343\u2013365","DOI":"10.1093\/oxfordhb\/9780199734689.013.0022"},{"key":"10743_CR25","unstructured":"Tabachnyk M, Nikolov S (2022) Ml-enhanced code completion improves developer productivity. [Online]. Available: https:\/\/research.google\/blog\/ml-enhanced-code-completion-improves-developer-productivity\/"},{"key":"10743_CR26","doi-asserted-by":"crossref","unstructured":"Tihanyi N, Bisztray T, Jain R, Ferrag MA, Cordeiro LC, Mavroeidis V (2023) The formai dataset: Generative ai in software security through the lens of formal verification. In: Proceedings of the 19th International Conference on Predictive Models and Data Analytics in Software Engineering, ser. PROMISE 2023. New York, NY, USA: Association for Computing Machinery, p. 33\u201343. [Online]. Available: https:\/\/doi.org\/10.1145\/3617555.3617874","DOI":"10.1145\/3617555.3617874"},{"key":"10743_CR27","unstructured":"Wang X, Wei J, Schuurmans D, Le QV, Chi EH, Narang S, Chowdhery A, Zhou D (2023) Self-consistency improves chain of thought reasoning in language models. In: The Eleventh International Conference on Learning Representations. [Online]. Available: https:\/\/openreview.net\/forum?id=1PL1NIMMrw"},{"key":"10743_CR28","first-page":"24824","volume":"35","author":"J Wei","year":"2022","unstructured":"Wei J, Wang X, Schuurmans D, Bosma M, Xia F, Chi E, Le QV, Zhou D et al (2022) Chain-of-thought prompting elicits reasoning in large language models. Adv Neural Inf Process Syst 35:24824\u201324837","journal-title":"Adv Neural Inf Process Syst"},{"key":"10743_CR29","unstructured":"Zhang Y, Li Y, Cui L, Cai D, Liu L, Fu T, Huang X, Zhao E, Zhang Y, Chen Y et al (2023) Siren\u2019s song in the ai ocean: a survey on hallucination in large language models. arXiv:2309.01219"},{"key":"10743_CR30","unstructured":"Zheng L, Chiang W-L, Sheng Y, Zhuang S, Wu Z, Zhuang Y, Lin Z, Li Z, Li D, Xing E, Zhang H, Gonzalez JE, Stoica I (2023) Judging LLM-as-a-judge with MT-bench and chatbot arena. In: Thirty-seventh Conference on Neural Information Processing Systems Datasets and Benchmarks Track. [Online]. Available: https:\/\/openreview.net\/forum?id=uccHPGDlao"}],"container-title":["Empirical Software Engineering"],"original-title":[],"language":"en","link":[{"URL":"https:\/\/link.springer.com\/content\/pdf\/10.1007\/s10664-025-10743-w.pdf","content-type":"application\/pdf","content-version":"vor","intended-application":"text-mining"},{"URL":"https:\/\/link.springer.com\/article\/10.1007\/s10664-025-10743-w","content-type":"text\/html","content-version":"vor","intended-application":"text-mining"},{"URL":"https:\/\/link.springer.com\/content\/pdf\/10.1007\/s10664-025-10743-w.pdf","content-type":"application\/pdf","content-version":"vor","intended-application":"similarity-checking"}],"deposited":{"date-parts":[[2026,1,14]],"date-time":"2026-01-14T04:33:54Z","timestamp":1768365234000},"score":1,"resource":{"primary":{"URL":"https:\/\/link.springer.com\/10.1007\/s10664-025-10743-w"}},"subtitle":[],"short-title":[],"issued":{"date-parts":[[2025,12,5]]},"references-count":30,"journal-issue":{"issue":"2","published-print":{"date-parts":[[2026,3]]}},"alternative-id":["10743"],"URL":"https:\/\/doi.org\/10.1007\/s10664-025-10743-w","relation":{},"ISSN":["1382-3256","1573-7616"],"issn-type":[{"value":"1382-3256","type":"print"},{"value":"1573-7616","type":"electronic"}],"subject":[],"published":{"date-parts":[[2025,12,5]]},"assertion":[{"value":"22 November 2024","order":1,"name":"received","label":"Received","group":{"name":"ArticleHistory","label":"Article History"}},{"value":"26 September 2025","order":2,"name":"accepted","label":"Accepted","group":{"name":"ArticleHistory","label":"Article History"}},{"value":"5 December 2025","order":3,"name":"first_online","label":"First Online","group":{"name":"ArticleHistory","label":"Article History"}},{"value":"The authors declare that they do not have any known relationship or competing interests that could have influenced this paper. The authors declare that the Human involved in the study for the assessment of the quality of the Generated Synthetic Dataset signed an informed consent approved by the Ethical Committee of Universit\u00e1 della Svizzera Italiana. The authors declare that their research for the current work did not involve Animals.","order":1,"name":"Ethics","group":{"name":"EthicsHeading","label":"Declarations"}},{"value":"The authors declare that they have no competing interests.","order":2,"name":"Ethics","group":{"name":"EthicsHeading","label":"Competing Interests"}},{"value":"The study involving human participants was approved by the Ethical Committee of Universit\u00e1 della Svizzera Italiana. Informed consent was obtained from all individual participants included in the study.","order":3,"name":"Ethics","group":{"name":"EthicsHeading","label":"Ethics Approval and Consent to Participate"}},{"value":"Not applicable.","order":4,"name":"Ethics","group":{"name":"EthicsHeading","label":"Consent for Publication"}}],"article-number":"35"}}