Skip to main content
QUICK REVIEW

[论文解读] Your Code Secret Belongs to Me: Neural Code Completion Tools Can Memorize Hard-Coded Credentials

Yizhan Huang, Yichen Li|arXiv (Cornell University)|Sep 14, 2023
Ferroelectric and Negative Capacitance Devices参考文献 46被引用 4
一句话总结

本文提出HCR,一种利用神经代码补全工具(NCCTs)如GitHub Copilot和Amazon CodeWhisperer从其输出中提取硬编码凭证的工具。该方法通过从真实GitHub代码中生成上下文相关的提示,揭示NCCTs可能记忆并泄露真实密钥——在Copilot中提取出2,702个有效凭证,其中3.6%为真实活跃密钥;在CodeWhisperer中提取出129个有效凭证,其中5.4%为真实活跃密钥。

ABSTRACT

Neural Code Completion Tools (NCCTs) have reshaped the field of software engineering, which are built upon the language modeling technique and can accurately suggest contextually relevant code snippets. However, language models may emit the training data verbatim during inference with appropriate prompts. This memorization property raises privacy concerns of NCCTs about hard-coded credential leakage, leading to unauthorized access to applications, systems, or networks. Therefore, to answer whether NCCTs will emit the hard-coded credential, we propose an evaluation tool called Hard-coded Credential Revealer (HCR). HCR constructs test prompts based on GitHub code files with credentials to reveal the memorization phenomenon of NCCTs. Then, HCR designs four filters to filter out ill-formatted credentials. Finally, HCR directly checks the validity of a set of non-sensitive credentials. We apply HCR to evaluate three representative types of NCCTs: Commercial NCCTs, open-source models, and chatbots with code completion capability. Our experimental results show that NCCTs can not only return the precise piece of their training data but also inadvertently leak additional secret strings. Notably, two valid credentials were identified during our experiments. Therefore, HCR raises a severe privacy concern about the potential leakage of hard-coded credentials in the training data of commercial NCCTs. All artifacts and data are released for future research purposes in https://github.com/HCR-Repo/HCR.

研究动机与目标

  • 探究商业神经代码补全工具(NCCTs)是否能从其训练数据中记忆并泄露硬编码凭证。
  • 开发一种系统化方法,利用真实代码上下文识别并提取此类记忆的密钥。
  • 评估NCCT在实际部署中的隐私风险,特别是针对API密钥和令牌等敏感凭证。
  • 证明即使仅通过黑盒访问,攻击者也能通过提示工程从NCCT中提取真实活跃密钥。
  • 提醒模型开发者和用户,需采取主动缓解策略以防止凭证泄露。

提出的方法

  • 使用GitHub的密钥扫描列表识别18种常见密钥类型(如AWS密钥、Stripe令牌)。
  • 设计正则表达式(regex)以检测代码文件中的密钥模式,实现对含凭证仓库的自动化识别。
  • 从GitHub收集含密钥的代码文件,移除密钥后,将修改后的代码作为提示,触发NCCT补全缺失的凭证。
  • 应用四种过滤机制——正则模式匹配、熵阈值检测、格式校验和服务特定语法检查——以区分真实密钥与随机字符串。
  • 通过黑盒查询评估NCCT响应,并借助直接访问或文档检查验证提取出的密钥。
  • 在两款商业NCCT上开展大规模评估:GitHub Copilot和Amazon CodeWhisperer。

实验结果

研究问题

  • RQ1商业NCCT如GitHub Copilot和Amazon CodeWhisperer是否能在代码补全过程中记忆并原样输出硬编码凭证?
  • RQ2使用真实代码上下文进行提示工程,在触发NCCT记忆密钥方面有多高效?
  • RQ3提取出的密钥中有多少比例是真实活跃凭证,而非合成或无效字符串?
  • RQ4不同密钥类型(如API密钥、OAuth令牌)在记忆与泄露风险方面有何差异?
  • RQ5在不修改模型架构的前提下,有哪些可行且有效的缓解策略可用于防止NCCT中的密钥泄露?

主要发现

  • HCR在900个测试提示下,成功从GitHub Copilot中提取出2,702个有效凭证,其中3.6%为真实活跃密钥。
  • Amazon CodeWhisperer返回了129个有效凭证,其中5.4%为真实活跃密钥,表明存在显著的记忆化风险。
  • 识别出两个生产环境凭证——具体为两个在Stripe API环境中验证为有效且活跃的测试密钥。
  • 研究证实,经过含密钥的公共代码仓库训练的NCCT,可在适当提示下原样记忆并泄露这些密钥。
  • 该攻击在黑盒环境下依然有效,无需访问模型权重或内部参数。
  • 结果凸显了广泛使用的AI编程助手存在关键隐私漏洞,强调需在NCCT中改进数据筛选与输出过滤机制。

更好的研究,从现在开始

从阅读论文到最终审阅,大幅缩短您的研究时间。

无需绑定信用卡

本解读由 AI 生成,并经人工编辑审核。