How to Secure Your Website: Practical Best Practices
Website security isn’t one single “feature” you turn on — it’s a set of habits and controls that reduce risk across your whole stack…
How to Secure Your Website: Practical Best Practices
Website security isn’t one single “feature” you turn on — it’s a set of habits and controls that reduce risk across your whole stack: frontend, backend APIs, infrastructure, and your development process.
Over the last month, our team focused on hardening a real production web app after reviewing penetration-testing findings. Below is a practical guide you can apply to your own site, with real examples of what we shipped.
1) Start with a “defense-in-depth” mindset
Attackers don’t need to break everything — just one weak point. The goal is layered protection so that if one control fails, another still blocks the attack.
Think in layers:
- Browser layer (security headers, CSP, iframe controls)
- App layer (auth, CSRF, validation, logging hygiene)
- API layer (rate limiting, request limits, strict authorization)
- Infra layer (WAF, CDN rules, TLS, monitoring)
- Process layer (secure CI/CD, scanning, code reviews)
2) Always enforce HTTPS + add HSTS
HTTPS prevents traffic interception and tampering. HSTS tells browsers to only use HTTPS for your domain going forward.
What to do:
- Redirect HTTP → HTTPS
- Enable TLS everywhere (CDN + origin)
- Add HSTS (carefully, especially if you use subdomains)
3) Use strong security headers (especially CSP)
Security headers reduce entire classes of browser attacks.
Recommended baseline headers:
- Content-Security-Policy (CSP): prevents many XSS paths by restricting where scripts can load from.
- frame-ancestors (in CSP): controls who can embed your site (clickjacking protection).
- X-Content-Type-Options: nosniff: blocks MIME sniffing issues.
- Referrer-Policy: stops leaking sensitive paths/params via referrer.
- Permissions-Policy: restricts powerful browser features you don’t use.
What we improved last month
We tightened CSP after seeing blocked scripts/inline handlers in the console and refined:
script-srcto allow only required domains- removed risky allowances where possible (like unsafe patterns)
- properly configured
frame-srcfor approved embeds (dashboards/analytics) - used
frame-ancestorsto prevent clickjacking
4) Don’t leak sensitive data in URLs (especially to third parties)
URLs get logged everywhere:
- browser history
- proxy logs / CDN logs
- analytics tools
- error trackers
- screenshots / shared links
Even if data looks “not sensitive” (orgId, module keys, internal identifiers), it can be sensitive depending on the customer (e.g., defense or regulated orgs).
What we improved last month
We identified endpoints that placed data in query strings and:
- moved sensitive parameters from GET → POST body
- reduced the chance of third-party tools capturing identifiers via page tracking
5) Protect against CSRF (especially for cookie-based auth)
If your app uses cookies for auth, CSRF protection matters.
Good options:
- anti-CSRF token pattern (cookie + header)
- same-site cookie settings
- confirm state-changing actions on the server
What we improved last month
We added / verified Angular XSRF protection so requests automatically include the correct CSRF header and cookie pairing, without breaking existing interceptors.
6) Enforce authentication + authorization everywhere (not just in the UI)
A secure UI means nothing if APIs accept requests without strict checks.
Best practices:
- Validate JWTs server-side (issuer, audience, signature, expiry)
- Enforce role-based access on each endpoint
- Don’t rely on “the frontend will hide that button”
- Use least privilege for service permissions
What we improved last month
We hardened API access rules and cleaned up request handling so headers/claims are parsed safely and only applied when valid — reducing crashes and unexpected behavior.
7) Add rate limiting + abuse protection
Rate limits protect against:
- brute force attempts
- scraping
- API floods / cost spikes
- accidental traffic storms
Where to apply:
- Edge (CDN/WAF rules)
- API Gateway throttling
- App-level limits (per IP / per token / per route)
What we improved last month
We implemented and tested:
- API Gateway throttling (burst + sustained)
- app-side protections for endpoints that were at risk
- clearer load-testing to confirm behavior under pressure
8) Validate inputs and set request size limits (including uploads)
Many vulnerabilities start with “we trusted input.”
Do this consistently:
- Validate types, lengths, formats, and allowed values
- Apply server-side limits to request size and payload shapes
- For file uploads:
- limit file size
- limit file types (and verify by content, not just extension)
- scan uploads if needed
- store safely (private buckets, short-lived access)
What we improved last month
We introduced:
- search text length limits
- request size caps
- tighter rules around bulk uploads (including large Excel uploads)
9) Make iframes and embeds safe
Iframes can be necessary (dashboards, third-party widgets), but they’re also a common source of security issues.
Best practices:
- Use CSP
frame-srcallowlists (only what you need) - Use iframe
sandboxrestrictions (avoid risky flags unless required) - Avoid
allow-same-originunless you absolutely need it - Keep third-party scripts on a strict leash via CSP
What we improved last month
We reviewed iframe usage and CSP rules, focused on:
- allowing only approved embed domains
- avoiding unsafe sandbox permissions
- preventing “user can swap iframe URL in dev tools and load untrusted pages”
10) Log securely + monitor continuously
Logging is essential — but logs can become a data leak.
Best practices:
- never log passwords, tokens, or full JWTs
- mask sensitive fields
- reduce noisy logs that accidentally capture request content
- alert on suspicious patterns (spikes, auth failures, unusual endpoints)
What we improved last month
We reduced noisy logging and adjusted token/org parsing so logs and headers are only created when safe and valid.
11) Automate security checks in CI/CD
Security work sticks when it’s automated.
Add to your pipeline:
- dependency scanning (SCA)
- secret scanning
- basic static analysis
- IaC checks if you use Terraform/CloudFormation
- build-time “security header tests” for environments
What we improved last month
We created a repeatable security checklist and Jira task flow so every release includes:
- header verification
- auth checks
- rate limit checks
- regression testing for embeds and third-party scripts
What We Delivered Last Month (Quick Summary)
Here’s the exact type of “security sprint” that brings measurable improvement:
- Tightened Content Security Policy and reduced risky script execution paths
- Added/verified XSRF protections for safer state-changing requests
- Converted a sensitive endpoint from GET query params → POST body
- Added rate limiting (edge/gateway/app strategy) and tested throttling behavior
- Introduced request size and input length limits (including upload scenarios)
- Hardened token/org parsing and reduced logging risk/noise
- Reviewed iframe usage and locked down frame-src / sandbox patterns
- Turned pen-test findings into tracked Jira tasks with acceptance criteria
Copy/Paste Security Checklist (Fast)
Frontend
- CSP in place and tested
- No sensitive info in URLs
- XSS-safe rendering (encoding, no unsafe HTML)
- Third-party scripts minimized and allowlisted
Backend / API
- JWT validation + per-endpoint authorization
- CSRF protection if cookie-based auth is used
- Input validation + request size limits
- Rate limiting (per IP / token / route)
- Secure logging (mask tokens/PII)
Infrastructure
- HTTPS everywhere + HSTS
- WAF rules for common abuse
- Monitoring + alerting for spikes/errors
Process
- Dependency + secret scanning in CI/CD
- Security regression tests for every release
- Pen-test findings tracked to completion
메타데이터
- post_id
- b86c46e9f727
- slug
- how-to-secure-your-website-practical-best-practices-b86c46e9f727
- url
- https://medium.com/@isurujayathissa/how-to-secure-your-website-practical-best-practices-b86c46e9f727
- canonical_url
- https://medium.com/@isurujayathissa/how-to-secure-your-website-practical-best-practices-b86c46e9f727
- author_url
- https://medium.com/@isurujayathissa
- status
- ok
- fetched_at
- 2026-07-26 02:20:04