← Latest papers
💻 computer science

Does Fixing Break Security? An Empirical Study of Security Degradation in Iterative LLM-Driven Infrastructure-as-Code Repair

This empirical study analyzes 5,968 iterative LLM-driven Infrastructure-as-Code repair scenarios to reveal that while security regressions occur in up to 13.8% of cases under standard detection, a more conservative strict-mode analysis shows a defensible degradation rate of 3.3%, primarily driven by resource restructuring and mitigated by stopping repairs after the third iteration.

Original authors: Benjamin Agyekum, Fabio Santos

Published 2026-08-14
📖 6 min read🧠 Deep dive

Original authors: Benjamin Agyekum, Fabio Santos

Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer

Imagine you are building a massive, intricate castle out of digital blocks. This isn't just any castle; it's the infrastructure that runs the internet, your favorite apps, and cloud services. In the world of software engineering, this is called Infrastructure-as-Code (IaC). Instead of clicking buttons in a menu, engineers write text files (code) that tell the computer exactly how to build these digital castles. Recently, we've started using super-smart AI assistants, known as Large Language Models (LLMs), to write this code for us. It's like hiring a robot architect who can draft blueprints in seconds.

But here's the catch: robots make mistakes. Sometimes, the blueprints they draw have security holes—like leaving the front door wide open or forgetting to lock the treasure chest. To fix this, we use a "feedback loop." We run a security scanner (a digital inspector) that checks the robot's work, points out the mistakes, and sends the bad news back to the robot. The robot then tries to fix the code and sends it back for another check. This cycle repeats, hoping the castle gets safer with every round. The big question is: Does fixing one problem accidentally break something else that was already safe? It's like trying to patch a hole in a boat, only to accidentally punch a hole in the hull while you're at it. This paper dives deep into that exact scenario to see if our AI helpers are actually making things safer or just making a mess.


The Robot Architect's Dilemma: When Fixes Break Fixes

In this study, researchers Benjamin Agyekum and Fabio Santos decided to play detective with a massive dataset of these AI repair attempts. They looked at nearly 6,000 different scenarios where an AI tried to build or fix cloud infrastructure code. They watched what happened over 5 rounds of repairs, tracking 30 specific security checks (like "Is the data encrypted?" or "Is the access locked down?").

Their main discovery is a bit of a twist: Yes, fixing things can break security, but it's not as scary as it first looks.

When they looked at the raw numbers using a "standard" way of counting, they found that 13.8% of the time, the AI managed to break a security rule that was previously working while trying to fix something else. That sounds like a lot, right? But the researchers realized that the way they were counting was a bit tricky. Because the code often involves many different parts (like multiple digital locks on a building), the AI might fix one lock but accidentally mess up the status of another, even if the actual security wasn't truly compromised.

When they switched to a "strict" way of counting—looking only for clear, undeniable cases where security actually got worse—the number dropped dramatically to just 3.3% of scenarios. This suggests that most of the "breaks" were just confusing measurement glitches caused by the complexity of the code, not genuine security disasters.

The "Why" and "How" of the Breakage

So, when the AI does mess up, what's going on? The researchers found that the culprit is almost always resource restructuring. Imagine the robot architect decides to completely rebuild a wall instead of just patching a crack. In doing so, it might forget to put the security camera back on the new wall. This happened in 79% of the cases where security actually regressed.

They also noticed something interesting about the "personality" of the AI models. One model (Mistral) seemed to break things 17 times more often than another (Gemini) when using the standard counting method. However, when they used the strict method, neither model broke anything exclusively. This means the "bad" model wasn't actually creating more dangerous holes; it was just creating more complex code structures that confused the counting method.

The Sweet Spot: When to Stop Fixing

One of the most practical findings is about when to stop. The AI keeps trying to improve the code, but does it ever stop? The study suggests that the 3rd iteration (the third time the AI tries to fix the code) is the sweet spot.

  • By the 3rd try, the code is about 83.1% secure.
  • If you keep going to the 4th or 5th try, you barely gain any more security (maybe 0.3% more), but you start increasing the risk of breaking things again.

It's like tuning a radio: after a certain point, turning the dial just makes the static worse without finding a clearer station.

The Silver Lining: Self-Correction

Here is the most hopeful part of the story. The researchers found that when the AI does accidentally break a security rule, it often fixes itself! About 36.6% of the time, the very next round of repairs corrects the mistake the AI just made. It's like the robot architect realizes, "Oops, I took the wrong door off," and puts it back on in the next step.

However, they also found a "tug-of-war" effect. About 28.5% of the time, the security checks would flip back and forth—pass, fail, pass, fail—like a pendulum that can't decide where to stop. This usually happens with complex access controls, suggesting the AI is still figuring out the best way to build those specific parts.

The Bottom Line

This paper tells us that while iterative AI repair is a powerful tool, we need to be careful about how we measure its success.

  1. Don't panic over every glitch: Most apparent security breaks are just confusing measurement artifacts, not real dangers.
  2. Watch out for big rewrites: If the AI starts tearing down whole sections of code to fix a small bug, that's when security is most likely to slip.
  3. Stop at three: Let the AI try three times to fix the code, then call it a day. Going further usually adds more risk than reward.
  4. Use the right tools: If you want to be super safe, use a "strict" way of checking that ignores confusing multi-part errors, but keep an eye on the "standard" alerts just in case.

In short, the AI is a helpful apprentice, but it needs a human supervisor to know when to stop turning the wrench, or it might just end up tightening the bolt so hard it snaps the whole machine.

Drowning in papers in your field?

Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.

Try Digest →