This is a bit of a weird one. It requires a discourse install using “full screen login” for authentication, and the omniauth origin param set to an external url (this is done either through a referrer or the ?origin=
param).
Steps to reproduce:
- Log into a Discourse site using FSL, setting the origin to an external site
e.g. https://discourse.mozilla.org/auth/auth0?origin=http://example.com/ (I’d suggest logging in via passwordless by entering your email at the top, GitHub authentication currently requires 2FA) - Log out of the Discourse site after a successful login
Result:
You’re redirected to the external site.
Video:
What’s going on here:
During login, in omniauth_callbacks_controller.rb
:
# origin is e.g. "http://example.com/"
parsed = URI.parse(origin)
@origin = "#{parsed.path}?#{parsed.query}"
cookies[:authentication_data] = {
destination_url: origin
}
redirect_to @origin
@origin
is a host-less url, but origin
is absolute. So in this case @origin = "/"
Also note, the cookie is set to the absolute origin
, but the redirect is to the host-less @origin
.
After logout, thanks to this in application.html.erb
(which triggers a call to Discourse.authenticationComplete
with the data), the user is redirected to the destination_url
set above:
<%- if !current_user && cookies[:authentication_data] %>
<meta id="data-authentication" data-authentication-data="<%= cookies.delete(:authentication_data) %>">
<%- end %>
So, there’s a couple of problems here:
-
That
authentcation_data
cookie seems to exist for login only. It then triggeringDiscourse.authenticationComplete
on logout seems wrong to me. The cookie should probably be nuked on logout. This would prevent the post-logout redirect toorigin
. -
The code in
omniauth_callbacks_controller.rb
is written to assume that theorigin
has the same domain as the Discourse instance, but that’s not always the case. I don’t know if the cookie-origin
/redirect-@origin
discrepancy is deliberate, but clearingorigin
prior to generating@origin
if it’s not a Discourse url should fix this problem.
I’m happy to work on a PR to fix these two issues.