By NHI Mgmt Group Editorial TeamDomain: Cyber SecuritySource: SonarPublished December 15, 2025

TL;DR: Among more than 4,000 Java tasks, GPT-5.2 High delivers the strongest security posture at 16 blocker vulnerabilities per MLOC, but also produces the highest code volume at 974,379 LOC, while Claude Sonnet 4.5 reaches 198 blocker vulnerabilities per MLOC and Opus 4.5 Thinking drops that to 44, according to Sonar. Functional correctness is not enough when AI-generated code also creates maintainability and review burden at scale, especially for teams shipping into production.


At a glance

What this is: Sonar's LLM code quality analysis shows that model choice changes not just functional success but also security, verbosity, and maintainability outcomes.

Why it matters: For IAM and security teams, the lesson is that AI-assisted development can expand attack surface and operational debt unless code quality, review depth, and security verification are governed together.

By the numbers:

👉 Read Sonar's analysis of AI coding model security, complexity, and maintainability


Context

AI-generated code is no longer judged only by whether it works. The governance gap is that functional benchmarks can hide structural weaknesses, including insecure input handling, concurrency errors, and code that becomes expensive to review and maintain once it reaches production. For identity and security programmes, that matters because application quality becomes part of the control environment, not just a developer productivity issue.

This analysis sits at the intersection of AI governance, application security, and engineering risk. Where AI-assisted development produces large volumes of code, teams need to understand how model behaviour changes the burden on secure coding review, static analysis, and release assurance. That is especially relevant for programmes that secure privileged workflows, authentication logic, or other identity-sensitive application paths.


Key questions

Q: How should security teams govern AI-generated code in production environments?

A: Security teams should treat AI-generated code as normal production code with extra provenance risk. Require architectural review, test coverage, static analysis, and approval before merge. Then bind the agent and the build pipeline to least privilege, short-lived credentials, and complete audit logging so implementation speed does not outrun control.

Q: Why do LLMs create security risk even when they pass tests?

A: Because test success only proves the code behaves correctly for the covered cases. It does not prove the implementation preserved secure input handling, avoided concurrency defects, or kept sensitive logic simple enough to review reliably. That gap is where insecure code enters production.

Q: What do security teams get wrong about AI-generated code risk?

A: They often focus on catching insecure output after code is written, which is too late for AI-native workflows. The more important control point is the moment the agent is allowed to initiate the action. If that step is not governed, testing becomes a detection layer rather than a prevention layer.

Q: What should teams do when AI-generated code is acceptable functionally but not structurally?

A: Block release until the code meets both functional and structural thresholds. If the logic is too complex, too verbose, or too defect-prone, the team should refactor or regenerate it before it reaches a production branch.


Technical breakdown

Why model reasoning changes code structure and review burden

LLMs do not just vary in correctness. They also vary in how much code they emit, how much logic they embed, and how much cognitive load they impose on reviewers. More verbose output often means more branching, more helper functions, and more places for subtle defects to hide. In practice, a model that passes tests can still produce code that is harder to reason about, harder to secure, and harder to keep stable across refactors. That is why static analysis remains essential even when functional benchmarks look strong.

Practical implication: treat AI-generated code as untrusted until it passes both functional and structural quality checks.

Blocker vulnerabilities reveal security verification gaps

Blocker vulnerabilities are the most severe findings because they point to flaws such as injection, unsafe path handling, or misuse of untrusted input. The Sonar results show that strong pass rates do not guarantee secure data flow reasoning. A model can solve the task and still fail to preserve source-to-sink trust boundaries, especially when the prompt allows complex control paths or framework-specific shortcuts. That makes security verification a distinct discipline from test success.

Practical implication: require automated static analysis and secure coding review before code produced by LLMs reaches release candidates.

Code smell density signals long-term maintainability debt

Code smells are not immediate exploits, but they are a leading indicator of long-term engineering cost. When 92% to 96% of all detected issues are maintainability problems, the real challenge is not just preventing bugs. It is reducing the amount of code that becomes brittle, opaque, or inconsistent over time. For security teams, that matters because brittle application code often weakens patching speed, auditability, and the reliability of security controls embedded in the application stack.

Practical implication: measure maintainability debt alongside defect counts when approving AI coding use cases.


Threat narrative

Attacker objective: The attacker objective is to exploit weaknesses in generated code paths before teams detect and remediate them, turning quality gaps into application compromise or control failure.

  1. Entry occurs when AI-generated code introduces insecure input handling, excessive complexity, or weak validation into application logic. Escalation follows when those flaws survive test coverage and enter production release pipelines.
  2. Impact emerges when blocker-level weaknesses or maintainability debt create exploitable paths, slow remediation, and increase the chance that security-critical code such as authentication or authorization logic degrades over time.

NHI Mgmt Group analysis

AI code governance now belongs in the same control conversation as application security. The Sonar results show that a model can satisfy test cases while still producing code with security flaws, concurrency defects, and maintainability debt. That means AI-assisted development cannot be governed as a pure productivity initiative. For security leaders, the practical conclusion is that code quality controls need to sit alongside SDLC policy, not after it.

Functional success is an inadequate proxy for secure software generation. The models with strong pass rates still produced very different security and quality profiles, which tells us that benchmark performance and production readiness are not the same thing. This is the same mistake organisations make when they treat one control signal as a full assurance signal. In an AI coding programme, secure-by-test is not secure-by-design. Practitioners should evaluate generated code on security, structure, and changeability together.

Maintainability debt is a governance issue, not just an engineering nuisance. When code smell volume dominates the issue mix, teams inherit hidden operational cost in review time, patch latency, and incident recovery. That cost compounds in identity-sensitive code paths where authorization, secrets handling, or session management errors can create disproportionate blast radius. The field should treat maintainability metrics as a security input, not merely a developer experience metric. Practitioners should fold code quality into risk acceptance decisions.

Model selection should be tied to the risk profile of the target code path. A model that is acceptable for low-risk utility code may be a poor fit for authentication flows, privileged automation, or data-access logic. The security posture differences in the Sonar results reinforce that teams should not apply one AI coding standard everywhere. For programmes managing NHI, IAM, or sensitive application logic, the right question is whether the model is fit for the control environment, not whether it is generally capable.

What this signals

Code quality now needs to sit inside the same governance framework as secure development and release assurance. When AI-generated code reaches production with latent complexity or security flaws, the control failure is not just in the model. It is in the organisation's ability to measure whether generated output meets a security boundary before it becomes a runtime problem. Teams should align review gates with NIST SP 800-53 Rev 5 Security and Privacy Controls and secure SDLC practices rather than relying on functional benchmarks alone.

Maintainability debt in AI-assisted development has identity implications when code touches secrets, sessions, and authorization logic. Poorly structured generated code makes these flows harder to audit and easier to break during change. That is why identity-sensitive application paths need extra scrutiny, especially where service accounts, tokens, or privilege checks are embedded in the code path. The operational lesson is to treat code smell density as a leading indicator of future security drag.

AI coding programmes should evolve toward model fit by use case, not one universal approval rule. High-risk paths such as authentication, authorization, and secrets handling deserve tighter constraints than low-risk utility code. For teams using agentic or AI-assisted development, the relevant question is whether the output can be governed inside the application's trust boundaries. That is the same discipline reflected in the OWASP Agentic AI Top 10 and related AI risk management guidance.


For practitioners

  • Gate AI-generated code with static analysis before merge Require every AI-assisted change to pass static analysis for injection, path handling, concurrency, and resource-leak checks before it reaches review approval.
  • Set model-specific risk thresholds for sensitive code paths Use stricter acceptance criteria for authentication, authorization, secrets handling, and other identity-sensitive paths than for low-risk utility code.
  • Track maintainability debt as a security metric Measure code smells, complexity growth, and review effort together so teams can see when AI-generated code is creating future remediation cost.
  • Separate functional pass rates from release readiness Do not treat benchmark success as production approval. Add security and maintainability gates before AI-generated code can move into release candidates.

Key takeaways

  • AI-generated code can pass functional tests while still creating security and maintainability debt that matters in production.
  • The Sonar results show that security posture, verbosity, and code quality do not move together, so model selection must be risk-aware.
  • Teams should apply static analysis, structural quality gates, and use-case-specific approval thresholds before AI-generated code reaches release.

Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

MITRE ATT&CK address the attack and risk surface, while NIST CSF 2.0, NIST SP 800-53 Rev 5, CIS Controls v8 and NIST AI RMF set the governance and control requirements practitioners need to meet.

FrameworkControl / ReferenceRelevance
NIST CSF 2.0PR.IP-1Secure development and testing controls fit AI-generated code quality governance.
NIST SP 800-53 Rev 5SI-2Flaw remediation is central when generated code contains blocker vulnerabilities.
CIS Controls v8CIS-16 , Application Software SecurityThis control maps directly to secure SDLC and code-review enforcement.
NIST AI RMFMANAGEAI risk management covers operational controls for generated output quality.
MITRE ATT&CKTA0002 , Execution; TA0005 , Defense EvasionInjected flaws and hidden complexity can enable unsafe execution paths and evade review.

Add static analysis and secure coding checks to the release pipeline before AI-generated code is merged.


Key terms

  • Blocker Vulnerability: A blocker vulnerability is a severe software flaw that can directly enable exploitation, data exposure, or control failure if released. In AI-generated code, blocker findings often point to unsafe input handling, path traversal, injection risk, or other defects that demand rejection or remediation before production use.
  • Code Smell: A code smell is a maintainability problem that makes software harder to understand, test, or change safely. It is not always an immediate exploit, but high smell density increases review burden, slows patching, and raises the chance that security defects survive future changes.
  • Cognitive Complexity: A metric that estimates how hard a function or code path is to understand, based on nesting, branching, and flow changes. Higher scores usually mean more mental effort for reviewers and a greater chance of maintenance errors.
  • Static analysis: Static analysis is the inspection of source code or configuration without executing it. It helps identify insecure patterns early, but its value depends on accuracy, timing, and whether the output is usable enough for developers to fix issues while they are still working on the code.

What's in the full report

Sonar's full analysis covers the operational detail this post intentionally leaves for the source:

  • Per-model benchmark tables for pass rate, code volume, concurrency defects, and blocker vulnerabilities across the full evaluation set
  • Side-by-side comparison data for GPT-5.2 High, GPT-5.1 High, Gemini 3.0 Pro, Opus 4.5 Thinking, and Claude Sonnet 4.5
  • The underlying SonarQube static-analysis methodology used to score maintainability and security findings
  • The full Sonar LLM Leaderboard view for teams that want to compare code quality signals before selecting a model

👉 The full Sonar analysis includes the per-model breakdowns and evaluation methodology behind the leaderboard.

Deepen your knowledge

The NHI Foundation Level course, the industry's only accredited NHI security programme, covers NHI governance, secrets management, and workload identity in the context of operational security. It helps practitioners connect identity controls to the broader security decisions that shape production risk.
NHIMG Editorial Note
Published by the NHIMG editorial team on August 20, 2026.
NHI Mgmt Group — the independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org