Patched, But Still Vulnerable?

Author: Denis Avetisyan


New research reveals that many software patches offer only superficial changes, leaving residual risks lurking in seemingly secure code.

A residual risk score is computed by integrating semantic similarity <span class="katex-eq" data-katex-display="false">S_{sem} </span>, structural similarity <span class="katex-eq" data-katex-display="false">S_{ast} </span>, and cross-model agreement <span class="katex-eq" data-katex-display="false"> \sigma_{cross}^2 </span>, offering a comprehensive assessment of potential vulnerabilities.
A residual risk score is computed by integrating semantic similarity S_{sem} , structural similarity S_{ast} , and cross-model agreement \sigma_{cross}^2 , offering a comprehensive assessment of potential vulnerabilities.

A novel framework quantifies residual risk by analyzing semantic and structural similarity between vulnerable and patched code.

Despite advancements in vulnerability patching, determining whether code truly becomes benign remains a significant challenge. This paper, ‘Residual Risk Analysis in Benign Code: How Far Are We? A Multi-Model Semantic and Structural Similarity Approach’, introduces a novel framework, Residual Risk Scoring (RRS), to quantify the extent to which patched code retains characteristics of its vulnerable predecessor. Our analysis reveals that a surprising percentage of ostensibly benign functions exhibit high similarity to their vulnerable counterparts, suggesting the persistence of residual risks-validated by static analysis tools in approximately 61\% of high-RRS cases. Does this indicate a need for more robust post-patch inspection and a re-evaluation of current software security assessment pipelines?


The Persistent Shadow of Undetected Vulnerabilities

Even with exhaustive pre-release testing, software systems persistently exhibit zero-day vulnerabilities – flaws unknown to developers and without available patches – creating substantial risk for users and organizations. These vulnerabilities arise from the inherent complexity of modern software, where subtle coding errors or unforeseen interactions can bypass standard security measures. The consequences range from data breaches and financial losses to disruptions of critical infrastructure, as attackers actively seek and exploit these weaknesses before defenses can be implemented. This constant threat necessitates a proactive and adaptive security posture, shifting the focus from reactive patching to preventative measures and continuous monitoring, as reliance on traditional testing alone proves insufficient in safeguarding against increasingly sophisticated attacks.

Contemporary software security relies heavily on vulnerability detection, yet these methods frequently falter when confronted with the intricacies of modern codebases. Traditional approaches, such as signature-based scanning and fuzzing, excel at identifying known patterns of malicious code, but struggle with nuanced flaws – those arising from complex interactions within the software or subtle deviations from expected behavior. The sheer scale of many applications, coupled with the increasing use of dynamic code generation and intricate dependencies, creates a vast search space that overwhelms these techniques. Consequently, vulnerabilities often remain hidden within complex systems, creating significant gaps in protection and providing opportunities for exploitation before detection – a challenge amplified by the rapid pace of software development and deployment.

Modern cyberattacks are no longer reliant on easily detectable signatures or predictable patterns; instead, malicious actors increasingly leverage intricate techniques that exploit the intended logic of software in unforeseen ways. Consequently, conventional vulnerability detection, which largely depends on identifying known problematic sequences, proves inadequate against these advanced threats. A shift towards semantic code analysis – a process that focuses on understanding what the code is designed to do, rather than simply what it does – is therefore crucial. This deeper comprehension enables security systems to anticipate potential misuse of legitimate functionalities, identify subtle flaws in program logic, and ultimately defend against attacks that bypass traditional pattern-matching defenses. The evolution demands tools capable of reasoning about code behavior, not just recognizing familiar strings, to effectively mitigate the rising tide of sophisticated cyber threats.

Analysis of vulnerable and benign function pairs reveals distinctions in both semantic meaning and underlying code structure.
Analysis of vulnerable and benign function pairs reveals distinctions in both semantic meaning and underlying code structure.

Quantifying Inherent Risk Through Code Similarity

Residual risk acknowledges that despite comprehensive testing and patching efforts, inherent uncertainty regarding software security persists. This uncertainty stems from the complexity of modern software, the possibility of previously unknown vulnerabilities, and the potential for new attack vectors to emerge. Consequently, a static assessment of security posture is insufficient; continuous assessment is crucial for identifying and mitigating lingering vulnerabilities. This ongoing evaluation allows for the proactive identification of weaknesses that may have been overlooked during initial testing or introduced through subsequent code changes, thereby reducing the potential for exploitation and minimizing the overall risk exposure.

The methodology employs code similarity analysis to detect potentially vulnerable code irrespective of static analysis tool outputs. This is achieved by calculating the resemblance between code segments, identifying instances where functionally similar code exists that may share vulnerabilities, even if the specific code paths differ. The technique focuses on identifying patterns known to be associated with security flaws, such as improper input validation or buffer overflows, by comparing code across the entire codebase and, potentially, against publicly available vulnerability databases. This allows for the discovery of vulnerabilities that static analysis may miss due to limitations in pattern matching or incomplete code coverage, providing an additional layer of security assessment.

Residual Risk Scoring (RRS) utilizes code similarity analysis to quantify the likelihood of undetected vulnerabilities. The methodology calculates a resemblance metric between code segments, identifying instances where functionally similar code exists despite potential differences in implementation or prior analysis. This allows security teams to prioritize code segments with high RRS values for manual review and focused testing, as these areas demonstrate a persistence of traits commonly associated with vulnerabilities. A higher RRS indicates a greater probability that a vulnerability, even if not currently known or flagged, may be present due to the similarity to known vulnerable patterns. The score is not a direct indication of vulnerability, but rather a risk indicator for focused security effort.

Corresponding abstract syntax trees (ASTs) reveal the structural differences between vulnerable and benign code.
Corresponding abstract syntax trees (ASTs) reveal the structural differences between vulnerable and benign code.

Unveiling Semantic Relationships Through Advanced Code Comparison

Our code similarity analysis integrates both syntactic and semantic comparison methods. Tree Edit Distance (TED), a tree-based technique, quantifies differences in Abstract Syntax Trees (ASTs) representing code structure, providing a measure of syntactic similarity. This is complemented by embedding-based semantic similarity, which leverages pre-trained code language models to generate vector representations of code snippets. By comparing these vectors, we assess semantic equivalence, even when syntactic differences exist. This multi-faceted approach allows for a more robust determination of code similarity than relying on either technique in isolation, capturing both structural and functional aspects of the code.

Code similarity is assessed by generating vector representations of code using pre-trained language models, specifically CodeBERT, UniXCoder, GraphCodeBERT, and CodeT5. These models capture semantic meaning, enabling comparison beyond simple textual differences. Evaluation demonstrates high fidelity in semantic preservation following code patching, with mean cosine similarities reaching 0.9988 for CodeBERT and 0.9970 for GraphCodeBERT. These values indicate that the vector representations effectively maintain semantic consistency even with localized code modifications, facilitating accurate identification of functionally equivalent code segments.

Localized AST-Based Structural Similarity utilizes the Tree-sitter parsing library to generate Abstract Syntax Trees (ASTs) for precise code structure comparison. This approach facilitates the identification of localized modifications introduced by patches while assessing the preservation of overall code structure. Quantitative analysis, yielding a mean Localized Tree Edit Distance (TED) Similarity score of 0.82, confirms that patches primarily affect limited code regions, indicating a high degree of structural preservation throughout the codebase. This structural similarity metric contributes to a more accurate risk assessment by distinguishing between minor, localized changes and substantial structural alterations.

Static analysis tools – specifically Clang-Tidy, Cppcheck, and Facebook Infer – contribute to the Residual Risk Scoring (RRS) framework by identifying potential code defects, vulnerabilities, and style violations. These tools perform automated inspections without executing the code, providing data points related to code quality and security. The results from these static analyses are integrated into the RRS, serving as additional indicators of risk beyond semantic and structural comparisons. This complementary data enhances the accuracy and comprehensiveness of the overall risk assessment by flagging issues such as memory leaks, null pointer dereferences, and coding standard violations that may not be apparent through other methods.

Vulnerable-benign pairs exhibit varying degrees of semantic and structural similarity depending on the α and β configuration, with γ fixed at 0.2.
Vulnerable-benign pairs exhibit varying degrees of semantic and structural similarity depending on the α and β configuration, with γ fixed at 0.2.

Validating Our Approach with the PrimeVul Dataset

The PrimeVul dataset, utilized for evaluating our framework, consists of 1,283 functions sourced from open-source projects and intentionally modified to introduce subtle vulnerabilities. These vulnerabilities are not readily apparent through simple pattern matching, requiring analysis beyond typical static analysis tools. The dataset is specifically designed to assess a system’s ability to detect flaws that require deeper semantic understanding of the code. Our framework’s performance on PrimeVul demonstrates its capability to identify these nuanced security issues, providing a quantifiable measure of its effectiveness in detecting vulnerabilities beyond those flagged by conventional methods. The dataset includes ground truth labels indicating the presence and type of each vulnerability, allowing for precise evaluation of precision, recall, and F1-score.

The framework’s improved performance in vulnerability detection stems from a combined approach utilizing multiple similarity metrics – including those assessing code structure and semantic relationships – alongside the integration of pre-trained models. These models, trained on large codebases, facilitate a more nuanced understanding of code behavior and potential vulnerabilities than traditional methods relying solely on pattern matching or rule-based systems. Quantitative evaluation demonstrated a statistically significant increase in both precision and recall compared to baseline techniques, indicating a reduced rate of false positives and a higher rate of true positive vulnerability identifications.

Analysis of the PrimeVul dataset revealed a strong correlation between high Residual Risk Scores (RRS) and actual vulnerabilities, with 61% of functions identified as having high RRS also flagged by static analysis tools for security-relevant issues. This indicates that the residual risk assessment effectively pinpointed areas of concern even within benign code, where traditional vulnerability scanners might not identify a direct exploit. The observed overlap suggests that the RRS metric captures characteristics indicative of potential vulnerabilities, complementing the findings of static analysis and increasing the likelihood of identifying genuine security flaws.

The incorporation of static analysis tools into our framework yielded complementary data that improved the precision of residual risk assessment. These tools identified security-relevant issues within code functions, providing an independent validation source for high residual risk scores (RRS). Specifically, 61% of functions flagged as high-RRS by our system were also flagged by static analysis, demonstrating a strong correlation. This cross-validation process reduces false positives and increases confidence in identifying genuinely vulnerable code segments, as the static analysis tools offer insights into potential weaknesses not directly captured by the RRS calculation.

Towards Proactive Resilience in Open Source Ecosystems

A novel framework for preemptive security has emerged, shifting the focus from reactive patching to anticipating vulnerabilities within open-source projects. This approach empowers developers to move beyond simply fixing flaws as they are discovered, instead enabling systematic identification of potential weaknesses during the development lifecycle. By integrating security considerations into the initial design and ongoing maintenance phases, the framework facilitates a continuous assessment of code, dependencies, and configurations. This proactive stance not only minimizes the window of opportunity for malicious actors, but also fosters a more resilient software supply chain, ultimately reducing the likelihood of successful exploitation and bolstering the overall integrity of open-source ecosystems.

Continuous assessment of residual risk is paramount for organizations navigating the complexities of open-source software security. This practice moves beyond simply identifying vulnerabilities to understanding the likelihood and potential impact of those vulnerabilities remaining in the codebase. By quantifying this remaining risk-considering factors like exploitability and asset value-security teams can move from a reactive posture to a proactive one. This allows for strategic allocation of limited resources, focusing efforts on mitigating the highest-impact risks first and accepting lower-level risks where the cost of remediation outweighs the potential damage. Consequently, organizations achieve a more efficient and effective security program, maximizing protection while minimizing disruption and cost – ultimately bolstering the overall resilience of the software ecosystem.

The proposed risk management framework is deliberately architected for scalability, a crucial attribute when applied to the expansive landscapes of modern open-source projects. Unlike approaches that become bogged down with increasing codebases and contributor networks, this methodology leverages automated tools and distributed assessment techniques. This allows for continuous monitoring across millions of lines of code and countless dependencies, identifying vulnerabilities as they emerge rather than during reactive post-incident analysis. The ability to adapt to the dynamic nature of open-source-where contributions and updates are frequent-is paramount, and this scalable design ensures the framework remains effective even as projects grow in complexity and scope, ultimately bolstering the security of the broader software ecosystem.

The study meticulously details how seemingly effective patches can leave a lingering shadow of vulnerability, a concept resonating with the inherent complexity of software systems. This echoes G. H. Hardy’s observation: “A mathematician, like a painter, is a maker of patterns.” The framework presented doesn’t simply seek to eliminate flaws, but to understand the patterns of change introduced by patching. Residual Risk Scoring, by quantifying the semantic and structural similarity between vulnerable and patched code, provides insight into whether the ‘pattern’ has been truly disrupted or merely superficially altered. Understanding this architectural continuity-or lack thereof-is crucial for assessing true security improvements, as modifications in one area invariably impact the whole.

What’s Next?

The quantification of ‘residual risk’-a deceptively simple phrase-highlights a persistent truth in software security: patching is often a superficial exercise. This work, by attempting to move beyond simple patch diffs and towards semantic and structural similarity, acknowledges that code, like any complex system, retains memory. A patch may close the immediate wound, but the underlying architecture, the very logic that permitted the vulnerability, often remains. The question isn’t merely whether a patch exists, but how thoroughly it reshapes the flawed foundation.

Future effort should resist the temptation of increasingly complex models. If a design feels clever, it’s probably fragile. The current landscape favors feature-rich tools; however, a truly robust system will likely emerge from a deeper understanding of fundamental principles. Rather than chasing ever-finer-grained semantic analysis, focus should be directed toward identifying the minimal structural changes necessary to eliminate a class of vulnerabilities – a sort of ‘surgical’ approach to code repair.

Ultimately, the pursuit of perfect patching is a fool’s errand. Code will always be imperfect. The real challenge lies in building systems that are resilient despite these imperfections-systems where vulnerabilities are difficult to exploit, even if they exist. This demands a shift in mindset, from focusing on individual patches to designing for inherent security at the architectural level.


Original article: https://arxiv.org/pdf/2604.21051.pdf

Contact the author: https://www.linkedin.com/in/avetisyan/

See also:

2026-04-25 05:12