Token CSRF nei cookie?

1

Ho visto alcuni siti Web utilizzare token CSRF nel campo dei cookie come

_csrf=123abc

e non come intestazione separata o come parte dei dati POST. La mia domanda è, quando il sito web di un utente malintenzionato effettua una richiesta CSRF con quei cookie sul sito web della vittima, come è utile il token CSRF qui? Il token CSRF non va con il cookie !? Sono confuso.

    
posta Knob 04.04.2018 - 22:55
fonte

1 risposta

0

Sì, il cookie verrà inviato automaticamente con tutte le richieste dal browser. Quindi solo l'uso di un token in un cookie sconfigge l'intero scopo della difesa CSRF.

Quindi ... Tutti i siti in cui vengono visualizzati i token CSRF nei cookie sono vulnerabili? No. Molto probabilmente, il valore nel cookie è incluso da qualche altra parte, ad es. in un'intestazione o in un campo modulo nascosto. Questo è noto come pattern "double submit cookie" e ha il vantaggio che non richiede uno stato del server. Come al solito, OWASP ti ha coperto:

When a user authenticates to a site, the site should generate a (cryptographically strong) pseudorandom value and set it as a cookie on the user's machine separate from the session id. The site does not have to save this value in any way, thus avoiding server side state. The site then requires that every transaction request include this random value as a hidden form value (or other request parameter). A cross origin attacker cannot read any data sent from the server or modify cookie values, per the same-origin policy. This means that while an attacker can force a victim to send any value he wants with a malicious CSRF request, the attacker will be unable to modify or read the value stored in the cookie. Since the cookie value and the request parameter or form value must be the same, the attacker will be unable to successfully force the submission of a request with the random CSRF value.

    
risposta data 05.04.2018 - 11:21
fonte

Leggi altre domande sui tag