使用大型语言模型检测源代码中的密钥泄露
Secret Breach Detection in Source Code with Large Language Models
AI总结:
本文提出正则候选提取与LLM分类结合的混合密钥泄露检测方法,经微调的开源模型在818个GitHub仓库基准上取得优异性能,可低误报、低成本地本地部署。
摘要:
背景:在源代码中泄露API密钥、令牌和凭证等敏感信息,始终是一项持续存在的安全威胁。传统基于正则表达式和熵的工具由于上下文理解能力有限,往往会产生较高的误报率。目标:本工作旨在利用大型语言模型(LLM)增强源代码中的密钥检测,在保持高召回率的同时减少误报。我们还评估了使用经过微调的较小模型进行本地部署的可行性。方法:我们提出一种混合方法,将基于正则表达式的候选提取与基于LLM的分类相结合。我们在来自818个GitHub仓库的基准数据集上评估了多种大型语言模型的预训练和微调变体。针对二分类和多分类任务,采用了多种提示策略和高效微调方法。结果:经过微调的LLaMA-3.1 8B模型在二分类中取得0.9852的F1分数,优于仅使用正则表达式的基线。在多分类方面,Mistral-7B达到0.982的准确率。微调显著提升了所有模型的性能。结论:经过微调的LLM为密钥检测提供了有效且可扩展的解决方案,大幅减少了误报。开源模型为商业API提供了切实可行的替代方案,能够在开发工作流中实现安全且具有成本效益的部署。
英文摘要:
Background: Leaking sensitive information - such as API keys, tokens, and credentials - in source code remains a persistent security threat. Traditional regex and entropy-based tools often generate high false positives due to limited contextual understanding. Aims: This work aims to enhance secret detection in source code using large language models (LLMs), reducing false positives while maintaining high recall. We also evaluate the feasibility of using fine-tuned, smaller models for local deployment. Method: We propose a hybrid approach combining regex-based candidate extraction with LLM-based classification. We evaluate pre-trained and fine-tuned variants of various Large Language Models on a benchmark dataset from 818 GitHub repositories. Various prompting strategies and efficient fine-tuning methods are employed for both binary and multiclass classification. Results: The fine-tuned LLaMA-3.1 8B model achieved an F1-score of 0.9852 in binary classification, outperforming regex-only baselines. For multiclass classification, Mistral-7B reached 0.982 accuracy. Fine-tuning significantly improved performance across all models. Conclusions: Fine-tuned LLMs offer an effective and scalable solution for secret detection, greatly reducing false positives. Open-source models provide a practical alternative to commercial APIs, enabling secure and cost-efficient deployment in development workflows.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。