INFLUENCE OF REQUIREMENTS SPECIFICATION ON THE SECURITY AND FUNCTIONAL CORRECTNESS OF CODE GENERATED BY LANGUAGE MODELS
DOI:
https://doi.org/10.63330/sasciencesv6n2-337Keywords:
Code generation, Language models, Requirements engineering, Software securityAbstract
Language models are widely used to generate code, but the effect of the instructions they receive on the security and functionality of that code remains poorly understood. This experimental study evaluated how functional detail and explicit security requirements influence security failures and functional compliance in applications generated by these models. We compared 800 generations of Python/FastAPI applications, covering ten tasks, four specification levels and two models, with an analysis plan publicly registered before data collection. Generations were assessed through behavioral tests in isolated containers, static analysis with Bandit and Semgrep, and manual review of a sample of 80 generations. Among conclusive generations, the proportion of failures was 53.4% with a brief request, 50.3% with functional detail, 21.6% with generic security guidance and 0% in the tested cases with specific requirements; in this last level, whose prompts describe the tested defenses, 83% of generations passed all cases, with 16 partial approvals and 18 inconclusive evaluations. The differences associated with generic guidance and specific requirements were significant and held across sensitivity analyses; with specific requirements, however, functional approval fell from 99% to 90%. Generic guidance did not reach certain defenses, such as login attempt limits, and static analysis did not report the XSS and SSRF failures observed in the tests. We conclude that, under the conditions evaluated, explicitly requesting security reduced the observed failures, whereas functional detail had no demonstrated effect. A criterion correction made after data collection is reported alongside the registered result.
Downloads
References
BANDIT. Welcome to Bandit. [S.l.], [s.d.]. Disponível em: https://bandit.readthedocs.io/en/latest/. Acesso em: 4 nov. 2026.
BASIC, Enna; GIARETTA, Alberto. From vulnerabilities to remediation: a systematic literature review of LLMs in code security. arXiv:2412.15004, versão 4, 2026. Preprint. Disponível em: https://arxiv.org/abs/2412.15004v4. Acesso em: 4 nov. 2026.
COCHRAN, William G. Some methods for strengthening the common χ² tests. Biometrics, v. 10, n. 4, p. 417-451, 1954. DOI: 10.2307/3001616.
HOLM, Sture. A simple sequentially rejective multiple test procedure. Scandinavian Journal of Statistics, v. 6, n. 2, p. 65-70, 1979.
KHARMA, Mohammed et al. An empirical evaluation of LLM-generated code security across prompting methods. arXiv:2605.24298, versão 1, 2026. Preprint. Disponível em: https://arxiv.org/abs/2605.24298v1. Acesso em: 4 nov. 2026.
KHOURY, Raphaël et al. How secure is code generated by ChatGPT? In: IEEE INTERNATIONAL CONFERENCE ON SYSTEMS, MAN, AND CYBERNETICS (SMC), 2023, Oahu. Proceedings [...]. IEEE, 2023. p. 2445-2451. DOI: 10.1109/SMC53992.2023.10394237. Versão dos autores disponível em: https://arxiv.org/abs/2304.09655v2. Acesso em: 4 nov. 2026.
KITCHENHAM, Barbara A. et al. Preliminary guidelines for empirical research in software engineering. IEEE Transactions on Software Engineering, v. 28, n. 8, p. 721-734, 2002. DOI: 10.1109/TSE.2002.1027796.
MANTEL, Nathan; HAENSZEL, William. Statistical aspects of the analysis of data from retrospective studies of disease. Journal of the National Cancer Institute, v. 22, n. 4, p. 719-748, 1959. DOI: 10.1093/jnci/22.4.719.
MITRE. About CWE. [S.l.], [s.d.]. Disponível em: https://cwe.mitre.org/about/index.html. Acesso em: 4 nov. 2026.
NASA. SWE-050 - Software Requirements. Software Engineering Handbook, versão D. [S.l.], [s.d.]. Disponível em: https://swehb.nasa.gov/spaces/SWEHBVD/pages/102695421/SWE-050%2B-%2BSoftware%2BRequirements. Acesso em: 4 nov. 2026.
OWASP. Application Security Verification Standard. Versão 5.0.0. [S.l.]: OWASP, 2025. Disponível em: https://owasp.org/projects/asvs. Acesso em: 4 nov. 2026.
PATIR, Rupam et al. DualGauge: automated joint security-functionality benchmarking of specification-only code generation by LLMs and coding agents. arXiv:2511.20709, versão 3, 2026. Preprint aceito em Findings of the Association for Computational Linguistics: EMNLP 2026. Disponível em: https://arxiv.org/abs/2511.20709v3. Acesso em: 4 nov. 2026.
PEARCE, Hammond et al. Asleep at the keyboard? Assessing the security of GitHub Copilot's code contributions. In: IEEE SYMPOSIUM ON SECURITY AND PRIVACY (SP), 2022. Proceedings [...]. IEEE, 2022. p. 754-768. DOI: 10.1109/SP46214.2022.9833571. Versão dos autores disponível em: https://arxiv.org/abs/2108.09293v3. Acesso em: 4 nov. 2026.
PERRY, Neil et al. Do users write more insecure code with AI assistants? In: ACM SIGSAC CONFERENCE ON COMPUTER AND COMMUNICATIONS SECURITY, 2023. Proceedings [...]. New York: ACM, 2023. p. 2785-2799. DOI: 10.1145/3576915.3623157. Versão dos autores disponível em: https://arxiv.org/abs/2211.03622v3. Acesso em: 4 nov. 2026.
ROBINS, James; BRESLOW, Norman; GREENLAND, Sander. Estimators of the Mantel-Haenszel variance consistent in both sparse data and large-strata limiting models. Biometrics, v. 42, n. 2, p. 311-323, 1986. DOI: 10.2307/2531052.
SEMGREP. Write rules. [S.l.], [s.d.]. Disponível em: https://docs.semgrep.dev/writing-rules/overview. Acesso em: 4 nov. 2026.
TONY, Catherine et al. Prompting techniques for secure code generation: a systematic investigation. ACM Transactions on Software Engineering and Methodology, v. 34, n. 8, p. 1-53, 2025. DOI: 10.1145/3722108. Versão dos autores disponível em: https://arxiv.org/abs/2407.07064v2. Acesso em: 4 nov. 2026.
WANG, Yanlin et al. RealSec-bench: a benchmark for evaluating secure code generation in real-world repositories. In: FINDINGS OF THE ASSOCIATION FOR COMPUTATIONAL LINGUISTICS: ACL 2026, 2026, San Diego. Proceedings [...]. San Diego: Association for Computational Linguistics, 2026. p. 35866-35883. DOI: 10.18653/v1/2026.findings-acl.1786. Versão dos autores disponível em: https://arxiv.org/abs/2601.22706v1. Acesso em: 4 nov. 2026.
WILSON, Edwin B. Probable inference, the law of succession, and statistical inference. Journal of the American Statistical Association, v. 22, n. 158, p. 209-212, 1927. DOI: 10.1080/01621459.1927.10502953.
WOHLIN, Claes et al. Experimentation in software engineering. Berlin, Heidelberg: Springer, 2012. DOI: 10.1007/978-3-642-29044-2.
Downloads
Published
How to Cite
Issue
Section
License

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Autores concordam com os seguintes termos:
a) Os autores mantêm os direitos autorais e concedem à revista o direito de primeira publicação, com o trabalho simultaneamente licenciado sob a LicençaAttribution-NonCommercial-ShareAlike 4.0 International, que permite o compartilhamento do trabalho com reconhecimento da autoria e publicação inicial na Revista SAS. A licença permite o uso, a distribuição e a reprodução irrestrita, em qualquer meio, desde que devidamente citada a fonte. Essa licença permite também que outros remixem, adaptem e criem a partir do seu trabalho para fins não comerciais, desde que atribuam a você o devido crédito e que licenciem as novas criações sob termos idênticos.
b) Não cabe aos autores compensação financeira a qualquer título, por artigos ou resenhas publicados na South American Sciences.
c) Os conceitos expressos nos artigos publicados na South American Sciences são de inteira responsabilidade de seus autores.
