Saltar al contenido
uencoder

Prevent CSRF (Cross-Site Petición Forgery) attacks

CSRF tricks authenticated usuarios en submitting unwanted requests. Aprender anti-CSRF tokens, SameSite cookies, y double-submit patrones.

  1. 1

    CSRF exploits the browser's automatic sending of cookies. If a user is logged in (cookies present) and visits a malicious site, that site can submit a form to the target site — the cookies are sent automatically. Prevention: (1) Anti-CSRF tokens (synchronizer pattern) — a random token in the form and session, verified on submission. (2) SameSite cookies — cookies are not sent cross-site. (3) Origin/Referer header validation. (4) Require custom headers for state-changing requests.

  2. 2
    Generador de HMAC →

    Generar an anti-CSRF token. The token should be: unpredictable (CSPRNG), per-session (or per-request for higher security), and bound to the user's session. HMAC(session_id, random) is a common pattern — it is deterministic (same session → same token) but unforgeable without the secret.

  3. 3
    Calculadora de hash →

    For the double-submit pattern: generate a random token, set it as a cookie (not HttpOnly, so JavaScript can read it) and include it as a header in every request. The server verifies that the cookie and header match. This does not require server-side state. Use SHA-256 for the token hash.

Preguntas frecuentes

Are SameSite cookies enough to prevent CSRF?
SameSite=Lax (default in modern browsers) prevents CSRF for top-level navigations (form POST, link clicks) but allows GET requests. SameSite=Strict prevents all cross-site sending but breaks legitimate cross-site usage (e.g., following a link to your site from email). Use SameSite=Lax + CSRF tokens for defense in depth.
CSRF vs XSS — what is the difference?
XSS executes malicious code in the victim's browser (the attacker reads data or performs actions as the user). CSRF tricks the victim's browser into making a request to a site where they are authenticated (the attacker does not read the response). XSS is a code injection; CSRF is a request forgery. XSS can bypass CSRF protections (the script can read the token).

Flujos que resuelven esta tarea

Hash contenido y codificar como Base64
Calcular un hash de la entrada y codificar el resumen como Base64 para transporte compacto.
CANALIZACIÓN
Hash texto y verificar integridad
Calcular un hash del texto de entrada y compararlo con un hash esperado para verificar la integridad.
CANALIZACIÓN
Hash texto y verificar con suma CRC32
Calcular tanto un hash criptográfico SHA-256 como una suma de verificación CRC32 para verificación de integridad de datos.
CANALIZACIÓN
Firmar HMAC y luego codificar en Base64
Generar firma HMAC y luego codificar en Base64 para encabezados de autenticación de API.
CANALIZACIÓN
Firmar HMAC y verificar
Generar una firma HMAC para un mensaje y verificarla contra una firma esperada.
CANALIZACIÓN
Firmar HMAC una cadena de solicitud API
Generar una firma HMAC-SHA256 para un payload de solicitud para autenticar llamadas API.
CANALIZACIÓN
Hash MD5 y luego codificar en Base58
Calcular hash MD5 y luego codificar como Base58 para representación compacta.
CANALIZACIÓN
Comparación de velocidad multi-hash
Hash la entrada y comparar múltiples algoritmos de hash para comparar su velocidad y salida.
CANALIZACIÓN
Generar contraseña y hash
Generar una contraseña aleatoria y luego hash para almacenamiento seguro.
CANALIZACIÓN
Hash SHA3-256 con suma CRC32
Calcular hash SHA3-256 y luego suma CRC32 para verificación dual de integridad.
CANALIZACIÓN
Hash SHA-512 y luego Hex
Calcular hash SHA-512 y luego codificar como Hex para legibilidad.
CANALIZACIÓN
Invertir texto y hash
Invertir texto y luego calcular el hash SHA-256 del resultado invertido.
CANALIZACIÓN
Mezclar texto y hash
Mezclar texto y luego hash del resultado mezclado.
CANALIZACIÓN

Herramientas relacionadas