通过廉价高效的提示工程增强基于 GitHub Copilot 的 AI 代码合成安全性
Enhancing Security of AI-Based Code Synthesis with GitHub Copilot via Cheap and Efficient Prompt-Engineering
AI总结:
本文提出三种提示修改方法(场景特定、迭代、通用条款)增强 GitHub Copilot 等 AI 代码生成器的安全性,在 OpenVPN 项目上实现不安全代码减少 16%、安全代码增加 8%,且无需专家知识或模型内部访问。
摘要:
AI 编程助手正在兴起。然而,开发者和公司避免充分利用其潜力的原因之一是生成代码的安全性存疑。本文首先回顾了当前的最新技术水平,并指出了在该问题上需要改进的领域。然后,我们提出了一种基于提示修改方法的系统化方法,以在最小化用户视角下的应用复杂性、计算资源和运营成本的同时,实现(即使是专有的黑盒)基于 AI 的代码生成器(如 GitHub Copilot)更好的代码安全性。总之,我们提出并评估了三种提示修改方法:(1)场景特定型,(2)迭代型,以及(3)通用条款型,同时我们讨论了它们的组合。与代码安全审计相反,后两种提出的方法不需要用户具备专家知识。我们在现实场景中使用 OpenVPN 项目在 GitHub Copilot 上评估了所提出方法的有效性,并证明所提出的方法将不安全的生成代码样本数量减少了多达 16%,并将安全代码的数量增加了多达 8%。由于我们的方法不需要访问 AI 模型的内部结构,因此它通常可以应用于任何基于 AI 的代码合成器,而不仅仅是 GitHub Copilot。
英文摘要:
AI assistants for coding are on the rise. However one of the reasons developers and companies avoid harnessing their full potential is the questionable security of the generated code. This paper first reviews the current state-of-the-art and identifies areas for improvement on this issue. Then, we propose a systematic approach based on prompt-altering methods to achieve better code security of (even proprietary black-box) AI-based code generators such as GitHub Copilot, while minimizing the complexity of the application from the user point-of-view, the computational resources, and operational costs. In sum, we propose and evaluate three prompt altering methods: (1) scenario-specific, (2) iterative, and (3) general clause, while we discuss their combination. Contrary to the audit of code security, the latter two of the proposed methods require no expert knowledge from the user. We assess the effectiveness of the proposed methods on the GitHub Copilot using the OpenVPN project in realistic scenarios, and we demonstrate that the proposed methods reduce the number of insecure generated code samples by up to 16\% and increase the number of secure code by up to 8\%. Since our approach does not require access to the internals of the AI models, it can be in general applied to any AI-based code synthesizer, not only GitHub Copilot.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。