Commit f01bab5
committed
Clear account tokens when an account change is made
Previously, the only account change that cleared all account tokens
was closing the account. If you reset your password, only the reset
password token was cleared, if you verified a login change, only the
verify login change token was cleared, etc. This changes the default
behavior to clear most account tokens when an account change is made.
The following account changes trigger clearing of tokens:
* change login
* close account
* reset password
* unlock account
* verify account
The following account tokens are cleared upon such actions:
* active sessions (other than logged in session)
* email auth
* jwt refresh (if not logged in)
* lockout (updates token if it exists)
* remember (creates and uses new remember token if logged in via remember token)
* reset password
* single session (if not logged in)
* verify account
* verify login change
This provides more secure behavior in some cases. Let's say you
notice something funny with your email. You request a password
change. However, then you realize someone has access to your email,
so you change your login. Previously, the password reset link for
the account is still valid after the email change, so an attacker
can still change the password on the account post login change.
With this commit, once the login has been changed, the reset
password token is no longer valid. Similarly, once the password has
been reset, the verify login change token is no longer valid.
While I think this makes for a more secure and more appropriate
default, it's possible that this behavior is not desirable for all
Rodauth installations. To allow for customization, a clear_tokens
configuration method is available. This takes a block that is
passed a symbol for the change being made. The user can override
the behavior for specific symbols. They can also call super with
the reason to get the default behavior of clearing all related
tokens.
This unfortunately requires a number of special cases so that it
does not break expected behavior. For active_sessions and
single_session, you don't want to clear a token used for the
current session, because otherwise changing your login would result
in a logout. For lockout, you cannot clear the token, because that
would result in an account unlock, so instead the token is updated.
Remember is a mix between active_sessions/single_session and lockout,
where you want to clear the token if the session is not logged in
via remember, if the session is logged in via remember, you want
to update the session value, so that the current session stays
remembered.
For jwt_refresh, this does not clear refresh tokens if the session
is logged in, as we don't know which refresh token is for the
current session. Potentially that ability could be added in the
future, but this issue is simple to address by using the
active_sessions feature, so recommend that approach.1 parent 0cee9cb commit f01bab5
File tree
23 files changed
+476
-20
lines changed- doc
- lib/rodauth/features
- spec
23 files changed
+476
-20
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
1 | 5 | | |
2 | 6 | | |
3 | 7 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
28 | 36 | | |
29 | 37 | | |
30 | 38 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
128 | 133 | | |
129 | 134 | | |
130 | 135 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
| 96 | + | |
96 | 97 | | |
97 | 98 | | |
98 | 99 | | |
| |||
330 | 331 | | |
331 | 332 | | |
332 | 333 | | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
333 | 337 | | |
334 | 338 | | |
335 | 339 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
89 | | - | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
90 | 92 | | |
91 | 93 | | |
92 | 94 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
| 49 | + | |
48 | 50 | | |
49 | 51 | | |
50 | 52 | | |
51 | 53 | | |
52 | | - | |
53 | 54 | | |
54 | 55 | | |
55 | 56 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
167 | 167 | | |
168 | 168 | | |
169 | 169 | | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
170 | 175 | | |
171 | 176 | | |
172 | 177 | | |
| |||
210 | 215 | | |
211 | 216 | | |
212 | 217 | | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | 218 | | |
219 | 219 | | |
220 | 220 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
92 | 97 | | |
93 | 98 | | |
94 | 99 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
| 129 | + | |
129 | 130 | | |
130 | 131 | | |
131 | 132 | | |
| |||
241 | 242 | | |
242 | 243 | | |
243 | 244 | | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
244 | 250 | | |
245 | 251 | | |
246 | 252 | | |
| |||
0 commit comments