-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Send password reset from HS: database stuff #5308
Send password reset from HS: database stuff #5308
Conversation
Codecov Report
@@ Coverage Diff @@
## anoa/feature_hs_password_resets #5308 +/- ##
===================================================================
- Coverage 63.04% 62.76% -0.29%
===================================================================
Files 341 341
Lines 35637 35536 -101
Branches 5835 5816 -19
===================================================================
- Hits 22468 22304 -164
- Misses 11598 11662 +64
+ Partials 1571 1570 -1 |
New schema change should go in |
synapse/storage/registration.py
Outdated
"""Remove threepid validation tokens with expiry dates that have passed""" | ||
def cull_expired_threepid_validation_tokens_txn(txn, ts): | ||
sql = ("DELETE FROM threepid_validation_token WHERE " | ||
"expires < ?") |
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.
Can you use multiline strings please, it makes it easier to change/c+p etc
expires BIGINT NOT NULL | ||
); | ||
|
||
CREATE INDEX threepid_validations_session_id ON threepid_validation_session(session_id); |
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.
This will create a duplicate index I believe, since PRIMARY KEY
will create a unique index.
|
||
CREATE INDEX threepid_validations_session_id ON threepid_validation_session(session_id); | ||
|
||
CREATE INDEX threepid_validation_token_session_id ON threepid_validation_token(session_id); |
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.
Ditto
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.
Just fix up the sql a bit and then merge into your base branch
synapse/storage/registration.py
Outdated
Args: | ||
medium (str): The medium of the 3PID | ||
address (str): The address of the 3PID | ||
sid (str): The ID of the validation session |
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.
What does it mean if these are None?
synapse/storage/registration.py
Outdated
|
||
if sid: | ||
keyvalues["session_id"] = sid | ||
elif address: |
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.
elif
? If we expect that only one is set, then let's assert that
synapse/storage/registration.py
Outdated
"client_secret", "last_send_attempt", "validated_at", | ||
] | ||
|
||
sql = "SELECT %s FROM threepid_validation_session" % ", ".join(cols_to_return) |
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.
Just stick these in the path rather than string concatenating them, see below
synapse/storage/registration.py
Outdated
# Convert the resulting row to a dictionary | ||
ret = {} | ||
for i in range(len(cols_to_return)): | ||
ret[cols_to_return[i]] = row[i] |
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.
We have helper function that uses the returned data structure to do this for us. Instead of txn.fetchone()
:
rows = self.cursor_to_dict(txn)
if not rows:
return None
return rows[0]
synapse/storage/registration.py
Outdated
if not row: | ||
raise ThreepidValidationError( | ||
400, "Validation token not found or has expired", | ||
) |
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.
If we're are conditionally doing stuff we should do this in a txn.
1505cd6
to
8f9daa4
Compare
…identity server (#5377) Sends password reset emails from the homeserver instead of proxying to the identity server. This is now the default behaviour for security reasons. If you wish to continue proxying password reset requests to the identity server you must now enable the email.trust_identity_server_for_password_resets option. This PR is a culmination of 3 smaller PRs which have each been separately reviewed: * #5308 * #5345 * #5368
Database component of new behaviour of sending password reset emails from Synapse instead of Sydent.
Allows one to store threepid validation sessions along with password reset token attempts and retrieve them again.
Relevant spec bits:
https://matrix.org/docs/spec/client_server/unstable.html#post-matrix-client-r0-account-password-email-requesttoken
https://matrix.org/docs/spec/identity_service/r0.1.0.html#post-matrix-identity-api-v1-validate-email-submittoken
Essentially the flow is:
/requestToken
is made with an email address, a client secret and a send_attempt to the homeserver/submitToken
on the homeserver, and we check if those three vars match up with a session and a validation request