AI-coded apps

    Does AI-generated code have security vulnerabilities?

    A 2026 view of AI-generated code that runs correctly but contains hardcoded secrets, missing access checks, and insecure defaults flagged in a security review

    AI coding tools are great at producing code that works, and "works" and "secure" are not the same thing. Research has repeatedly found that a substantial share of AI-generated code contains security weaknesses, and the reason is structural: models learn from public code that includes insecure patterns, they optimize for a working result, and they do not know your threat model. For mobile apps the effect shows up as hardcoded secrets, weak access rules, and insecure storage. The takeaway is not to avoid AI, but to treat its output as a draft to review. Here is why the vulnerabilities appear and how to ship AI code safely.

    Short answer

    Yes, AI-generated code commonly contains security vulnerabilities. Studies have repeatedly found that a significant portion of code produced by AI assistants includes weaknesses, because models are trained on public code that contains insecure patterns, they optimize for code that works rather than code that is secure, and they lack the context of your specific threat model. Per OWASP, the result is familiar issues like hardcoded secrets, injection flaws, weak cryptography, and missing access checks. The fix is not to avoid AI but to treat its output as a draft: review it, do not trust insecure defaults, and verify the result, since the model produced something functional, not something audited.

    What you should know

    • AI code often has vulnerabilities: a significant share contains weaknesses.
    • It optimizes for working, not secure: functional output is not audited output.
    • It learns insecure patterns: trained on public code that includes them.
    • It lacks your threat model: it does not know what you need to protect.
    • Treat it as a draft: review and verify before shipping.

    Does AI-generated code have vulnerabilities?

    Yes, and the reasons are built into how these tools work. Research on AI coding assistants has consistently found that a meaningful fraction of generated code contains security flaws, and that developers using AI assistance sometimes produce less secure code while feeling more confident about it. Three structural causes drive this. First, models are trained on large amounts of public code that includes plenty of insecure examples, so they reproduce those patterns. Second, they are optimized to produce code that satisfies the request and runs, and security is not the same objective as functionality, so a working result can still be insecure. Third, the model does not know your application's threat model, what data is sensitive, what must be protected, what an attacker would target, so it cannot make the judgment calls security depends on. The output is plausible and functional, which is exactly why its weaknesses are easy to miss.

    What vulnerabilities does AI commonly introduce?

    The same categories that show up in insecure code generally. The table lists the frequent ones.

    VulnerabilityHow it appears in AI output
    Hardcoded secretsKeys or tokens embedded in the code
    Injection flawsUnsanitized input in queries or commands
    Weak or misused cryptographyOutdated algorithms or hardcoded keys
    Missing access checksEndpoints or data without authorization
    Insecure defaultsPermissive configuration left as generated

    For mobile apps specifically, these surface as a key hardcoded in the client, a database left open because access rules were generated as permissive, sensitive data written to insecure storage, or cleartext network calls. None of it looks wrong at a glance, because the app runs; the weakness is in what the code does not do, validate, restrict, encrypt, rather than in an obvious bug.

    How do you ship AI-generated code safely?

    Treat it as a starting point and put a security step between generation and release. Review the code with security in mind rather than only checking that it works, paying attention to the categories above, secrets, input handling, access control, crypto, and configuration. Do not trust insecure defaults; the model often leaves permissions broad and storage plain because that is the path of least resistance. Move real secrets to your backend, enforce access server-side, and use proper secure storage and strong standard crypto. For anything sensitive or production-facing, add a human security review, since the model cannot reason about your threat model. And verify the built artifact, not just the source, because the question that matters is what actually ships. AI accelerates the writing; the security judgment is still yours to apply.

    What to watch out for

    The first trap is trusting AI code because it works and looks clean, when functional and secure are different properties and the weaknesses are in what the code omits. The second is shipping insecure defaults, broad permissions, plain storage, embedded keys, that the model produced for convenience. The third is assuming a future review will catch it, which often does not happen before launch. A pre-submission scan such as PTKD.com (https://ptkd.com) reads your compiled APK, AAB, or IPA against OWASP MASVS and surfaces hardcoded secrets, insecure storage, cleartext traffic, and related issues, giving you an objective check on what the AI-generated code actually shipped. That turns "it works" into "it is verified."

    What to take away

    • Yes, AI-generated code commonly contains security vulnerabilities, because models optimize for working code, learn insecure patterns, and lack your threat model.
    • The common issues are hardcoded secrets, injection flaws, weak cryptography, missing access checks, and insecure defaults.
    • Treat AI output as a draft: review it for security, do not trust insecure defaults, keep secrets server-side, and add a human review for sensitive code.
    • Verify the built artifact with a pre-submission scan such as PTKD.com, so you ship something checked rather than just functional.
    • #ai-generated-code
    • #vulnerabilities
    • #ai-coded-apps
    • #secure-coding
    • #owasp
    • #app-security
    • #code-review

    Frequently asked questions

    Does AI-generated code have security vulnerabilities?
    Yes, commonly. Research on AI coding assistants has repeatedly found that a meaningful fraction of generated code contains security flaws, and that developers using AI sometimes produce less secure code while feeling more confident. The reasons are structural: models learn from public code that includes insecure patterns, they optimize for a working result rather than a secure one, and they lack your threat model. The output is functional and plausible, which is why its weaknesses are easy to miss.
    Why does AI produce insecure code?
    Three structural reasons. Models are trained on large amounts of public code that includes insecure examples, so they reproduce those patterns. They are optimized to produce code that satisfies the request and runs, and functionality is not the same objective as security. And they do not know your application's threat model, what data is sensitive or what an attacker would target, so they cannot make the judgment calls security depends on. The result works but is not audited.
    What vulnerabilities does AI code commonly have?
    The same categories as insecure code generally: hardcoded secrets like keys or tokens in the code, injection flaws from unsanitized input, weak or misused cryptography, missing access checks on endpoints or data, and insecure defaults left as generated. In mobile apps these appear as keys embedded in the client, open database access rules, sensitive data in insecure storage, or cleartext network calls. They are weaknesses of omission, so the app runs while lacking validation, restriction, or encryption.
    Can I ship AI-generated code safely?
    Yes, if you treat it as a draft and add a security step. Review the code for secrets, input handling, access control, crypto, and configuration rather than only checking that it works. Do not trust insecure defaults; move real secrets to your backend, enforce access server-side, and use secure storage and strong crypto. Add a human security review for sensitive or production code, and verify the built artifact, since what ships is what matters.
    How do I check AI-generated code for vulnerabilities?
    Verify the build, not just the source. A pre-submission scan such as PTKD.com reads your compiled APK, AAB, or IPA against OWASP MASVS and surfaces hardcoded secrets, insecure storage, cleartext traffic, and related issues, giving you an objective check on what the AI-generated code actually shipped. That complements a manual review and turns a working app into a verified one, which matters because the vulnerabilities in AI code are exactly the kind that do not show up by running it.

    Keep reading

    Scan your app in minutes

    Upload an APK, AAB, or IPA. PTKD returns an OWASP-aligned report with copy-paste fixes.

    Try PTKD free