Balancing Security and Correctness in Code Generation: An Empirical Study on Commercial Large Language Models

Large language models (LLMs) continue to be adopted for a multitude of previously manual tasks, with code generation as a prominent use. Multiple commercial models have seen wide adoption due to the accessible nature of the interface. Simple prompts can lead to working solutions that save developers time. However, the generated code has a significant challenge with maintaining security. There are no guarantees on code safety, and LLM responses can readily include known weaknesses. To address this concern, our research examines different prompt types for shaping responses from code generation tasks to produce safer outputs. The top set of common weaknesses is generated through unconditioned prompts to create vulnerable code across multiple commercial LLMs. These inputs are then paired with different contexts, roles, and identification prompts intended to improve security. Our findings show that the inclusion of appropriate guidance reduces vulnerabilities in generated code, with the choice of model having the most significant effect. Additionally, timings are presented to demonstrate the efficiency of singular requests that limit the number of model interactions.

Authors

Institutions

Publication Details

Journal
IEEE Transactions on Emerging Topics in Computational Intelligence
Published
2024-08-29
DOI
https://doi.org/10.1109/tetci.2024.3446695
Citations
9
Primary Topic
Software Engineering Research
Type
article
Field-Weighted Citation Impact
7.01

Funders

Controls
|||
ALL TIME
JAN
FEB
MAR
APR
MAY
JUN
JUL
AUG
SEP
OCT
article

Balancing Security and Correctness in Code Generation: An Empirical Study on Commercial Large Language Models

Bhaskar Prasad Rimal, Varghese Mathew Vaidyan, Gavin Black
9 citations
IEEE Transactions on Emerging Topics in Computational Intelligence
Software Engineering Research
7.01
article

Balancing Security and Correctness in Code Generation: An Empirical Study on Commercial Large Language Models

Bhaskar Prasad Rimal, Varghese Mathew Vaidyan, Gavin Black
article en
9 citations

Abstract

Large language models (LLMs) continue to be adopted for a multitude of previously manual tasks, with code generation as a prominent use. Multiple commercial models have seen wide adoption due to the accessible nature of the interface. Simple prompts can lead to working solutions that save developers time. However, the generated code has a significant challenge with maintaining security. There are no guarantees on code safety, and LLM responses can readily include known weaknesses. To address this concern, our research examines different prompt types for shaping responses from code generation tasks to produce safer outputs. The top set of common weaknesses is generated through unconditioned prompts to create vulnerable code across multiple commercial LLMs. These inputs are then paired with different contexts, roles, and identification prompts intended to improve security. Our findings show that the inclusion of appropriate guidance reduces vulnerabilities in generated code, with the choice of model having the most significant effect. Additionally, timings are presented to demonstrate the efficiency of singular requests that limit the number of model interactions.

IEEE Transactions on Emerging Topics in Computational IntelligenceVol. 9(1)
Dakota State University (US), University of Idaho (US)
University of Idaho
Openalex Percentile: Top 3%
Software Engineering Research
7.01
AI Navigator

Ask Laika to Summarize, Analyze, and Connect papers live on the map.

Summarize Papers & Methodologies

Extract key findings, datasets, and comparative methods across publications.

Benchmark Rankings & Visual Analytics

Rank top research institutions, authors, funders, topics, and journals by Field-Weighted Citation Impact (FWCI) and paper volume with instant charts.

Connect Distant Disciplines

Bridge topological clusters on the map to find hidden collaborative intersections.