Search code examples
webformscsrfcsrf-protection

Is Encrypted Token Pattern CSRF protection immune to BREACH attack?


OWASP's Encrypted Token Pattern is a CSRF protection solution, where the token value is a function of time. Would this mean that Encrypted Token Pattern has a built in BREACH attack protection?


Solution

  • Generally no, because in most implementations the token is only generated once per authentication (i.e. when somebody logs in). It is still generally recommended to only generate the CSRF token once per session.

    Once the CSRF token has been retrieved by a BREACH attack, then it could be used on subsequent requests in the session. It doesn't matter if the value is encrypted as it is only the ciphertext itself that is required.

    However, as a mitigation for BREACH, you could regenerate the token on every request.

    There are some other mitigations here. The one I like best is disabling HTTP compression when the referer header does not match your domain, or is blank because this will not break any functionality of the system. For high security systems, it might be better to disable HTTP compression altogether for HTTPS requests, because in theory it is possible for any part for a repeatable response to be determined.