Reviewing AI-generated code before it reaches production
Reviewing AI-generated code before it reaches production connects a security requirement to the behaviour of a real feature. The relevant controls need to remain effective across custom code, integrations and the production configuration. Understanding AI-generated code before it reaches production helps establish which security property the feature needs and where that property is actually enforced.
What does this involve?
A framework provides useful security mechanisms only when the application uses them consistently and deploys them with appropriate settings. Custom handlers, plugins and alternate execution paths can bypass protections that the development team assumes are automatic.
AI coding tools have moved beyond code suggestion. In 2026, agentic coding tools (Claude Code, Cursor agent mode, Aider, Devin, Copilot Workspace, Codex) execute shell commands, install packages, edit files, run tests, access the network, and push branches autonomously. Many developers run these agents with auto-accept enabled, meaning the agent operates with the developer's full permissions and minimal human oversight.
AI coding assistants frequently suggest package names that do not exist on public registries. Attackers monitor these hallucinated names and register malicious packages with matching names (AI-assisted typosquatting).
Why it matters
Consider a realistic failure: aI-generated code looks plausible but introduces an unverified dependency or omits a required permission check.
A configuration or integration mistake can affect many routes at once. The important question is which application data and operations become reachable, rather than whether a framework option merely differs from its default.
Implementation guidance should be applied to a real feature and its deployment. Framework defaults, custom handlers and integrated services all influence whether the intended protection remains effective.
How penetration testers check for it
Trace the relevant feature from its entry point to the data or operation it protects, including custom code and alternate paths.
- Review supported runtime versions and release settings.
- Trace identity, input and output through real application paths.
- Inspect custom integrations and security overrides.
- Test important negative cases alongside ordinary functionality.
How to fix it
Use the appropriate maintained mechanisms and verify the result in the actual production configuration.
- Repository content as instruction source. Issue bodies, PR descriptions, PR comments, README files, dependency changelogs, error traces, fetched web pages, and MCP tool responses all become instructions when the agent reads them. An attacker who can write to any of these can influence agent behaviour.
- MCP servers as tool providers. Agents connect to MCP servers to access tools. A malicious or compromised MCP server can poison tool descriptions, shadow legitimate tool names, exfiltrate credentials through tool arguments, or update tool definitions after initial approval (rug-pull).
- Rules files as persistent steering. Files like .cursorrules, CLAUDE.md, AGENTS.md, .github/copilot-instructions.md, and .windsurfrules silently steer every future generation. They can be modified by a malicious PR or by the agent itself to embed persistent instructions.
- The agent itself. Agents running with auto-accept and full developer permissions can install packages, write to any file, execute shell commands, modify CI configuration, and push branches. A compromised agent context has the same blast radius as a compromised developer workstation.
- Avoid unnecessary custom replacements for trusted mechanisms.
- Retain regression checks for the application's actual trust boundaries.
A secure framework cannot determine every business permission or data ownership rule. Those requirements still need clear application design and enforcement.
Recheck the changed behaviour against the original failure conditions and the legitimate user journey. Keep enough evidence to show which release and configuration were verified, and include related entry points that depend on the same security decision.
Related issues
- Running a practical secure code review process
- Delivering application secrets without embedding them in code
- Hardening PHP runtime settings for production applications
Read about our methodology or contact pentested.com to discuss secure development and code review.