Manuscript Offprint

arXiv:2610.10659

Applying Security by Design at the Point of Execution: How Governed Security Requirements Affect the Security of AI-Generated Code

Pedro Farinha

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

Security by design asks that security requirements are defined before code is written. Coding agents can receive those requirements at the point of execution, when they write the code. Secure-code benchmarks typically measure the opposite situation: the agent receives the task without requirements and is scored with security tests it has not seen. We measured what changes when security requirements, selected from a governed security-by-design knowledge base (SbD-ToE) and delivered through a Model Context Protocol (MCP) server, are given to the generator at the point of execution.

We used two benchmarks with different evaluators. On DualGauge, which scores with a language-model judge, we ran 59 Python tasks: the share of tasks passing all security tests rose from 44.1% to 78.0% and the share of security tests passed from 77.4% to 93.0%. On BaxBench, which runs functional tests and real exploits in containers, we ran 28 backend scenarios: among functionally correct solutions, the share with no successful exploit rose from 65% to 86%, comparable to the authors' Oracle Security Reminder (85%), which they call an unrealistic upper bound because it is built from the tested weaknesses. The requirement delivery reached that level without knowing the tests.

The study has limits. The pre-specified joint secure-and-functional metric did not improve significantly on either benchmark. The code written with the governed requirements is stricter, and it failed functional tests that fix values the task never states; we attribute those failures case by case in a post-hoc analysis. Each experiment used one model and one generation per task. The requirements come from the author's own open-source manual, compiled into a knowledge base and used as it is; we do not assess its completeness or its content.

A governed, compiled set of security requirements, delivered at the point of execution, appears to improve the security of generated code. And current benchmarks cannot tell whether that code meets the security requirements that apply to it, only whether it shows the weaknesses their evaluators were built to detect. We propose measuring conformance with the applicable requirements.

1. The problem

Security by design asks that the security requirements of software are defined before the code is written. The NIST Secure Software Development Framework (SSDF) asks organisations to define the security requirements for the software they develop and to design the software to meet them [18]. ISO/IEC 25010 treats security as a quality characteristic that is first specified and then evaluated [17]. In practice, this depends on engineers who know the requirements and apply them when they write code.

Coding agents create a new way to apply this principle. An agent decides how to write the code at one moment, when it generates it. We call this moment the point of execution. If the applicable requirements are delivered at that moment, the agent can apply them without depending on what the engineer remembered to state in the prompt.

Secure-code benchmarks measure a different situation. The agent receives a functional task without security requirements. The benchmark then scores the code with security tests that the agent has not seen. A low score is often read as “the model writes insecure code”. For a part of the gap, a more accurate reading is this: the generator was not given the security requirements, and at the point of execution it had to guess which properties applied and which of them the tests would check.

A low score therefore cannot tell at least two failures apart. In one, the model could not implement a property (a capability failure). In the other, it did not guess that the property was required (a specification failure). If specification failures explain a measurable part of the gap, stating the requirements should help without changing the model.

Hypothesis. Language models are trained on large amounts of code and text, and earlier work reports that a cue derived for the task activates security knowledge that the model already has [14]. BaxBench's own published results point the same way. A prompt that names the weaknesses that the tests check raises the correct-and-secure rate of Claude Opus 4.5 from 0.561 to 0.686 (Appendix F). Both results use the same model with different prompts. For many security properties, the model can therefore produce a secure construction when it is told that the property is required. What it may not do reliably is decide, without being told, which properties apply to a given task. Our hypothesis is that delivering the applicable requirements at the point of execution raises the security of the generated code without changing the model. Once the requirements are delivered, the remaining failures can be attributed: to capability, to missing coverage in the knowledge base, or to the tests.

We test this hypothesis on two benchmarks that differ in what they test and how they test it. DualGauge [1] gives short Python tasks as text specifications. An executor runs the code, and a language-model judge scores the test results. BaxBench [10] asks for complete backend applications from an OpenAPI specification. It runs functional tests and real exploits against the application in containers, and it publishes a leaderboard with three prompts. The two benchmarks therefore differ in the size of the task (a function or a short program against an application) and in the security evaluator (a judge against executed exploits). We delivered the requirements at the point of execution on both benchmarks. Security rose on both, under two different evaluators. Each experiment adds one thing, the requirement-delivery package, and keeps the agent or model, the tasks and the evaluator fixed. A difference between the conditions can therefore be read as the effect of that delivery. On security, both benchmarks show a difference in the same direction (Section 3).

On both benchmarks, we compare the code written with the requirements against the code written without them. On DualGauge, the reference is the same agent without the grounding package. On BaxBench, the reference is the benchmark's baseline prompt, which its authors call No Security Reminder. We add a second reference on BaxBench, the authors' Oracle Security Reminder, which is their upper bound for security through prompting. We also report what the benchmarks could not measure once the generator received the requirements.

References (20)