Blog / Build with AI /

AI and security: what to check before you ship

AI writes code that works. That’s different from code that’s safe.

When an assistant builds you a form, a login or a plugin, it aims at “does the thing you asked”. It doesn’t automatically think about someone who wants to abuse it. The result can run perfectly in a demo and still leave a door open on launch day.

If you’re about to put an AI-built tool, plugin or page in front of real users, here’s a checklist to work through first. It won’t make anything bulletproof. It’ll catch the mistakes that cause most problems.

For the wider background, see security basics for AI-built web apps and copying code from AI safely: what to check first. This post is the pre-flight version.

1. Secrets: nothing sensitive in the code

The most common AI-era mistake: an API key pasted into code, then published.

  • Search your project for keys, tokens, passwords and database URLs.
  • Never put secrets in front-end code, meaning anything running in the user’s browser. Anyone can view it.
  • Keep them in environment variables or your platform’s secret storage.
  • If you ever pasted a real key into an AI chat or a public repository, treat it as exposed: revoke it and create a new one.
  • Check your version history too. A key removed today may still sit in an old commit.

2. Inputs: never trust what users type

Anything a user can type, upload or send is untrusted. The classic failures are still the classics:

  • Cross-site scripting (XSS): user text displayed on a page without being escaped, letting someone inject a script.
  • SQL injection: user text placed straight into a database query.
  • File uploads: accepting any file type or size.

Ask the AI directly: “Review this code for XSS, SQL injection and unsafe file handling. List each risk and the fix.” Then check its answers rather than trusting them. In WordPress, use the built-in functions for escaping output, sanitising input and checking nonces, and make sure the generated code actually does.

3. Permissions: who can do what

Whatever your tool does, ask who is allowed to do it.

  • Does every admin action check that the user is logged in and has the right role?
  • Can one user see or change another user’s data by changing a number in the URL?
  • Does a visitor-facing form let anyone trigger something expensive, like sending emails or calling a paid AI service?

AI often builds the feature and forgets the permission check. Look for it explicitly.

4. Dependencies: what you’ve pulled in

AI is generous with libraries.

  • List what your project depends on.
  • Remove anything unused.
  • Make sure each package is a real, maintained one. Assistants sometimes suggest packages that don’t exist or are abandoned, which is an opening for someone to publish a malicious package under that name.
  • Keep dependencies updated, and know how you’ll hear about security fixes.

Browser extensions that are a security risk is a good reminder of how much a small tool can quietly touch.

5. Data: collect less, protect what you keep

  • Do you actually need each piece of personal data? Delete what you don’t.
  • Is anything stored in plain text that shouldn’t be, such as passwords or tokens? Passwords should never be stored in a readable form.
  • Is traffic over HTTPS everywhere?
  • Do you know what any AI service you call does with the text you send it?

Privacy-first tools: keeping user data local shows how to avoid the problem by not collecting the data.

6. AI-specific risks

If your tool uses AI at runtime, there are extra items:

  • Prompt injection: if the AI reads content from users or the web, that content can contain instructions that try to override yours. Don’t give the AI power to take sensitive actions based on text it just read.
  • Output you display: treat AI output as untrusted text. Escape it before showing it on a page.
  • Cost abuse: someone can hammer a public AI feature and run up your bill. Add rate limits and caps. Caching AI answers to save money helps with cost, and moderation and safety filters in AI apps covers misuse.
  • Leaking your instructions: assume anything in a system prompt could be extracted. Don’t put secrets there.

7. Error messages and logs

Detailed error messages help you debug and help attackers learn about your system. Show users a friendly message; log the details privately. And keep personal data and secrets out of logs. Logging: knowing what your tool did explains how.

8. Test the unhappy paths

Try to break your own tool:

  • Empty fields, very long text, special characters.
  • A logged-out user visiting an admin page.
  • Changing IDs in a URL.
  • Uploading the wrong file type.
  • Submitting a form a hundred times.

If you can break it in ten minutes, someone else can in five.

9. Backups and a way back

Before launch, have a backup you’ve actually restored once, and know how to take the thing offline quickly. If something goes wrong, you’ll want to disable it in minutes, not hours. Backups as security: the last line of defence covers the principle.

10. A second pair of eyes

For anything involving payments, logins or sensitive data, have a developer or security-minded friend review it. Asking a developer to review AI-written code shows how to make that request useful.

What AI can and can’t do here

You can ask an assistant to run a security review of its own code, and it will find real issues. It also misses things and sometimes invents problems. Treat its review as a first pass, not a certificate.

The one-page pre-launch checklist

Key takeaways

  • AI-built code needs the same security checks as any other, and more attention to secrets and permissions.
  • Never trust user input or AI output without escaping.
  • Rate-limit anything that costs money.
  • Have a backup and an off-switch before launch.

Which item on that list have you never checked on your own project?