[論文レビュー] Can We Trust Large Language Models Generated Code? A Framework for In-Context Learning, Security Patterns, and Code Evaluations Across Diverse LLMs
本論文は、In-Context Learning (ICL) セキュリティ・フレームワークを提案し、4つの多様なLLM(PDCGsおよび CCPs)をC++、C#、Pythonにわたって訓練・評価し、セキュリティパターンとSAST/コードレビューを用いて安全なコード生成を評価・改善する。
Large Language Models (LLMs) such as ChatGPT and GitHub Copilot have revolutionized automated code generation in software engineering. However, as these models are increasingly utilized for software development, concerns have arisen regarding the security and quality of the generated code. These concerns stem from LLMs being primarily trained on publicly available code repositories and internet-based textual data, which may contain insecure code. This presents a significant risk of perpetuating vulnerabilities in the generated code, creating potential attack vectors for exploitation by malicious actors. Our research aims to tackle these issues by introducing a framework for secure behavioral learning of LLMs through In-Content Learning (ICL) patterns during the code generation process, followed by rigorous security evaluations. To achieve this, we have selected four diverse LLMs for experimentation. We have evaluated these coding LLMs across three programming languages and identified security vulnerabilities and code smells. The code is generated through ICL with curated problem sets and undergoes rigorous security testing to evaluate the overall quality and trustworthiness of the generated code. Our research indicates that ICL-driven one-shot and few-shot learning patterns can enhance code security, reducing vulnerabilities in various programming scenarios. Developers and researchers should know that LLMs have a limited understanding of security principles. This may lead to security breaches when the generated code is deployed in production systems. Our research highlights LLMs are a potential source of new vulnerabilities to the software supply chain. It is important to consider this when using LLMs for code generation. This research article offers insights into improving LLM security and encourages proactive use of LLMs for code generation to ensure software system safety.
研究の動機と目的
- 公開リポジトリや不安全なサンプルでの訓練に起因するLLM生成コードのセキュリティリスクに対処する。
- LLMs にセキュアなコーディング挙動を教えるためのIn-Context Learning (ICL) セキュリティパターンを開発・評価する。
- 複数言語にわたり、prompt-driven code generators (PDCGs) と coding copilots (CCPs) を比較する。
- LLM生成コードのデータセットとセキュリティ評価ワークフローを作成・分析する。
- AI支援開発における安全なコード生成を進めるための洞察とデータセットを提供する。
提案手法
- DS&A、API開発、MVCデザインパターンを含む、C++、C#、Pythonの多様なプログラミング問題セットを選定する。
- Chain-of-thought推論を組み込んだゼロショット、ワンショット、および few-shot 学習シナリオを用いたIn-Context Learning (ICL) セキュリティパターンを開発する。
- 問題ごとに4つのLLM(PDCGs: ChatGPT-4、Google Bard;CCPs: GitHub Copilot、Amazon Code Whisperer)を用いてコードを生成する。
- Static Application Security Testing (SAST) および手動のセキュリティレビューを用いて生成コードを評価し、脆弱性や隠れたコードスメルを特定する。
- ソースコードレベルでのセキュリティリスク指標を計算し、ICL後のコードスメルの持続性を分析する。
- 将来のLLMセキュリティ訓練を支援するセキュリティ指示データセットを公開する。

実験結果
リサーチクエスチョン
- RQ1RQ1: 多様なLLMはゼロショットのシナリオで、さまざまなプログラミング課題に対してどの程度安全なコードを生成できるか?
- RQ2RQ2: LLMは、ICLセキュリティパターンを用いたワンショットおよびfew-shot学習の後に、ベストプラクティスを理解し適用し、脆弱性にどの程度対処できるか?
- RQ3RQ3: ICLの下で、PDCG LLMs(ChatGPT-4、Google Bard)と CCP LLMs(GitHub Copilot、Code Whisperer)は安全なコード生成の点でどう比較されるか?
- RQ4RQ4: ICLセキュリティパターンを適用した後に残るセキュリティコードスメルは何で、それに関連するリスクは何か?
主な発見
- ICLを用いたワンショットおよびfew-shot学習パターンは、プログラミングシナリオ全体でコードの安全性を高め、脆弱性を低減できる。
- 4つの多様なLLMを3言語にわたり評価し、PDCGsとCCPsの安全なコード生成における差異を明らかにした。
- セキュリティテストはSASTツールと手動のコードレビューを組み合わせて、脆弱性と隠れたコードスメルを特定する。
- コードレベルのセキュリティ脅威を定量化するセキュリティリスク評価フレームワークを開発した。
- 本研究は、将来の安全なコード生成研究を指針づけるためのセキュリティ指示データセットの公開を提案(する) 。

より良い研究を、今すぐ始めましょう
論文設計から論文執筆まで、研究時間を劇的に削減しましょう。
クレジットカード登録不要
このレビューはAIが作成し、人間の編集者が確認しました。