Mitigating fix reversal: Counterfactual constraints for function-level vulnerability detection
Yun Bian, Shihao Li, Haiquan Wang, Yi Chen, Zhao Yang, Zhe Cui
Abstract
Function-level vulnerability detectors often exhibit fix reversal, assigning a higher vulnerability probability to a fixed version than to its vulnerable counterpart. Fixes usually lengthen functions, and larger length increases are associated with more severe reversal. Code-transformation experiments indicate that fix reversal mainly stems from a length shortcut: vulnerability probability increases with function length when content is fixed. We propose CFVul to address this problem. Sliding-window encoding covers complete functions, retaining fix information beyond the truncation boundary. During training, a content constraint encourages the vulnerable version to receive a higher vulnerability probability under a common length input. During inference, a length constraint averages vulnerability probabilities over fixed reference lengths, reducing the influence of actual length changes. On PrimeVul, CFVul achieves a fix-pair ranking metric, PairRank, of 59.4\%, exceeding the existing methods compared. For fixes that increase function length by more than 15\%, PairRank rises from CodeBERT's 25.8\% to 48.4\%. PairRank also improves in experiments with four additional models and three additional datasets. By weakening the length shortcut, CFVul reduces cases in which fixed versions receive higher vulnerability probabilities than vulnerable versions. It requires only existing fix pairs and applies to multiple pretrained code models, facilitating adoption in existing detectors.
Create a lesson
Related papers
Hardening JavaScript Programs against LLM-Based Vulnerability Detection
Shared title terminology · Zhenhao Tian, Jintong Yu, Jingwei Feng et al.
LLMs as Validators for Cross-Chain Bridges: Evaluating Source-Level and Transaction-Level Attack Detection on Solana
Shared title terminology · Yasir Rahman, Ishraq Samiha, Shahnewaz Karim Sakib et al.
AudioTrace: File-Level Membership Detection for Audio Large Language Models
Shared title terminology · Guangzhi Sun, Xiao Zhan, Shuai Wang et al.
ProcReverser: Multi-Agent Black-Box Microarchitectural Reverse Engineering for Processor Vulnerability Analysis
Shared title terminology · Guanqi Lyu, Decheng Qiu, Guangyang Zhang et al.
Too Fast to Doubt? Skipping Reasoning Leaves Jev-like Models Vulnerable
Shared title terminology · Yue Li, Hao Wu, Zenan Fu et al.
Mjolnir: Finding and Reproducing Vulnerabilities in Root-of-Trust Firmware and RTL with Project-Grounded Agents
Shared title terminology · Collin MacDonald, Carl Lundin, Stephen Herwig et al.