Building Real Things

Don't Get Burned: Security Basics

You do not need to be a security expert — you need to not make the five classic mistakes that turn a weekend project into a very bad month.

Security sounds like an advanced topic. It is not — it is a beginner topic, because the worst breaches of small projects come from beginner mistakes, and AI-generated code makes several of them by default unless you know to ask. A few rules, learned once, prevent almost all of it.

The rules that prevent most disasters

  • Secrets never go in frontend code — remember, the frontend is PUBLIC. API keys pasted "just to test" get scraped by bots within hours and can rack up real bills. Secrets live server-side, in environment variables, always.
  • Never trust input from users — anything a person can type will eventually contain something hostile. Validate on the SERVER (frontend checks are politeness, not protection).
  • Don't build your own login — use a proven auth service or framework feature. Hand-rolled password systems are how databases end up dumped online.
  • The backend enforces the rules — hiding a button in the frontend is not security; the request it made can be sent by anyone directly. Every permission check belongs on the server.
  • Keep secrets out of code-sharing too — a key committed to a public repository is compromised the moment it lands, even if you delete it after.

When you use AI to build, add one habit: ask it "what are the security problems with this code?" — it is genuinely good at auditing its own output, but only when asked. Generated code optimizes for working, not for safe; the review step is yours.

The classic burn: a leaked API key on a pay-per-use service. Bots scan the public internet for keys around the clock — this is not a "who would target little me?" situation; it is automated and indiscriminate. Environment variables + spending limits on every paid key, from day one.

That is the whole beginner curriculum: secrets server-side, validate input, rent your auth, enforce on the backend, ask AI to audit. Five habits, learned in an afternoon, that separate builders from cautionary tales.

Key takeaways

1Frontend is public: secrets live server-side in environment variables, always.
2Validate everything on the server; the backend — never the UI — enforces rules.
3Rent proven auth, set spend limits on keys, and make AI audit its own code.

This is one lesson of 541.

The whole Foundation is free — 16 subjects, beginner to advanced. Sign in to track what you have read, take the end-of-module quizzes, and use the terminal.