Skip to content

VaadinWebSecurity is broken with Hilla 2 #681

Closed
vaadin/flow
#15804

Description

@simasch

I have a simple Hilla application created on https://start.vaadin.com with VaadinWebSecurity configured.

Login redirect to the login view and navigating to / results in a 401:

Connect.ts:422          POST http://localhost:8080/connect/UserEndpoint/getAuthenticatedUser 401

Activity

  1. added
    bugSomething isn't working
    hillaIssues related to Hilla
    on Dec 1, 2022
  2. simasch commented on Dec 1, 2022

    @simasch
    ContributorAuthor

    The issue seems to be vaadin/flow#14923

  3. Artur- commented on Dec 1, 2022

    @Artur-
    Member

    Looks like some other problem as CsrfTokenRequestAttributeHandler is used and not XorCsrfTokenRequestAttributeHandler

  4. simasch commented on Dec 1, 2022

    @simasch
    ContributorAuthor

    Alright. Thank you

  5. simasch commented on Dec 21, 2022

    @simasch
    ContributorAuthor

    Any news on that? I'm working on a Hilla talk and it would be great to show Hilla 2 with Spring Boot 3

  6. added this to the 2.0 milestone on Jan 30, 2023
  7. self-assigned this
    on Jan 31, 2023
  8. cromoteca commented on Feb 1, 2023

    @cromoteca
    Contributor

    I think that the problem comes from vaadin/flow#14853: if I do the same change on 23.3 and try to use it with Hilla 1.3, integration tests pass, but applications can no longer log in. The code removed in that PR cannot be restored because it no longer works (requestResponseHolder.getResponse() is null), but must be replaced with a different implementation. The fact of calling saveContext while loading the context is no longer possible, but Hilla 1.3 was counting on that to pass the context between calls.

  9. Artur- commented on Feb 1, 2023

    @Artur-
    Member

    Where in the code can you see the problem when debugging? Or in other words, what is not available at which point?

  10. cromoteca commented on Feb 1, 2023

    @cromoteca
    Contributor

    I was wrong. The issue is not there. It's this response header: XSRF-TOKEN=; Max-Age=0; Expires=Thu, 01 Jan 1970 00:00:10 GMT; Path=/ which resets that cookie and causes a mismatch when verifying the POST request for the authenticated user, which then returns a 401 and the client application resorts to an infinite login. Now I must search where that empty cookie is set.

  11. cromoteca commented on Feb 1, 2023

    @cromoteca
    Contributor

    That header is set in the authentication request, and only in that case. Otherwise, the XSRF-TOKEN is expected to have a value. Hilla 1.3 correctly resets that cookie only in the authentication response.

    But with Hilla 2, other requests are seen as authentication ones, even some completely unrelated like http://localhost:8080/VAADIN/@vite/client or http://localhost:8080/VAADIN/generated/vite-devmode.ts, but not others like http://localhost:8080/VAADIN/generated/vaadin-featureflags.ts. I have the feeling that those empty cookies are sent for some time after the first auth response.

    There are also some JSESSIONID cookies sent, all different.

    I still haven't been able to understand what causes this behavior. Anyway, the wrong path passes by this: https://github.com/spring-projects/spring-security/blob/19c55372a3f2f97d1f0ee235f90b38187a8b3a69/web/src/main/java/org/springframework/security/web/session/SessionManagementFilter.java#L97-L102

    Only the first http://localhost:8081/login request should show that behavior.

  12. added a commit that references this issue on Feb 2, 2023
    7149f77
  13. vaadin-bot commented on Feb 3, 2023

    @vaadin-bot
    Collaborator

    This ticket/PR has been released with Vaadin 24.0.0.alpha10 and is also targeting the upcoming stable 24.0.0 version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions