Web app security best practices start with the OWASP Top 10: enforce server-side access control, use parameterized queries, require TLS 1.2 or higher with strong headers, hash passwords with Argon2 or bcrypt, offer phishing-resistant MFA, patch dependencies quickly, validate every input on the server, log security events centrally, and test with regular penetration tests.
Key takeaways
- Most web breaches come from known, fixable flaws: broken access control, injection and misconfiguration, not novel attacks.
- Enforce every security decision on the server, never in the browser, and default to deny.
- Security is a release gate: scan, test and log on every deploy, and have a written incident plan before you need it.
Most web applications are not breached through a clever zero-day. They are breached through a missing authorization check, an unpatched library, a weak password or a header that was never set. This guide turns the OWASP Top 10 and CISA Secure by Design guidance into a checklist your team can actually ship against.
What are web app security best practices?
Web app security best practices are the controls that stop the most common attacks: server-side access control, parameterized queries, TLS, strong authentication, secure headers, patched dependencies and central logging. The OWASP Top 10 is the standard list to measure against, and CISA's Secure by Design guidance adds the same idea at the product level.
Start with the highest-impact controls first. A perfect CSP does not help if any logged-in user can read another user's invoices by changing an ID in a URL. Fix access control and injection before you polish the rest. CISA's Secure by Design guidance makes the same point at the product level.
What is the OWASP Top 10?
The OWASP Top 10 is a standard awareness document listing the most critical risks to web applications. The 2021 edition, still the current reference most teams use, ranks broken access control first, followed by cryptographic failures and injection.
| Rank | Risk | Main defense |
|---|---|---|
| A01 | Broken access control | Server-side authorization on every request, deny by default |
| A02 | Cryptographic failures | TLS 1.2 or higher, Argon2 or bcrypt, managed keys |
| A03 | Injection | Parameterized queries, output encoding |
| A04 | Insecure design | Threat modeling before building |
| A05 | Security misconfiguration | Hardened defaults, secure headers |
| A06 | Vulnerable components | Dependency scanning, patch SLAs |
| A07 | Authentication failures | MFA, session hardening, rate limits |
| A08 | Integrity failures | Signed builds, verified updates |
| A09 | Logging failures | Central, tamper-evident logs and alerts |
| A10 | Server-side request forgery | Allowlist outbound requests, block private IPs |
Use the list as a prioritization tool, not a one-off audit. Map each category to an owner, a control and a test, and re-check it on every major release. Our small business cybersecurity checklist covers the same controls alongside backups and device security.
How do you fix broken access control?
Enforce authorization on the server for every request, check that the resource belongs to the current user, and default to deny. Never rely on hiding a button in the user interface, because an attacker can call the API directly.
Common failures include insecure direct object references, where changing /api/orders/12345 to 12346 returns someone else's order, missing checks on POST, PUT and DELETE endpoints, and privilege escalation through tampered tokens. Test for each one: log in as a low-privilege user and try to reach admin functions and other users' data.
Use role-based access control for admin features, keep the rules in one place rather than scattered across handlers, and re-check ownership on every data access, not just at the route level.
How should authentication and sessions work?
Require MFA for admin accounts, offer passkeys where possible, hash passwords with Argon2id or bcrypt, and rate-limit login attempts. Sessions should use long random tokens in HttpOnly, Secure, SameSite cookies, and rotate after login.
Set a minimum password length of 12 characters and check new passwords against known breach lists. You can test whether a password already appears in breaches with our pwned password checker. Lock or slow down repeated failures, but avoid permanent lockouts that let an attacker deny service to real users.
Expire sessions after inactivity, invalidate all sessions on password change, and never put sensitive data in a JWT payload, since anyone can read it. Keep access tokens short-lived and refresh tokens revocable.
How do you prevent injection attacks?
Use parameterized queries or a safe ORM for every database call, and never build SQL, commands or LDAP queries by concatenating user input. Encode output for its context so that data is never treated as code.
Injection covers SQL, NoSQL, command and cross-site scripting attacks. The fix is the same pattern: separate code from data, validate input on the server with a strict schema, and reject anything that does not match. Client-side validation is a convenience for users, not a security control.
For XSS specifically, set a Content-Security-Policy that restricts script sources, encode user content when rendering it, and avoid inserting untrusted data into HTML with innerHTML-style APIs.
How do you encrypt traffic and harden headers?
Serve all traffic over TLS 1.2 or higher, prefer TLS 1.3, redirect HTTP to HTTPS, and set HSTS with a long max-age once you are confident the setup is stable. Disable legacy protocol versions and weak cipher suites.
Then set the baseline headers: Content-Security-Policy, X-Content-Type-Options: nosniff, Referrer-Policy and Permissions-Policy. Deploy CSP in report-only mode first, collect violations, then enforce it. Check the result with our free security headers checker.
Confirm the certificate itself with the SSL checker, and read the OWASP Top 10 for the full description of each risk category.
Encrypt sensitive data at rest with strong algorithms and managed keys, never hard-code secrets in source code, and store secrets in a secrets manager or environment variables that are not committed to the repository.
What causes security misconfiguration?
Security misconfiguration is the catch-all for defaults left in place: debug mode on in production, default accounts and passwords, directory listing enabled, overly broad CORS, verbose error messages and unnecessary services running. It is one of the most common findings in real assessments.
Prevent it with hardened defaults, automated configuration checks in CI, and a review of every change to infrastructure. Error pages should give users a generic message and an ID to quote to support, while the detail goes to your logs, never to the browser.
Set CORS to an explicit allowlist of your own front-end domains, never * with credentials, and remove sample applications, test endpoints and unused admin panels from production.
How do you manage vulnerable dependencies?
Pin dependencies with a lock file, scan them in CI on every build, and fix critical vulnerabilities on a defined schedule, for example within days for critical and weeks for high severity. Enable automated update tools such as Dependabot or Renovate.
Keep a software bill of materials so you can answer, in minutes, whether a newly disclosed vulnerability affects you. When a library is unmaintained, has a single maintainer, or has a history of security issues, treat that as a risk and look for a maintained alternative.
Verify the integrity of packages and updates with signatures or hashes where available, and never install packages from untrusted sources in a production build.
What should you log and monitor?
Log logins and failures, password resets, privilege changes, access to sensitive data, data exports and admin actions, then forward them to a central store that attackers cannot easily delete or alter. Alert on patterns, not just single events.
Good logging is the difference between discovering a breach in hours and discovering it months later from a customer complaint. Include enough context to investigate, such as user, time, source IP and the resource accessed, but never log passwords, tokens or full payment details.
Monitor for failed authorization attempts, unusual export volumes and new admin accounts, and make sure someone actually watches the alerts. An alert nobody reads is the same as no alert.
How do you test web app security?
Combine automated and human testing: dependency and secret scanning in CI, dynamic scanning against a staging environment, and a human penetration test at least once a year and after major changes. Each method finds flaws the others miss.
Write security tests for your own rules too. Automated tests that try to access another user's data, submit invalid input and call admin endpoints as a normal user catch regressions before they reach production.
Consider a bug bounty program once the basics are solid. It gives skilled researchers a safe way to report flaws, but it is not a substitute for fixing the OWASP Top 10 first.
What do you do when a web app is breached?
Have a written incident plan before you need it: who decides, who talks to customers, how you preserve evidence, and how you rotate secrets and sessions. In the first hour, contain the damage, preserve logs, and stop the bleeding before you start the post-mortem.
Common mistakes are wiping servers before preserving evidence, delaying customer notification, and fixing only the one exploited flaw while leaving the same pattern elsewhere. After containment, fix the root cause across the whole app, rotate every credential that may have been exposed, and review the logs to understand the full scope.
Practice the plan with a tabletop exercise at least once a year. A plan nobody has rehearsed will not survive first contact with a real incident.
Web app security checklist for 2026
Use this as a release gate. If you cannot check a row, you are shipping with a known risk, so record it and set a date to fix it.
- Access control: server-side checks on every endpoint, deny by default, ownership verified.
- Authentication: MFA for admins, passkeys offered, Argon2 or bcrypt, rate-limited logins.
- Injection: parameterized queries everywhere, server-side validation, CSP enforced.
- Transport: TLS 1.2 or higher, HSTS, strong headers verified with a scanner.
- Secrets: no secrets in code, secrets manager used, keys rotated on a schedule.
- Dependencies: lock file committed, CI scanning on, patch SLA defined and met.
- Logging: security events logged centrally, alerts configured, logs protected.
- Testing: annual penetration test, automated scans on every deploy.
- Incident plan: written, rehearsed, with customer notification steps.
For the wider picture, our guide to spear phishing explains the human side of the same attacks, since many web breaches start with a stolen credential rather than a code flaw.
The bottom line
Web app security is mostly discipline: cover the OWASP Top 10, enforce decisions on the server, patch on a schedule, and log so you can see an attack while it is happening. None of these controls is exotic, and together they stop the flaws behind most real breaches.
Start with the highest-risk item on your own app today, add the release gate to your deploy process, and verify your public headers and certificate with the free security headers checker. Small, consistent controls beat a perfect policy that nobody follows.
Frequently asked questions
What are the most important web app security best practices?
Cover the OWASP Top 10 first: server-side access control, parameterized queries, TLS with strong headers, strong password hashing, MFA, dependency patching, server-side input validation, central logging and SSRF defenses. Those controls stop the flaws behind most real breaches.
What is the OWASP Top 10?
It is OWASP's standard awareness list of the most critical web application risks. The 2021 edition ranks broken access control first, followed by cryptographic failures, injection, insecure design, security misconfiguration, vulnerable components, authentication failures, integrity failures, logging failures and server-side request forgery.
How often should a web app be penetration tested?
At least once a year, and again after any major change such as a new authentication flow, a public API or a payment integration. Automated scanning should run on every deploy, while a human test finds the logic flaws scanners miss.
Is HTTPS enough to secure a web app?
No. HTTPS encrypts traffic in transit, which is essential, but it does not fix broken access control, injection, weak passwords or exposed secrets. You also need secure headers, server-side validation, strong authentication and patched dependencies.
What is the best way to store passwords?
Hash them with a slow, modern algorithm such as Argon2id or bcrypt with a cost factor of 12 or higher, using a unique salt per password. Never store plain-text passwords and never use MD5 or SHA-1 for password hashing.
What security headers should a web app set?
At minimum set Content-Security-Policy, Strict-Transport-Security, X-Content-Type-Options: nosniff, Referrer-Policy and Permissions-Policy. Use frame-ancestors in CSP instead of X-Frame-Options where your framework supports it, and test the result with a header scanner.
How do you protect a web app from supply chain attacks?
Pin dependencies with a lock file, scan them in CI, update them on a fixed schedule, verify signatures where available, and keep a software bill of materials. Treat a new dependency like a new vendor: check who maintains it before you add it.
What should you log for web app security?
Log logins and login failures, password resets, privilege changes, access to sensitive data, data exports and admin actions. Send logs to a central, tamper-resistant store, protect them from deletion, and alert on unusual patterns rather than reading them only after an incident.
Sources
The engineers and analysts who build Cysoro's domain scanner, email-authentication checks and free security tools. We test what we write about every day — SPF, DKIM, DMARC, certificates, look-alike domains and phishing — and check each guide against the relevant standards, government guidance and vendor documentation.
Checked against the OWASP Top 10 (2021), the OWASP Cheat Sheet Series and CISA Secure by Design guidance.
How we write and fact-check →