# Web Security Essentials

> Defend a full-stack app against XSS, CSRF, injection, SSRF and secret leaks with sensible defaults and headers. Free notes, key concepts, resources and a mini...

Canonical: https://www.internhack.in/roadmaps/tracks/full-stack/web-security
Last updated: 2026-11-28

Defend a full-stack app against XSS, CSRF, injection, SSRF and secret leaks with sensible defaults and headers.

Intermediate · about 6 hours · difficulty 3/5

Learn first: [Authorization and Access Control](https://www.internhack.in/roadmaps/tracks/full-stack/authorization-rbac)

You do not need to be a security engineer, but you must not ship the classic bugs. Most are prevented by using frameworks correctly and a few deliberate settings.

### The usual suspects

- **XSS**: attacker script runs in your page. React escapes output by default; danger comes from dangerouslySetInnerHTML, unsanitised markdown and URLs like javascript:. Add a **Content Security Policy**.
- **CSRF**: another site triggers actions using the user's cookies. SameSite cookies, Next.js server action origin checks and CSRF tokens for older setups protect you.
- **SQL injection**: avoided by ORMs and parameterised queries; stay careful with raw SQL.
- **SSRF**: your server fetches a URL supplied by the user and hits internal services. Validate and allowlist destinations.
- **Insecure file uploads**: check type and size, store outside your app server, and never execute uploads.

### Defaults to set

- Security headers (helmet in Express, headers config in Next.js): CSP, HSTS, X-Content-Type-Options, frame protections.
- HTTPS everywhere.
- **Secrets** only in environment variables or a secret manager, never in the repo or the client bundle.
- Keep dependencies updated with Dependabot or Renovate and npm audit.

### Pitfalls

- Disabling a security check because it was "annoying" during development.
- Prefixing a secret with NEXT_PUBLIC\_ and shipping it to every browser.
- Logging tokens, passwords or full payment details.

You are ready to move on when you can name the OWASP Top 10 categories, show the protection for each one that applies to your portal, and get a clean result from a security headers scan.

## Key concepts

- **XSS and Content Security Policy**
- **CSRF and SameSite cookies**
- **SQL injection**
- **SSRF**
- **Secure file uploads**
- **Security headers**
- **Secrets management**
- **Dependency updates and audits**

## Mini project

Run a security review of your portal against the OWASP Top 10: add a CSP and security headers, enable Dependabot, scan the client bundle for leaked secrets, and document each control in a SECURITY.md.

## Check yourself

React escapes output by default. Name two ways an XSS bug can still get into a React app.

## Free resources

- [OWASP Top 10](https://owasp.org/www-project-top-ten/) (OWASP)
- [OWASP Cheat Sheet Series](https://cheatsheetseries.owasp.org/) (OWASP)
- [Content Security Policy (CSP)](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP) (MDN)
- [PortSwigger Web Security Academy](https://portswigger.net/web-security) (PortSwigger)

Previous: [Authorization and Access Control](https://www.internhack.in/roadmaps/tracks/full-stack/authorization-rbac) · Next: [Testing Fundamentals with Vitest](https://www.internhack.in/roadmaps/tracks/full-stack/testing-basics)

## More in Authentication, Authorization and Security

- [Authentication Fundamentals and Password Storage](https://www.internhack.in/roadmaps/tracks/full-stack/auth-fundamentals)
- [Sessions, Cookies and JWTs](https://www.internhack.in/roadmaps/tracks/full-stack/sessions-vs-jwt)
- [OAuth 2.0, OpenID Connect and Social Login](https://www.internhack.in/roadmaps/tracks/full-stack/oauth-and-social-login)
- [Auth with Auth.js (NextAuth)](https://www.internhack.in/roadmaps/tracks/full-stack/authjs)
- [Auth with a Hosted Provider (Clerk)](https://www.internhack.in/roadmaps/tracks/full-stack/clerk)
- [Authorization and Access Control](https://www.internhack.in/roadmaps/tracks/full-stack/authorization-rbac)
- [Web Security Essentials](https://www.internhack.in/roadmaps/tracks/full-stack/web-security)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [Full-Stack Developer Roadmap](https://www.internhack.in/roadmaps/tracks/full-stack)
