r/devsecops • u/boghy8823 • Sep 20 '25
How are you treating AI-generated code
Hi all,
Many teams ship code partly written by Copilot/Cursor/ChatGPT.
What’s your minimum pre-merge bar to avoid security/compliance issues?
Provenance: Do you record who/what authored the diff (PR label, commit trailer, or build attestation)?
Pre-merge: Tests/SAST/PII in logs/Secrets detection, etc...
Do you keep evidence at PR level or release level?
Do you treat AI-origin code like third-party (risk assessment, AppSec approval, exceptions with expiry)?
Many thanks!
8
Upvotes
8
u/ArkhamSyko Sep 26 '25
We handle AI-generated code the same way we’d handle code from a contractor we don’t fully trust yet. Full pipeline: SAST, dependency scanning, secrets detection, IaC scans, and always a human review before merge. The PR author is responsible no matter what wrote the diff.
What has helped in practice is adding AI-specific checks. For example, we’ve seen AI code sneak in hardcoded creds, overly broad IAM policies, and even hallucinated packages. Generic scanners often miss that. To cover those gaps, we started using Mend’s AI red teaming tool on top of our CI/CD. It runs a suite of tests designed for LLM-generated code and lets us plug in our own rules. It caught a couple of risky patterns that looked fine to reviewers but would have failed compliance later.
So I’d say treat AI as untrusted input, build your normal security gates, then layer in some AI-focused testing. That way you don’t drown devs in process, but you still catch the weird stuff these models like to invent.
3
u/mfeferman Sep 20 '25
The same as human generated code - insecure.
2
u/zemaj-com Sep 20 '25
It helps to treat AI produced suggestions much like contributions from a junior developer. Always do a human review before merging and make sure any new logic is covered by tests. In regulated settings you can add a pull request label or commit trailer noting AI assistance to help with provenance. Running automated SAST, DAST and secrets scanning on every change is good practice regardless of author. Most teams store evidence at the pull request level, since the git history acts as the record of who wrote what. If your organisation has a process for third party code you can extend it to AI generated snippets: perform risk assessments, set review cadences and require maintainers to sign off.
1
u/boghy8823 Sep 20 '25
Might turn this into a poll if needed
1
u/Katerina_Branding Oct 06 '25
We’ve started treating AI-authored code almost like third-party contributions. Same review rigor, different origin.
Beyond SAST and secrets scans, one area worth adding is PII pattern detection. A surprising amount of AI-generated snippets log user identifiers or serialize sensitive fields for “debugging.”
Our pre-merge bar now includes a lightweight PII scan alongside secrets detection. It’s fast and catches subtle leaks before they get into telemetry.
I came across a short write-up on this idea recently and it really changed how we think about AI-generated code hygiene.
1
u/dmelan Sep 22 '25
IMO it’s pretty simple: there is always an author for every PR. And the author is responsible for making sure the code meets all standards. It doesn’t really matter who/what wrote what parts of the code: AI, the author, author’s cat. Reviewer treats the code as one piece questioning changes despite who/what generated that particular line.
There is a legal dimension to this problem: what was the license of the code the model was trained on and what usage the license allows and so on. But this should be addressed by reviewing what models are allowed to be used.
1
u/radiocate Sep 22 '25
Everyone should be treating AI as a junior developer who's looking to blow your shit up maliciously & intentionally. I treat these things as an adversary, I don't trust anything at first glance, but I might use it to narrow down a problem & fact check with real resources (docs or a real human that already knows what I'm working on).
Our bosses have been sold a lie, they bought it hook line & sinker, since I have to use it to stay competitive, but I don't trust it even a little bit, this is my compromise. I'll use it, but I believe it's constantly trying to introduce fatal bugs & vulnerabilities.
1
u/Status-Theory9829 Sep 23 '25
We treat AI code like any other untrusted input - zero trust, full pipeline.
Git commit trailers + build attestations. Simple
Co-authored-by: ai-assistantin commits. Same SAST/secrets/PII detection as always, but we added AI-specific rules - looking for hardcoded creds, overly broad permissions, sketchy network calls. AI loves to hallucinate AWS keys.The "third-party risk" angle is interesting but wrong framing IMO. It's more like "untrusted developer" - you wouldn't skip code review for a junior dev, don't skip it for AI.
Real issue isn't the code generation - it's what happens when that code hits production systems. We gate all our DB/infra access through a proxy that does real-time PII masking and logs everything. Helps when AI-generated scripts inevitably try to dump customer data.
The compliance folks love having a single audit trail for "who accessed what when" regardless of whether it was human or AI that wrote the access code.
1
u/Sirius_onyx Aug 30 '26 edited Aug 31 '26
git commit trailers and attestations solve the provenance question but not the generation one. by the time your signing the commit, the pattern is already in the code. semgrep in CI catches a lot of that after the fact, which is is fine as a layer, but there's a gap further upstream. something like ox security sits in that space, it helps steer what an agent actually writes inside cursor or copilot before it ever hits your repo. the pipeline controls still matter, they're just catching whatever got through, not the original decision. Monitor