Our AI's Security Audit Flagged a Bug We Never Asked It to Fix
We gave a set of AI agents a small, realistic task on a demo shopping cart: discount codes now come from user input, so validate them. Trim whitespace, uppercase, letters and digits only, 20 characters max, and reject an
We gave a set of AI agents a small, realistic task on a demo shopping cart: discount codes now come from user input, so validate them. Trim whitespace, uppercase, letters and digits only, 20 characters max, and reject anything else before it reaches the totals. Add tests.
We ran it through a Security-Sensitive Change workflow: five agents in a row. One scopes the change, one analyses the risk, one implements, one audits the diff, and one validates the result. The whole run took about 35 seconds and cost under 20 cents.
The implementation did what we asked. The diff added a validateDiscountCode helper that trims, uppercases, checks the pattern and length, and throws on anything else. Tests covered valid codes, illegal characters, long codes and unknown codes.
Then the audit step came back with four findings. Three were minor. One was marked HIGH:
Unvalidated
discountPercentparameter allows arbitrary discount values.
The cart's older total() function still accepted a raw discountPercent option. We had asked the agents to lock down the new input path, and they did. But the old path was still wide open: a caller could pass 100, or 250, and get a free cart or a negative total. Nobody had asked about it. The auditor found it anyway, because it was reading the code around the change, not just the change.
The gate held. Because a HIGH finding was open, the change was not release-ready. It could not become a pull request until the finding was fixed or a person signed off on it. One click on Fix sends the finding back to an agent as a new task.
Three takeaways
- Audit the code around the change, not just the diff lines. The most dangerous bugs were next to what we changed, not in it.
- A finding needs teeth. If a reviewer can flag a HIGH issue and the change still merges, the review is advice. Tie open high or critical findings to a merge block.
- Scope creep is good when it's a finding, not a commit. The auditor didn't silently "fix" the extra issue inside our change. It reported it, so a person decides.
We recorded runs like this as short tutorials on our YouTube channel: https://www.youtube.com/@AICodeOps
AI CodeOps is free during the open beta and free forever for non-commercial open source: https://aicodeops.dev
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.