What do most successful cyberattacks have in common? Here's the surprise: they're rarely genius-level hacks. Year after year, attackers walk in through the same few unlocked doors — simple mistakes that take minutes to prevent once you know them. Let's learn those doors, and how to lock them from day one.

Security is a habit, not a feature

Beginners often think security is something you "add later," like a dark mode toggle. It isn't. Security is a set of small habits you apply while writing everyday code — the same way you already indent consistently or name variables clearly. Build the habits now, while your projects are small, and they'll be automatic when the stakes are real. Five mistakes cause a huge share of real-world breaches. Here they are.

Mistake 1: SQL injection

Imagine your app looks up a user by email, and you build the query by gluing strings together:

// DANGER: never do this
var sql = "SELECT * FROM Users WHERE Email = '" + email + "'";

Looks harmless — until someone types ' OR '1'='1 into the email box. Now the query becomes "give me every user," because their input was executed as code. That's SQL injection, one of the oldest and still most common attacks on the web. The fix is a parameterized query: you send the SQL and the user's value separately, and the database treats the value as pure data, never as code.

// Safe: the value can never become SQL code
using var command = new SqlCommand(
    "SELECT * FROM Users WHERE Email = @Email", connection);
command.Parameters.AddWithValue("@Email", email);

Tip: If you use an ORM like Entity Framework, LINQ queries are parameterized for you automatically — one more reason LINQ is worth learning early.

Mistake 2: Trusting user input

SQL injection is really one example of a bigger rule: never trust input. Anything a user can send — form fields, URL parameters, uploaded files, API request bodies — can be malformed, malicious, or both. And here's the catch beginners miss: checking input in your web page's JavaScript is not enough, because attackers can skip your page entirely and call your API directly. Validate on the server, always: check types, lengths, ranges, and formats, and reject anything that doesn't fit. Client-side checks are a convenience for honest users; server-side checks are the actual lock.

Mistake 3: Cross-site scripting (XSS)

XSS is injection's twin, aimed at the browser instead of the database. If your app displays user-provided text — a comment, a username — without encoding it, an attacker can submit something like <script>stealCookies()</script>, and that script runs in every visitor's browser. The habit that prevents it: encode output, so text is displayed as text rather than executed as HTML. Modern frameworks like Blazor and React encode by default — the danger appears when you use "raw HTML" escape hatches, so treat those with real suspicion.

Mistake 4: Secrets in source code

An API key pasted into a source file feels harmless — until you push that file to a repository. Bots scan public repos around the clock, and a leaked key can be found and abused within minutes. Worse, Git remembers: even if you delete the key in your next commit, it lives on in history. Keep secrets out of code entirely:

// DANGER: this ends up in Git history forever
const string ApiKey = "sk-live-abc123...";

// Better: read it from the environment at runtime
var apiKey = Environment.GetEnvironmentVariable("PAYMENT_API_KEY");

For local development, .NET's user secrets feature stores values outside your project folder; in production, use your host's environment variables or a dedicated secret store. If a key ever does leak, deleting the file isn't enough — revoke the key and issue a new one.

Mistake 5: Outdated dependencies

Your app is mostly other people's code — packages, frameworks, libraries. When a security hole is found in one of them, a fix usually ships fast... but only helps if you actually update. Attackers love known vulnerabilities in old versions because the exploit instructions are public. Make updating routine: enable automated dependency alerts on your repository, and check your own projects with a single command:

dotnet list package --vulnerable

Your security habits checklist

  • Query with parameters — never build SQL from user input.
  • Validate on the server — client-side checks are decoration.
  • Encode output — and be suspicious of raw-HTML escape hatches.
  • Keep secrets out of code — environment variables or a secret store, never a commit.
  • Update dependencies — old versions are open doors with public maps.

Note: This applies to AI-generated code too. Coding assistants are great, but they can happily produce string-concatenated SQL if you don't ask for better. You are the security reviewer — now you know what to look for.

Keep going

Five doors, five locks — that's a genuinely strong foundation, and you learned it in five minutes. Nobody becomes a security expert overnight, but every developer can refuse to make the easy mistakes, starting today. Next, see where much of this input actually arrives from in REST APIs explained with a pizza shop, and get comfortable with the databases you're now protecting in SQL vs. NoSQL: which to learn first? Happy (safe) coding!