Web security best practices: the short answer
The web security best practices that matter most are simple to list. Encrypt all traffic. Keep software updated. Protect logins with a second step. Treat every piece of user input as untrusted. Then test the site regularly. The rest of this checklist builds on those habits.
Each item below maps to the OWASP Top 10. OWASP is a nonprofit that publishes free web security guidance. Its Top 10 is the most widely used list of serious web app risks. The current edition is from 2025. Our guide to the OWASP Top 10 explained covers each risk in detail.
| # | Practice | OWASP Top 10:2025 risk it helps with |
|---|---|---|
| 1 | HTTPS everywhere, with HSTS | A04 Cryptographic Failures |
| 2 | Fast updates for software and libraries | A03 Software Supply Chain Failures |
| 3 | Strong logins and MFA | A07 Authentication Failures |
| 4 | Least privilege for users and staff | A01 Broken Access Control |
| 5 | Check all input, and use safe database queries | A05 Injection |
| 6 | Security headers and safe settings | A02 Security Misconfiguration |
| 7 | Keep secrets out of code | A04 Cryptographic Failures, A07 Authentication Failures |
| 8 | Handle errors safely | A10 Mishandling of Exceptional Conditions |
| 9 | Logging and monitoring | A09 Security Logging and Alerting Failures |
| 10 | Tested backups | Limits damage from any attack |
| 11 | A web application firewall | Extra layer, mainly against A05 Injection |
| 12 | Regular testing | All ten, including A06 Insecure Design |
Encryption and updates
1. Use HTTPS everywhere and turn on HSTS. HTTPS encrypts traffic between the browser and your site. It is the padlock in the address bar. HSTS is a setting that tells browsers to always use the secure version, even if someone types the plain address. Free certificates are widely available, so there is no reason to skip this.
2. Patch fast, including the libraries your code uses. Modern sites are built from many outside code packages (dependencies). A flaw in one of them is a flaw in your site. Use a tool that warns you when a package has a known problem, and update within days for serious ones.
Two recent cases show why. React2Shell let attackers take over servers running React Server Components, which many Next.js apps use. PHP2Shell did the same to PHP servers. In both cases, sites that updated quickly were safe. Sites that waited were at risk.
Logins and access
3. Protect logins and require MFA. MFA is a second login step, such as a code on your phone. Require it for every admin account, and offer it to customers. Also limit failed login attempts, and check new passwords against lists of known leaked ones. Passkeys are a strong option if your platform supports them.
4. Give people only the access they need. This is called least privilege. Staff, users and even your app's own database account should have the smallest set of rights that still lets them work. Check access on the server for every request. A user should never see another customer's order just by changing a number in the address bar.
Web application security in the code
These items are for your developers. They stop the attacks that target the app itself.
5. Never trust user input. Anything a visitor types or sends can be an attack. Two common examples:
- SQL injection: an attacker types database commands into a form field. If the site pastes that text straight into a query, the attacker can read or delete your data. The fix is parameterized queries, which keep data and commands apart.
- Cross-site scripting (XSS): an attacker gets the site to show their script to other visitors. The script can steal logins or change the page. The fix is to encode output, so the browser shows the text instead of running it.
6. Set security headers and safe defaults. Headers are short instructions your site sends to the browser. A Content-Security-Policy (CSP) tells the browser which scripts it may run, which limits XSS. Other useful headers stop your pages being loaded inside other sites. Also turn off default accounts, sample pages and directory listings.
7. Keep secrets out of your code. Secrets are passwords, API keys and tokens. (An API is how one piece of software talks to another.) Never store them in source code or shared documents. Use a secrets manager from your cloud or hosting provider. Change them when someone leaves or a leak is suspected.
8. Handle errors safely. Show visitors a plain error page, not a technical one. Detailed errors can reveal file paths and software versions. Make sure the app fails closed. If a check breaks, access should be denied, not allowed.
Backups, logging and a firewall
9. Log the events that matter and watch them. Record logins, failed logins, admin changes and payment changes. Send the logs somewhere an attacker cannot easily erase them. Set alerts for unusual activity, and make sure someone reads them.
10. Back up and test restores. Keep copies of your site, database and settings, with at least one copy the web server cannot change or delete. Restore from them on a schedule. A backup you have never restored may not work when you need it.
11. Put a web application firewall in front of the site. A web application firewall (WAF) filters traffic and blocks common attacks before they reach your app. It buys time while you fix a flaw. It is not a fix by itself.
Website security checklist step 12: test regularly
12. Test the site, not just the checklist. Good intentions drift as code changes. Use a mix of testing methods:
- Automated code checks while developers write code (SAST) and checks against the running site (DAST). Our SAST vs DAST guide explains the difference.
- Regular vulnerability scans to catch missing updates and weak settings.
- A penetration test at least once a year, and after major releases. A skilled tester looks for logic flaws that tools miss.
How NextGarrison helps
We test websites, web apps and APIs against the OWASP Top 10 and beyond. You get findings ranked by real risk and clear steps your developers can follow. We can also retest once fixes are in. See our services or request a web application test.
Sources

Need a hand with this?
Talk to a senior consultant. We reply within one business day with clear next steps and a scoped quote.
Prefer to just ask? Contact us and a consultant will reply.
Written by
Vince AntonioSecurity writer and consultant, NextGarrison
Vince writes NextGarrison's security news, technical vulnerability write-ups and guides. He covers actively exploited flaws, penetration testing, SOC monitoring and getting ready for SOC 2, ISO 27001 and PCI DSS, in plain English with sources for every claim.
Want the next alert like this one?
New vulnerability alerts as soon as we publish them. Free, no sign-up, works in Feedly, Outlook, Slack and Teams.
