Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use customized SpaCsrfTokenRequestHandler to handle CSRF token #25907

Merged
merged 2 commits into from
Apr 23, 2024

Conversation

yhao3
Copy link
Contributor

@yhao3 yhao3 commented Apr 21, 2024

Description

In the production configuration, the server has enabled the compression feature (as shown below):

server:
  port: 8080
  shutdown: graceful # see https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-graceful-shutdown
  compression:
    enabled: true
    mime-types: text/html,text/xml,text/plain,text/css,application/javascript,application/json,image/svg+xml
    min-response-size: 1024

This implies that the server might be vulnerable to BREACH attacks. Currently, in the SecurityConfiguration, we're using CsrfTokenRequestAttributeHandler to manage Csrf Tokens. However, according to the official documentation, "The primary use of CsrfTokenRequestAttributeHandler is to opt-out of BREACH protection of the CsrfToken" because the value of X-Xsrf-Token in the response headers remains constant for every request.

Following the guidance from the Spring Security official documentation, I found the following section:

Integrating with CSRF Protection > JavaScript Applications > Single-Page Applications

In fact, for single-page applications (SPAs), we can use XorCsrfTokenRequestAttributeHandler in conjunction with CsrfTokenRequestAttributeHandler. By employing different implementations in various contexts to manage Csrf Tokens, we can leverage the capabilities of XorCsrfTokenRequestAttributeHandler to shield against BREACH attacks.

Therefore, I've submitted this pull request in alignment with the recommendations provided in the official documentation.

@yhao3
Copy link
Contributor Author

yhao3 commented Apr 22, 2024

Hi @mshima, thank you for your review. I've made adjustments based on your suggestions. Could you please review again? Thanks!

@yhao3 yhao3 requested a review from mshima April 22, 2024 16:27
@mshima mshima merged commit 9e6182d into jhipster:main Apr 23, 2024
52 checks passed
@mraible mraible added this to the 8.4.0 milestone Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants