-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Fix 'response head already sent' when the login request to form-based authentication when proactive authentication is disabled #46418
Conversation
michalvavrik
commented
Feb 21, 2025
- closes: IllegalStateException: Response head already sent during login #44458
Thanks for your pull request! Your pull request does not follow our editorial rules. Could you have a look?
This message is automatically generated by a bot. |
// we expect that form-based authentication mechanism to recognize the post-location, | ||
// authenticate and if user provided credentials in form attribute, response will be ended | ||
if (!event.response().ended()) { | ||
event.response().end(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is event.response().end();
actually intended here? Why not event.next()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
event.response().end();
actually intended here? Why notevent.next()
?
It is, I don't know why Stuart implemented this whole endpoint this way, I think one they someone will report bug regarding other authentication mechanisms interfering, but when you call https://quarkus.io/guides/all-config#quarkus-vertx-http_quarkus-http-auth-form-post-location request path, you are supposed to be logged in and that is it. It should not continue let say to Quarkus REST (which is what was happening) or somewhere else. There is following property:
quarkus.http.auth.form.landing-page
that is where Quarkus redirects you if this request was successful to log in- is it is not set, e.g. like
quarkus.http.auth.form.landing-page=
, then we return 200 (for SPA where JS determines what next)
So I never actually expect this to be not ended. I was strongly considering to return 500 and log some error message, but there are users that inherit from this mechanism and customize it, I am not 100 % sure what they do, hence just ending it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
of course we can continue using event.next()
, but I don't see a point. if you have an idea, I can change it, it is not the root cause
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also I am not 100 % there is always some handler that ends the response, I never checked if Vert.x or Quarkus has something like "last resort handler" that ends it if noone else did?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose it is implemented this way to align with proactive auth.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sberyozkin I am just fixing bug (IMHO correctly), it is not my design/code, that is how it worked from the start (I assume).
No, I don't think it can be constrained to the FormAuthenticationMechanism
because we know some users inherits this mechanism, some can use delegate
pattern and call that mechanism completely differently. We would break their applications. This code is basically same thing as:
- enforce authentication for path
/j_security_check
So it is completely safe, I just don't think it is always reliable, like if there are other authentication mechanisms like the code flow, they can interfere). So maybe some users will need to use path-based authentication if they combine multiple authentication mechanisms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more thing, from @geoand and @sberyozkin questions I am not sure it is clear, maybe I should had written it to the PR description. The issue here was that FormAuthenticationMechanism
does what is supposed to do, it sends the response, but this code still did next()
. The fact that I added end()
, well, it just felt right. :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, what you did feels right to me too, but I am not privy to this code at all
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@michalvavrik Oh, this code is specific to the form processing, done inside the form specific handler, it was not easy to see it in the PR, so LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fun fact, I think this issue #30637 is example of such unreliability I mentioned; wdyt @sberyozkin ? we can move discussion into the issue
Status for workflow
|