Prompting Techniques for Secure Code Generation: A Systematic Investigation
Tony, Catherine, Ferreyra, Nicolás E. Díaz, Mutas, Markus, Dhiff, Salem, Scandariato, Riccardo
–arXiv.org Artificial Intelligence
Large Language Models (LLMs) are gaining momentum in software development with prompt-driven programming enabling developers to create code from natural language (NL) instructions. However, studies have questioned their ability to produce secure code and, thereby, the quality of prompt-generated software. Alongside, various prompting techniques that carefully tailor prompts have emerged to elicit optimal responses from LLMs. Still, the interplay between such prompting strategies and secure code generation remains under-explored and calls for further investigations. OBJECTIVE: In this study, we investigate the impact of different prompting techniques on the security of code generated from NL instructions by LLMs. METHOD: First we perform a systematic literature review to identify the existing prompting techniques that can be used for code generation tasks. A subset of these techniques are evaluated on GPT-3, GPT-3.5, and GPT-4 models for secure code generation. For this, we used an existing dataset consisting of 150 NL security-relevant code-generation prompts. RESULTS: Our work (i) classifies potential prompting techniques for code generation (ii) adapts and evaluates a subset of the identified techniques for secure code generation tasks and (iii) observes a reduction in security weaknesses across the tested LLMs, especially after using an existing technique called Recursive Criticism and Improvement (RCI), contributing valuable insights to the ongoing discourse on LLM-generated code security.
arXiv.org Artificial Intelligence
Jul-9-2024
- Country:
- South America > Brazil
- Pernambuco > Recife (0.04)
- Oceania
- New Zealand > North Island
- Auckland Region > Auckland (0.04)
- Australia > Victoria
- Melbourne (0.04)
- New Zealand > North Island
- North America
- Dominican Republic (0.04)
- United States
- Maryland > Baltimore (0.04)
- Washington > King County
- Seattle (0.04)
- New York > New York County
- New York City (0.04)
- Minnesota > Hennepin County
- Minneapolis (0.14)
- Louisiana > Orleans Parish
- New Orleans (0.04)
- California
- San Francisco County > San Francisco (0.14)
- San Diego County > San Diego (0.04)
- Orange County > Anaheim (0.04)
- Canada
- Ontario > Toronto (0.04)
- Quebec > Montreal (0.04)
- British Columbia > Metro Vancouver Regional District
- Vancouver (0.14)
- Europe
- Austria (0.04)
- Sweden > Stockholm
- Stockholm (0.04)
- Germany
- Denmark > Capital Region
- Copenhagen (0.04)
- United Kingdom > England
- Greater London > London (0.04)
- Buckinghamshire > Milton Keynes (0.04)
- Portugal > Lisbon
- Lisbon (0.04)
- Italy
- Croatia > Dubrovnik-Neretva County
- Dubrovnik (0.04)
- Belgium > Brussels-Capital Region
- Brussels (0.04)
- Asia
- South Korea (0.04)
- Singapore > Central Region
- Singapore (0.04)
- Middle East
- Japan > Honshū
- Kantō > Kanagawa Prefecture > Yokohama (0.04)
- China > Guangdong Province
- Guangzhou (0.04)
- Africa > Rwanda
- South America > Brazil
- Genre:
- Overview (1.00)
- Research Report
- New Finding (1.00)
- Experimental Study (0.93)
- Industry:
- Information Technology > Security & Privacy (1.00)
- Education (0.67)
- Technology: