多次修复,一个方向:引导代码模型采用更安全的加密API使用方式
Many Repairs, One Direction: Steering Code Models Toward Safer Cryptographic API Use
AI总结:
本研究针对大型语言模型生成代码的加密API误用问题,构建48000个程序对,提出CrypSteer方法提取通用修复方向,可提升代码安全率5.28-15.00个百分点。
摘要:
大型语言模型生成的代码中存在加密API误用问题,可能会损害软件安全性。尽管现有许多方法通过修改模型参数或输入来提升代码安全性,但不同加密API修复方式相关的表征变化如何为安全代码生成提供通用干预手段,这一问题尚未得到充分探索。为探究该问题,我们构建了4种编程语言、10类加密API误用类别下的48000个匹配程序对,每对程序在保留编程任务的同时修改指定的API决策。将误用程序的内部表征与其安全对应程序的内部表征相减,即可得到修复向量。在5种模型上对平均修复向量的比较显示,修复向量按误用类别划分的组织性强于按编程语言划分的组织性,且这些类别特定模式也支持通用干预手段。我们提出CrypSteer,该方法通过归一化修复差异并选择与各类别误用修复对齐的主成分,提取出通用方向。在模型权重固定的情况下,生成过程中为每个模型的内部激活添加一个通用方向,相较于未引导的生成方式,在各类语言和误用类别上,整体目标安全率提升了5.28至15.00个百分点。这些发现将加密修复表征的通用结构与安全代码生成的可复用干预手段联系起来。
英文摘要:
Cryptographic API misuse in large language model-generated code can compromise software security. While many existing approaches improve code security by modifying model parameters or inputs, how representation changes associated with different cryptographic API repairs can support a shared intervention for safer code generation remains underexplored. To investigate this, we construct 48,000 matched program pairs across four programming languages and ten cryptographic API misuse categories. Each pair changes a specified API decision while preserving the programming task. Subtracting the misuse program's internal representation from its secure counterpart's gives a repair vector. Across five models, comparisons of mean repair vectors reveal stronger organization by misuse category than by language. These category-specific patterns also support a shared intervention. We introduce CrypSteer, which extracts a shared direction by normalizing repair differences and selecting a principal component aligned with repairs across misuse categories. With model weights fixed, adding one shared direction per model to its internal activations during generation improves aggregate target security rates by 5.28--15.00 percentage points over unsteered generation across languages and misuse categories. These findings connect the shared structure of cryptographic repair representations to a reusable intervention for safer code generation.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。