Envenenamiento de caché y defensa de la capa de caché
Aprenda cómo funcionan los ataques de envenenamiento y engaño de caché, y cómo reforzar la capa de caché frente a ellos gestionando cuidadosamente las claves y las cabeceras.
Envenenamiento de caché y defensa de la capa de caché es una lección gratuita de Caching Strategies: Redis + CDN + Edge Computing en CoddyKit. Esta es la lección 4 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de Caching Strategies: Redis + CDN + Edge Computing, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de Caching Strategies: Redis + CDN + Edge Computing incluye 4 lecciones en total.
Partes de esta lección aún no han sido traducidas y se muestran en inglés.
What Is Cache Poisoning?
Web cache poisoning tricks a cache into storing a malicious response that is then served to other users. The attacker manipulates an input that influences the response but is not part of the cache key.
- Attacker sends a crafted request
- Origin reflects attacker input into the response
- Cache stores it and serves it to everyone
Unkeyed Inputs Are the Risk
The root cause is an unkeyed input: a header or parameter that changes the response but is excluded from the cache key. If an attacker controls it, they poison the shared entry.
Example: Poisoning via a Custom Header
Imagine the origin reflects X-Forwarded-Host into a generated URL but the cache ignores that header. An attacker sets it to their domain, and the cached page now points everyone at attacker resources.
GET / HTTP/1.1
Host: example.com
X-Forwarded-Host: evil.comCache Key Hygiene
The primary defense is to include every input that affects the response in the cache key, or to strip dangerous headers before caching. Never reflect untrusted headers into cached output.
Cache Deception
Cache deception tricks the cache into storing private data under a public-looking URL. An attacker appends a fake static extension so the cache treats a sensitive page as a cacheable asset.
https://app.com/account/info.css (still serves the private account page)Defending Against Deception
Defend by caching based on the actual Content-Type and explicit rules, not just the URL extension. Never cache responses marked private or that set authenticated cookies.
Stripping Risky Headers
Configure the edge to drop headers an attacker should not control before they reach the origin or cache, such as forwarded-host style headers unless explicitly trusted.
proxy_set_header X-Forwarded-Host "";Sanitizing Reflected Values
If the origin must echo a value, validate and encode it. Never build cacheable URLs or scripts directly from request headers without strict allow-lists.
Separating Authenticated Traffic
Authenticated responses should generally bypass shared caches. Route logged-in requests around the public cache, or mark them private, no-store so they are never shared.
Cache-Control: private, no-storeMonitoring for Poisoning
Watch for anomalies: sudden cache entries with unexpected hosts, spikes in 4xx after a deploy, or reports of users seeing foreign content. Detection lets you purge fast.
Hardening Checklist
Protect the cache layer by:
- Keying on every response-affecting input
- Stripping untrusted forwarding headers
- Caching by content type, not URL extension
- Never caching private or authenticated responses
- Encoding any reflected request values
Quick Check
Test your cache security understanding.
Recap
You learned how cache poisoning and cache deception attacks exploit unkeyed inputs and URL-based caching. You saw defenses: rigorous cache-key hygiene, stripping untrusted headers, caching by content type, never sharing authenticated responses, and monitoring for anomalies.
Aprende Caching Strategies: Redis + CDN + Edge Computing con un tutor de IA — gratis
Escribe y ejecuta código real en tu navegador, obtén ayuda instantánea de un tutor de IA disponible 24/7 y continúa donde lo dejaste en la web o en la aplicación.
- Cursos
- 12
- Lecciones
- 48
Preguntas frecuentes
¿La lección «Envenenamiento de caché y defensa de la capa de caché» es gratis?
Sí — el texto completo de «Envenenamiento de caché y defensa de la capa de caché» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de Caching Strategies: Redis + CDN + Edge Computing, actualiza a CoddyKit PRO. El curso de Caching Strategies: Redis + CDN + Edge Computing incluye 4 lecciones en total.
¿Qué aprenderé en «Envenenamiento de caché y defensa de la capa de caché»?
Aprenda cómo funcionan los ataques de envenenamiento y engaño de caché, y cómo reforzar la capa de caché frente a ellos gestionando cuidadosamente las claves y las cabeceras. Practicas Caching Strategies: Redis + CDN + Edge Computing con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.
¿Necesito experiencia previa para empezar Caching Strategies: Redis + CDN + Edge Computing?
No se requiere experiencia previa. Caching Strategies: Redis + CDN + Edge Computing en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 4 de 4.
¿Cuánto tiempo toma la lección «Envenenamiento de caché y defensa de la capa de caché»?
La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.
¿Puedo escribir y ejecutar código en esta lección de Caching Strategies: Redis + CDN + Edge Computing?
Sí. Cada lección de Caching Strategies: Redis + CDN + Edge Computing incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.
Todas las lecciones de este curso
- Alternativas de caché y Circuit Breakers
- Prácticas recomendadas de seguridad para cachés
- Tendencias futuras del almacenamiento en caché
- Envenenamiento de caché y defensa de la capa de caché