Zum Inhalt springen
uencoder

Prevent CSRF (Cross-Site Anfrage Forgery) attacks

CSRF tricks authenticated Benutzer in submitting unwanted requests. Lernen anti-CSRF tokens, SameSite cookies, und double-submit Muster.

  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
    HMAC-Generator →

    Erzeugen 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
    Hash-Rechner →

    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.

Häufige Fragen

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).

Workflows, die diese Aufgabe lösen

Inhalt hashen und als Base64 kodieren
Einen Hash der Eingabe berechnen und den Hash-Digest als Base64 kodieren für kompakten Transport.
PIPELINE
Text hashen und Integrität verifizieren
Einen Hash des Eingabetextes berechnen und mit einem erwarteten Hash vergleichen zur Integritätsverifikation.
PIPELINE
Text hashen und mit CRC32-Prüfsumme verifizieren
Sowohl einen kryptografischen SHA-256-Hash als auch eine CRC32-Prüfsumme berechnen zur Datenintegritätsverifikation.
PIPELINE
HMAC signieren dann Base64 kodieren
HMAC-Signatur generieren dann Base64 kodieren für API-Auth-Header.
PIPELINE
HMAC signieren und verifizieren
Eine HMAC-Signatur für eine Nachricht generieren und gegen eine erwartete Signatur verifizieren.
PIPELINE
HMAC eine API-Anfragezeichenkette signieren
Eine HMAC-SHA256-Signatur für eine Anfrage-Nutzlast generieren zur Authentifizierung von API-Aufrufen.
PIPELINE
MD5 hashen dann Base58 kodieren
MD5-Hash berechnen dann als Base58 kodieren für kompakte Darstellung.
PIPELINE
Multi-Hash-Geschwindigkeitsvergleich
Die Eingabe hashen und mehrere Hash-Algorithmen benchmarken zum Vergleich von Geschwindigkeit und Ausgabe.
PIPELINE
Passwort generieren und hashen
Ein Zufallspasswort generieren dann hashen für sichere Speicherung.
PIPELINE
SHA3-256-Hash mit CRC32-Prüfsumme
SHA3-256-Hash berechnen dann CRC32-Prüfsumme für duale Integritätsverifikation.
PIPELINE
SHA-512 hashen dann Hex
SHA-512-Hash berechnen dann als Hex kodieren für Lesbarkeit.
PIPELINE
Text umkehren und hashen
Text umkehren dann SHA-256-Hash des umgekehrten Ergebnisses berechnen.
PIPELINE
Text verschlüsseln und hashen
Text verschlüsseln dann das verschlüsselte Ergebnis hashen.
PIPELINE

Verwandte Tools