DEV Community

Fahad Bin Siddique
Fahad Bin Siddique

Posted on

Protecting applications against SQL Injection, XSS, and CSRF.

One missing security check can turn a working application into a serious security problem.

The scary part?

SQL Injection, XSS and CSRF usually don't require some vulnerability.

They often start with something simpler:

Untested input.

When building backend systems it's easy to focus on whether the API works

A better question is:

"What happens if someone doesn't use it the way I expect?"

That's where backend security becomes part of everyday developmentβ€”not something to think about after deployment.

Here are three vulnerabilities every backend developer should understand:

πŸ”΄ SQL Injection

It happens when untrusted user input gets mixed directly into SQL queries.

The safer approach?

Use queries or your frameworks ORM properly instead of building SQL strings from user input.

Think:

User input β†’ Validate β†’ query β†’ Database

Not:

User input β†’ String concatenation β†’ Database

🟠 XSS. Cross Site Scripting

If user-controlled content is rendered as HTML/JavaScript, an attacker may be able to inject malicious scripts into another users browser.

That's why:

βœ… Output encoding matters

βœ… Sanitization matters when HTML is actually allowed

βœ… Content Security Policy can provide another layer of defense

βœ… Never assume user-provided content is safe

🟑 CSRF. Cross Site Request Forgery

This one is especially important when authentication relies on cookies.

A malicious website may try to trick a users browser into sending an authenticated request to your application.

That's why proper:

β†’ CSRF tokens

β†’ cookie settings

β†’ Origin/Referer validation where appropriate

β†’ Secure authentication design

matter.

One thing I've learned from development:

Security isn't a feature you add at the end.

It should influence how you design the API handle input manage authentication, store data and configure the application from the beginning.

A practical security mindset I try to keep:

βœ… Treat every input as untrusted.

βœ… Prefer framework defaults instead of reinventing security mechanisms.

βœ… inputβ€”but don't confuse validation with output encoding or authorization.

βœ… Use queries/ORMs for database access.

βœ… Protect state-changing requests, against CSRF when cookies are involved.

βœ… Keep dependencies and frameworks updated.

βœ… Don't expose information through errors, logs or API responses.

πŸ’‘ The goal isn't to make an application impossible to attack.

The goal is to make attacks much harderβ€”and to design the system so that one mistake doesn't become a complete compromise.

Whats one backend security mistake you've seen often?

BackendSecurity #CyberSecurity #WebSecurity #SoftwareDevelopment #fahadbinsiddique

Top comments (0)