Infrastructure & Ops · 8 min read · Intermediate
Rate Limiting, Request Bounds & Preventing SSRF
Protect login, signup, and webhook endpoints from abuse, and block Server-Side Request Forgery.
What you'll learn
- Throttle `/api/auth/login` and `/api/auth/register` per IP
- Bound request body sizes and execution timeouts on every endpoint
- Block private IP ranges whenever backend code fetches user-supplied URLs
Overview
Protect login, signup, and webhook endpoints from abuse, and block Server-Side Request Forgery.
Code Example
# Always cap request body size and rate-limit auth endpoints
MAX_BODY_BYTES = 16_000 # reject oversized payloads early (413/400)
# When fetching user-provided URLs on the server (webhooks/avatars):
# 1. Allow only https:// scheme
# 2. Resolve DNS and block private/loopback ranges (127.0.0.0/8, 10.0.0.0/8, 169.254.169.254)
Key Takeaways
- Throttle
/api/auth/loginand/api/auth/registerper IP - Bound request body sizes and execution timeouts on every endpoint
- Block private IP ranges whenever backend code fetches user-supplied URLs
Quick Check
Check Your Understanding
Score: 0 / 1
1. Why is `169.254.169.254` a high-value target in SSRF (Server-Side Request Forgery) attacks?
Study Workspace
Finished this lesson?
Your progress is saved locally in your browser, no account needed.