Attackers rarely need advanced techniques. Most incidents come from a handful of well-known weaknesses, many of them listed in the OWASP Top 10. Getting these ten essentials right protects you from the majority of real-world attacks.
1. Strong authentication
Hash passwords with a modern algorithm such as Argon2 or bcrypt, enforce reasonable length, rate-limit login attempts and offer multi-factor authentication — at least for administrators.
2. Check permissions on the server, every time
Hiding a button in the user interface is not access control. Every API request must check that the signed-in user is allowed to see or change that specific record. Missing checks lead to "insecure direct object reference" bugs, where changing an ID in the URL exposes someone else's data.
3. Validate all input
Treat everything from the browser as untrusted: form fields, query strings, headers and uploaded files. Validate type, length and format on the server, and reject unexpected fields.
4. Prevent injection
Use parameterised queries or a safe ORM for databases. Never build SQL, shell commands or file paths by joining strings with user input.
5. Escape output to stop XSS
Render user content as text, not HTML. If you must allow formatting, use a well-tested sanitiser. Add a Content Security Policy as a second line of defence.
6. Handle file uploads carefully
Check file type by content, not by the name or browser-supplied type. Store uploads outside the web root with generated names, limit size, and never serve them with a type the browser can execute.
7. Keep secrets out of code
API keys, database passwords and tokens belong in environment variables or a secrets manager — never in the repository. Rotate any secret that has ever been committed.
8. Update dependencies
Most applications are largely made of open-source packages. Enable automated vulnerability alerts and update regularly; old libraries are an easy way in.
9. Use secure defaults for transport and headers
Serve everything over HTTPS with HSTS, set cookies as Secure, HttpOnly and SameSite, and add headers such as X-Content-Type-Options and frame-ancestors.
10. Log, monitor and practise
Log security-relevant events (logins, permission failures, admin actions) without logging passwords or personal data. Alert on unusual patterns, keep backups, and rehearse how you would respond to an incident.
Key takeaways
Server-side authorisation, input validation, safe output, careful uploads, protected secrets and up-to-date dependencies prevent most attacks. Add monitoring so that if something does go wrong, you find out quickly.