CWEval:面向大语言模型代码生成功能与安全性的结果驱动评估
CWEval: Outcome-driven Evaluation on Functionality and Security of LLM Code Generation
AI总结:
针对现有LLM代码生成评估基准无法准确兼顾功能正确性与安全性的问题,提出结果驱动评估框架CWEval及配套多语言安全编码基准CWEval-bench,可更精准评估代码安全风险,弥补了此前评估的不足。
摘要:
大语言模型(LLM)可生成或辅助编写代码,极大地帮助了开发者,提升了各类任务的生产效率。虽然识别错误代码通常较为简单,但检测功能正确的代码中存在的漏洞却更具挑战性,尤其是对于安全知识有限的开发者而言,这给使用LLM生成的代码带来了相当大的安全风险,也凸显了对可同时评估功能正确性与安全性的可靠评估基准的需求。现有的基准如CyberSecEval和SecurityEval试图解决这一问题,但受限于不清晰且不切实际的规范,无法准确评估功能与安全性两方面。为弥补这些不足,我们提出了CWEval,这是一种新型的结果驱动评估框架,旨在改进对LLM安全代码生成能力的评估。该框架依托高质量任务规范和具备高准确率的结果驱动测试判定器,可同时评估代码的功能与安全性。结合多语言、聚焦安全关键场景的编码基准CWEval-bench,CWEval能够对LLM生成的代码开展严谨的实证安全评估,克服了以往基准的缺陷。通过我们的评估,CWEval揭示了LLM生成的代码中有相当一部分功能正常但存在安全隐患,同时表明以往的评估存在严重的不准确性,最终为安全代码生成领域做出了重要贡献。我们的项目已开源,地址为:https://github.com/Co1lin/CWEval 。
英文摘要:
Large Language Models (LLMs) have significantly aided developers by generating or assisting in code writing, enhancing productivity across various tasks. While identifying incorrect code is often straightforward, detecting vulnerabilities in functionally correct code is more challenging, especially for developers with limited security knowledge, which poses considerable security risks of using LLM-generated code and underscores the need for robust evaluation benchmarks that assess both functional correctness and security. Current benchmarks like CyberSecEval and SecurityEval attempt to solve it but are hindered by unclear and impractical specifications, failing to assess both functionality and security accurately. To tackle these deficiencies, we introduce CWEval, a novel outcome-driven evaluation framework designed to enhance the evaluation of secure code generation by LLMs. This framework not only assesses code functionality but also its security simultaneously with high-quality task specifications and outcome-driven test oracles which provides high accuracy. Coupled with CWEval-bench, a multilingual, security-critical coding benchmark, CWEval provides a rigorous empirical security evaluation on LLM-generated code, overcoming previous benchmarks' shortcomings. Through our evaluations, CWEval reveals a notable portion of functional but insecure code produced by LLMs, and shows a serious inaccuracy of previous evaluations, ultimately contributing significantly to the field of secure code generation. We open-source our artifact at: https://github.com/Co1lin/CWEval .
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。