Website Security 101: 15 Must-Know Practices
From HTTPS to CSP headers, learn the 15 security practices that will protect your website from common attacks. Includes free security audit checklist.
Website Security 101: 15 Essential Practices Every Site Owner Must Know
Website security isn't optional anymore. With automated attacks scanning millions of sites daily, even small websites are targets. One breach can destroy trust, tank your SEO, and cost thousands in recovery.
Here's what every site owner needs to implement.
Critical Security Headers
Add these headers to your server configuration (Nginx/Apache/Cloudflare):
1. Content-Security-Policy (CSP)
Prevents XSS attacks by controlling which resources can load:
# Nginx
add_header Content-Security-Policy "default-src 'self'; script-src 'self' https://cdn.jsdelivr.net; style-src 'self' 'unsafe-inline';";
2. X-Frame-Options
Prevents clickjacking by blocking your site from being embedded in iframes:
add_header X-Frame-Options "SAMEORIGIN";
3. X-Content-Type-Options
Prevents MIME type sniffing:
add_header X-Content-Type-Options "nosniff";
4. Strict-Transport-Security (HSTS)
Forces HTTPS connections:
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains";
HTTPS: Non-Negotiable
5. Force HTTPS Everywhere
Redirect all HTTP traffic to HTTPS:
# Nginx
return 301 https://$server_name$request_uri;
6. Use Modern TLS
Disable TLS 1.0 and 1.1:
ssl_protocols TLSv1.2 TLSv1.3;
7. Get a Free Certificate
Let's Encrypt provides free SSL certificates with auto-renewal. No excuse not to have HTTPS.
Input Validation & Sanitization
8. Validate All User Input
Never trust user-submitted data:
// Validate email format
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailRegex.test(email)) {
return res.status(400).json({ error: 'Invalid email' });
}
// Sanitize HTML to prevent XSS
import DOMPurify from 'isomorphic-dompurify';
const clean = DOMPurify.sanitize(userInput);
9. Use Parameterized Queries
Prevent SQL injection by never concatenating user input into SQL:
// BAD
const query = `SELECT * FROM users WHERE email = '${email}'`;
// GOOD (parameterized)
const query = 'SELECT * FROM users WHERE email = $1';
await db.query(query, [email]);
Authentication Security
10. Hash Passwords Properly
Never store plain text passwords. Use bcrypt or Argon2:
import bcrypt from 'bcrypt';
const hash = await bcrypt.hash(password, 12);
const match = await bcrypt.compare(input, hash);
11. Implement Rate Limiting
Prevent brute force attacks:
# Nginx - limit requests per IP
limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s;
location /api/ {
limit_req zone=api burst=20 nodelay;
}
12. Use Secure Cookies
Set secure, httpOnly, and sameSite flags:
res.cookie('session', token, {
httpOnly: true,
secure: true,
sameSite: 'strict',
maxAge: 24 * 60 * 60 * 1000 // 24 hours
});
Regular Maintenance
13. Keep Everything Updated
- Update your CMS, plugins, and themes weekly
- Use a vulnerability scanner
- Subscribe to security mailing lists for your stack
14. Regular Backups
- Automated daily backups
- Store off-site (cloud storage)
- Test restoration quarterly
15. Security Headers Scan
Run a free security audit to check your headers:
Quick Win: Audit Your Security
Don't know if your site is secure? Run a free security audit to check your headers, SSL configuration, and common vulnerabilities. Get a detailed report with actionable fixes in under 90 seconds.
Security Checklist
Copy this checklist and run through it monthly:
- [ ] HTTPS enabled with valid certificate
- [ ] All security headers set (CSP, X-Frame-Options, etc.)
- [ ] TLS 1.2+ only
- [ ] Input validation on all forms
- [ ] Parameterized queries used
- [ ] Rate limiting configured
- [ ] Secure cookie flags set
- [ ] Dependencies up to date
- [ ] Automated backups running
- [ ] Security headers tested
Conclusion
Website security is an ongoing process, not a one-time fix. Start with the basics (HTTPS + security headers), then layer in authentication security and input validation. Run regular audits to catch new vulnerabilities.
Want a complete security assessment? Get your free security audit now — it checks 30+ security factors and gives you a prioritized fix list.