Engineering
Web app security: the baseline every app needs
Most breaches come from a short list of well-understood mistakes. Here is the security baseline every web app should have, applied consistently.
TL;DR
Most real-world breaches exploit a short list of well-understood mistakes. Get authentication, input validation, secrets, headers, and dependency hygiene right and you close the majority of your exposure.

Most web app breaches do not come from exotic zero-days. They come from a short list of well-understood mistakes made in ordinary codebases. You do not need to be a security researcher to close them. You need a concrete baseline, applied consistently from the start.
Get authentication and sessions right
This is where serious failures cluster, so do not invent it. Use a battle-tested library or a managed auth provider rather than hand-rolling password hashing and session logic. The primitives exist; use them.
- Hash passwords with bcrypt or argon2. Never store them reversibly or use MD5/SHA1.
- Issue short-lived tokens, store session state in
HttpOnlysecure cookies, and make logout actually invalidate the session server-side. - Enforce authorization on the server, on every request. Hiding a button in the UI is not access control. Check permissions on the backend, and default to deny.
Broken access control, a user reaching data or actions they should not have, is consistently among the most common and damaging vulnerabilities in production apps. The fix is straightforward: never trust the client to tell you what the user is allowed to do.
Treat all input as hostile
Every piece of data arriving from a client is a potential attack vector. Two classes of vulnerability still dominate real incidents.
Injection. Always use parameterized queries or an ORM that handles escaping for you. Never build SQL by concatenating user-supplied strings. This closes SQL injection at the source and takes about zero extra effort in any modern stack.
Cross-site scripting (XSS). Escape and sanitize user-supplied content before rendering it. React and Next.js help by default, but dangerouslySetInnerHTML and equivalent escape hatches will bite you if you use them carelessly.
Validate input on the server against a strict schema. Client-side validation is a user experience feature; it is not a security control, because any client can bypass it.
Protect secrets and configuration
Credentials in your codebase are a breach waiting to be indexed by a scanner. Keep secrets out of source control entirely. Use environment variables in development and a secrets manager in production. If a key leaks, rotate it immediately.
Scan your repository history, not just the current files. A secret committed once lives in the git log until it is explicitly purged. Tools like git-secrets or Gitleaks can catch this in CI before anything reaches a remote.
Ship secure headers and HTTPS
A handful of cheap defaults raise the floor considerably:
- HTTPS everywhere, with HSTS configured so browsers refuse to downgrade.
- A Content-Security-Policy header to reduce XSS blast radius, plus
X-Content-Type-Optionsand frame protections. - CSRF protection for any app using cookie-based sessions, via anti-CSRF tokens or the
SameSitecookie attribute. - Rate limiting on authentication endpoints and anything else sensitive to brute-force attempts. See rate limiting AI features and cost control for a practical look at this in API-heavy products.
Libraries like Helmet (Node/Express) and Next.js middleware make adding these headers a few lines of configuration.
Keep dependencies honest
A modern web app is mostly other people's code, and vulnerabilities in that code become yours to inherit. Run automated dependency scanning in CI using something like npm audit, Snyk, or Dependabot. Keep packages reasonably current. Be deliberate about what you add, because every dependency is additional attack surface.
A vulnerable library you have not updated in eighteen months is a common path in. It is also one of the easiest to close.
Make it a posture, not a checklist
Security is not something you complete once before launch. The baseline above becomes effective only when it is baked into how you work day-to-day: parameterized queries by default in every data access layer, secrets never committed, dependency scans running in every pipeline, and authorization checks on every endpoint.
For teams building on React, Next.js, NestJS, or Supabase, most of this falls naturally out of framework conventions if you pay attention early. Retrofitting it into an app that grew without these defaults is more expensive. See technical debt management and how to secure your web app for more on what that cost looks like in practice.
Do the basics consistently and you will be ahead of most applications in production, and well outside the reach of the opportunistic, automated attacks that account for the majority of real-world damage.
If you want a security review before shipping something that handles sensitive data, let's talk.
Frequently asked questions
what is the most common web app security vulnerability
Broken access control tops most lists. It happens when authorization is checked in the UI rather than enforced on the server for every request. Fix it by defaulting to deny and verifying permissions on the backend on every call.
should I build my own authentication system
No. Use a battle-tested library or managed auth provider. Hand-rolling password hashing and session logic is where serious failures start. The primitives exist; use them.
how do I keep secrets out of my codebase
Use environment variables or a secrets manager and never commit credentials to source control. Scan your git history too, not just the current files, because a key committed once stays in the history until it is purged.
how often should I audit web app security
Treat it as a continuous posture rather than a pre-launch event. Automate dependency scanning in CI, enforce secure defaults in code review, and run a focused review before shipping anything that handles sensitive data.
How Pykero can help
Services related to this article.
Building something like this?
Pykero Agency designs and ships production web, mobile, SaaS, and AI products.
Talk to us


