arXiv:2611.05823cs.CRNov 2026

Manuscript Offprint

arXiv:2611.05823

A Hybrid Approach for Automated Security Pattern Recovery

Anh Minh Nguyen, Tuan Dat Tran, Alzubair Hassan, Liliana Pasquale

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original. This text is shared under the same licence.

Anh Minh Nguyen

University College Dublin

Dublin, Ireland

Tuan Dat Tran

University College Dublin

Dublin, Ireland

dat.tran@ucdconnect.ie

Alzubair Hassan

University College Dublin

Dublin, Ireland

alzubair.hassan@ucd.ie

Liliana Pasquale

University College Dublin

Dublin, Ireland

liliana.pasquale@ucd.ie

Abstract—Security-by-design emphasises integrating security into software design and development. Security pattern catalogues operationalise this principle by prescribing reusable architectural solutions to recurring security problems. However, recovering their implementations from source code remains challenging because security patterns are abstract, span multiple components, and admit many valid implementations. We present SecPatRec, a hybrid approach for automated security pattern recovery from source code repositories. We treat a security pattern as a reference architecture and frame its recovery as a deductive task: determining which prescribed roles are present, grounding them in code entities, and recovering their interaction sequences. SecPatRec pairs a ReAct-style LLM agent equipped with semantic and lexical code search for role detection and grounding with static code property graph analysis for interaction recovery. We curate a human-validated ground-truth dataset of 100 pattern instances covering five security patterns across 93 open-source Java and Python repositories, and introduce a three-level evaluation framework measuring recovery correctness against this ground truth. We evaluate SecPatRec using four LLMs, including proprietary and open-source models. Averaged over all models and pattern instances, SecPatRec achieves role-detection accuracy of 0.84, role-grounding similarity of 0.84, and an interaction-recovery score of 0.66. Compared to a one-shot end-to-end LLM baseline, SecPatRec achieves higher aggregate recovery scores and lower estimated LLM API costs per run, while processing repositories that exceed the baseline's configured input limit. The recovered role mappings and statically derived interaction sequences provide structural and behavioural evidence that can support inspection of security-pattern implementations.

I. INTRODUCTION

Software vulnerabilities can arise from weaknesses in a system's design as well as from implementation mistakes. McGraw estimates that roughly half of software security defects are design flaws [1], not implementation bugs [2]. Security-by-design emphasises integrating security into software design and development [2], [3]. The EU Cyber Resilience Act reinforces this goal by establishing cybersecurity requirements for products with digital elements made available on the EU market [4]. Tracing architectural security decisions to their implementation supports inspection of whether the code reflects the intended design [5]. However, this inspection is difficult when developers have only a partial view of the security architecture [6], or when architectural documentation is missing, outdated or inconsistent with the code [7], [8].

Security patterns are one of the primary means of security-by-design: they document reusable architectural solutions to recurring security problems [9]–[11]. A pattern describes a solution through architectural roles and the actions between them, providing both a blueprint for implementing a security control and a reference for inspecting an existing implementation. Unlike the Gang of Four design patterns [12], which offer code-level guidelines, security patterns admit multiple valid implementations. A role may be realised through different classes, functions or library calls, depending on the language, framework and application context [11], [13], [14], and an implementation may span several components. Consequently, finding individual security mechanisms does not establish how the pattern is implemented. Recovering the roles and their interactions can support architectural inspection and enable larger-scale empirical studies of how security patterns are used in practice, for which evidence remains limited [15], [16].

In this paper, we address automated security pattern recovery: given a security pattern and a codebase, determine which prescribed roles are present, ground them in code entities, and recover their interaction sequence. Because a security pattern describes both structure and behaviour, we treat it as a reference architecture and frame recovery as a deductive software architecture recovery (DSAR) task [17]. The pattern specification guides the search for implementing entities, including code defined within the repository and references to externally defined functionality.

Three challenges motivate our approach. First, roles are implemented in many ways. Prior work detects security patterns by architectural analysis and pattern matching [18], [19]; Bunke and Sohr, for example, match connected object process graphs and evaluate on a benchmark of Android applications [20]. LLM-assisted DSAR adds a different ability: it finds code units by what they mean rather than by their structure [17], [21]. We ask whether this can detect and ground roles in Java and Python repositories too large for a single prompt. Second, role mappings alone are not enough. They say which entities play the roles, not how those entities interact, and LLM-assisted DSAR only supports the mapping [17], [21]. Static analysis can supply the call relationships and their order. Third, each recovery output needs its own measure. Although architecture-level similarity measures provide useful comparisons of recovered architectures [22], [23], evaluat-ing individual patterns requires measurements linked to role presence, code grounding and interaction recovery. Assessing these outputs and comparing recovery configurations requires human-validated annotations at this granularity, which we construct.

In this paper, we propose SECPATREC, a hybrid approach that combines an LLM agent with static code property graph (CPG) analysis [24]. Guided by the pattern specification, the agent iteratively uses semantic and lexical code search to locate and inspect relevant code, producing role mappings and presence statuses. CPG traversal then uses these mappings to recover interactions between the identified entities. This division combines semantic interpretation of architectural roles with interaction evidence extracted from source code. To evaluate the approach, we construct human-validated ground truth and define three corresponding correctness metrics.

Our contributions are:

  • SECPATREC, a hybrid approach to automated security pattern recovery, with specifications from the Van Den Berghe catalogue [11] as reference architectures.

  • A human-validated ground-truth dataset of 100 security pattern instances covering five patterns across 93 open-source repositories: 49 Python and 44 Java projects. Each pattern is represented by ten instances per language. Each instance records role-to-code mappings, role presence statuses and an interaction sequence.

  • A three-level evaluation framework that measures recovery correctness against the ground truth through role detection accuracy (RDA), mapping localization score (MLS) and interaction recovery correctness (IRC).

  • An empirical evaluation using four LLMs, including proprietary and open-source models, across five patterns and two languages. We compare SECPATREC with a one-shot end-to-end LLM baseline, examine scalability with repository size, and assess how the code search tools affect correctness, token consumption and estimated LLM API costs.

Over the four models and all evaluated pattern instances, SECPATREC achieves a mean role detection accuracy of 0.84, a mean mapping localization score of 0.84 and a mean interaction recovery correctness of 0.66. It achieves higher aggregate recovery scores and lower mean estimated LLM API costs per run than the one-shot baseline, and processes repositories whose packed source exceeds the baseline's configured input limit.

References (61)