<commit_before># Invalidating devices during password modification

There are multiple use cases for why a user might want to modify their password:

* Adopting a password manager (to use a unique password or more secure password).
* Password rotation.
* Re-secure a compromised account.
* ... probably tons of others ...

These can be summarized into two groups:

1. "My account has been compromised and I need to re-secure it."
2. "I just want to change my password."

The [current Matrix specification](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-account-password)
does not provide a way to differentiate between these use cases. It gives no
guidance into what should happen to other sessions / devices when a password is
modified and leaves it up to the implementation.

It is reasonable for a client to want to specify this behavior to offer two
different workflows:

1. Modify a password and log all other devices out (for use when an account has
   been compromised).
2. Modify a password and do not touch any session data (for use in a
   non-malicious situations).

Alternately a client may default to whichever workflow is best for their users.

## Proposal

An optional field is added to the JSON body body of the [password reset endpoint](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-account-password)
called `logout_devices`. This is a boolean flag (defaulting to `true`) that
signals to whether other devices and sessions should be invalidated after
modifying the password.

## Potential issues

While Synapse defaults to the behavior of invalidating other devices and
sessions this may not be true of other implementations. Thus, a default of
`true` may not be backwards compatible. It might be more prudent to specify that
the behavior of not specifying the `logout_devices` flag is undefined.

## Alternatives

Provide a new endpoint in a future version that supports an additional field (as
above), using a new endpoint would avoid backwards compatibility issues.

## Security considerations

By defaulting to invalidating devices and sessions the security considerations
of this endpoint should remain intact. A client will need to be modified to
choose to keep other devices active.
<commit_msg>Remove concerns about backwards compatibility.<commit_after># Invalidating devices during password modification

There are multiple use cases for why a user might want to modify their password:

* Adopting a password manager (to use a unique password or more secure password).
* Password rotation.
* Re-secure a compromised account.
* ... probably tons of others ...

These can be summarized into two groups:

1. "My account has been compromised and I need to re-secure it."
2. "I just want to change my password."

The [current Matrix specification](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-account-password)
does not provide a way to differentiate between these use cases. It gives no
guidance into what should happen to other sessions / devices when a password is
modified and leaves it up to the implementation.

It is reasonable for a client to want to specify this behavior to offer two
different workflows:

1. Modify a password and log all other devices out (for use when an account has
   been compromised).
2. Modify a password and do not touch any session data (for use in a
   non-malicious situations).

Alternately a client may default to whichever workflow is best for their users.

## Proposal

An optional field is added to the JSON body body of the [password reset endpoint](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-account-password)
called `logout_devices`. This is a boolean flag (defaulting to `true`) that
signals to whether other devices and sessions should be invalidated after
modifying the password.

## Potential issues

The specification states:

> The homeserver SHOULD NOT revoke the access token provided in the request,
> however all other access tokens for the user should be revoked if the request
> succeeds.

Defaulting `logout_devices` to `true` should be backwards compatible.

## Alternatives

A new endpoint could be provided in a future version of the specification that
supports an additional field (as described above).

## Security considerations

By defaulting to invalidating devices and sessions the security considerations
of this endpoint should remain intact. A client will need to be modified to
choose to keep other devices active.

{'fraction_non_alphanumeric': 0.05159433126660762, 'fraction_numerical': 0.005314437555358724, 'mean_word_length': 4.4487334137515075, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5394191', 'n_tokens_mistral': 1130, 'n_tokens_neox': 1083, 'n_words': 637}