Commit aa157f5
authored
FIX: Delete destination_url cookie when it's used to set origin param during redirect to social auth (#36194)
When we navigate out to a social auth method, we set the origin param on
that request to the value of the destination_url.
Upon returning to Discourse, that origin param is returned and [we use
it to
set](https://github.com/discourse/discourse/blob/4dd3becec10c5b245ca122e684244f604b5c550a/config/initializers/009-omniauth.rb#L24)
server_session["destination_url"].
Then during the [omniauth
callback](https://github.com/discourse/discourse/blob/4dd3becec10c5b245ca122e684244f604b5c550a/app/controllers/users/omniauth_callbacks_controller.rb#L43),
we use the server_session["destination_url"] value to redirect back to
the page the destination_url cookie originally pointed to.
The problem is that in this scenario, the destination_url cookie never
gets deleted. This was causing a bug with Discourse ID in a corner case
where [the discourse-login plugin sets the destination_url
cookie](https://github.com/discourse-org/discourse-login/blob/646e32f4a66acab3692360188364815e5ff08fcf/config/initializers/doorkeeper.rb#L38)
to a url that contains an OAuth state parameter which can become stale,
and the cookie keeps getting re-used for redirection but not deleted,
resulting in an error message "Sorry, the authorization timed out, or
you have switched browsers. Please try again." which the user can't
escape.
The solution is to make sure that when we return to the omniauth callback we always clean up both the server_session[:destination_url] and cookies[:destination_url]1 parent 5789d7e commit aa157f5
File tree
2 files changed
+33
-2
lines changed- app/controllers/users
- spec/system
2 files changed
+33
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
46 | 45 | | |
47 | 46 | | |
48 | 47 | | |
49 | 48 | | |
50 | | - | |
51 | 49 | | |
52 | 50 | | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
53 | 54 | | |
54 | 55 | | |
55 | 56 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
438 | 438 | | |
439 | 439 | | |
440 | 440 | | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
441 | 471 | | |
442 | 472 | | |
443 | 473 | | |
| |||
0 commit comments