用语义理解提升IaC脚本安全漏洞检测效果
Detection of security smells in IaC scripts through semantics-aware code and language processing
- 融合代码与自然语言表示,增强静态分析的语义理解
- 在Ansible和Puppet上精度和召回率显著提升至0.92和0.88
- 适合安全开发、DevSecOps团队快速识别配置风险
基础设施即代码(IaC)通过脚本自动化管理IT基础设施,但常含重复性安全配置错误。现有方法多依赖静态分析,使用统计代码特征或机器学习分类器区分安全与不安全代码。本文提出一种新方法,通过联合利用自然语言与代码表示,增强静态分析的语义理解能力。基于两个互补的ML模型:CodeBERT用于捕捉代码与文本间的语义关联,LongFormer用于处理长IaC脚本而不丢失上下文。在Ansible和Puppet两个主流IaC工具的误配置数据集上评估。通过两次消融实验(移除代码文本输入、截断脚本以减少上下文)及与四种大语言模型和已有方法对比,结果表明语义增强显著提升检测效果:Ansible上精确率与召回率从0.46和0.79提升至0.92和0.88;Puppet上从0.55和0.97提升至0.87和0.75。
原文摘要 · Abstract (English)
Infrastructure as Code (IaC) automates the provisioning and management of IT infrastructure through scripts and tools, streamlining software deployment. Prior studies have shown that IaC scripts often contain recurring security misconfigurations, and several detection and mitigation approaches have been proposed. Most of these rely on static analysis, using statistical code representations or Machine Learning (ML) classifiers to distinguish insecure configurations from safe code. In this work, we introduce a novel approach that enhances static analysis with semantic understanding by jointly leveraging natural language and code representations. Our method builds on two complementary ML models: CodeBERT, to capture semantics across code and text, and LongFormer, to represent long IaC scripts without losing contextual information. We evaluate our approach on misconfiguration datasets from two widely used IaC tools, Ansible and Puppet. To validate its effectiveness, we conduct two ablation studies (removing code text from the natural language input and truncating scripts to reduce context) and compare against four large language models (LLMs) and prior work. Results show that semantic enrichment substantially improves detection, raising precision and recall from 0.46 and 0.79 to 0.92 and 0.88 on Ansible, and from 0.55 and 0.97 to 0.87 and 0.75 on Puppet, respectively.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。