CSRF

Cross-site request forgery

Summary

Cross-site request forgery (also known as CSRF) is a web security vulnerability that allows an attacker to induce users to perform actions that they do not intend to perform.

3 conditions must be in place:

  • A relevant action.

  • Cookie-based session handling.

  • No unpredictable request parameters.

Approach

- Removing the token parameter entirely
- Setting the token to a blank string
- Changing the token to an invalid token of the same format
- Using a different user's token
- Put the parameters in the URL instead of POST body (and remove the token) and change the HTTP verb to GET
- Testing every sensitive endpoint
- Check whether the token might be guessed / cracked
- Check whether new tokens are generated for every session, if not they may be a hash of something simple like the user's email address. If so you can craft your own valid tokens.
- Try building the payload with multiple methods including a standard HTML form, multipart form, and XHR (Burp can help)
- Extract token with HTML injection.
- Use a CSRF token that has been used before.
- Bypass regex.
- Remove referer header.
- Request a CSRF by executing the call manually and use that token for the request.

Quick attacks

Tools

Example 1

Example 2

Json CSRF

CSRF Token Bypass

CSRF sample POC

CSRF to reflected XSS

Common defenses

  • SameSite cookies: If the session cookie is using this flag, you may not be able to send the cookie from arbitrary web sites.

  • Ask for the password user to authorise the action.

  • Resolve a captcha

  • Read the Referrer or Origin headers. If a regex is used it could be bypassed form example with:

    • http://mal.net?orig=http://example.com (ends with the url)

    • http://example.com.mal.net (starts with the url)

  • Modify the name of the parameters of the Post or Get request

  • Use a CSRF token in each session. This token has to be send inside the request to confirm the action. This token could be protected with CORS.

SameSite

This will indicate the browser if the cookie can be sent from other domains. It has 3 possible values:

  • Strict: The cookie will not be sent along with request by third party websites.

  • Lax: The cookie will be sent along with the GET request initiated by third party websites.

  • None: The cookie is sent from any third party domain

Mindmaps

Last updated