Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Limit number of devices per user #8263

Open
TheJJ opened this issue Sep 6, 2020 · 12 comments
Open

Limit number of devices per user #8263

TheJJ opened this issue Sep 6, 2020 · 12 comments
Labels
A-Device-List-Tracking Telling clients about other devices. Often related to E2EE. S-Minor Blocks non-critical functionality, workarounds exist. T-Enhancement New features, changes in functionality, improvements in performance, or user-facing enhancements.

Comments

@TheJJ
Copy link
Contributor

TheJJ commented Sep 6, 2020

Synapse should have a limit of, say 100, devices per user. "Old" devices have to be removed first.

I've encountered a database where a bot account created over 20000 devices, because it apparently logs in again very often.

@erikjohnston erikjohnston added z-p2 (Deprecated Label) A-Performance Performance, both client-facing and admin-facing labels Sep 7, 2020
@ptman
Copy link
Contributor

ptman commented Sep 8, 2020

Hopefully a configurable limit. What should happen when limit is hit? Remove oldest device (or only if there are no keys associated with the device)? Or prevent logging in with new? If you cannot login you also cannot selectively log out the ones you want.

@TheJJ
Copy link
Contributor Author

TheJJ commented Sep 9, 2020

Of course configurable :)
Good question how to handle it. I'd say yes, the oldest one is logged out/accesskey revoked. Otherwise your account might be locked.

@clokep
Copy link
Member

clokep commented Oct 20, 2020

What would be your expected behavior when you run over that limit? An particular error during login? Maybe a 403 with a sane message. (The spec around this doesn't offer too many ideas for this.)

@TheJJ
Copy link
Contributor Author

TheJJ commented Oct 27, 2020

I think the new login should always succeed, but the oldest session is then logged out? That way you can never be locked out of your account, and old devices will be removed.

@richvdh
Copy link
Member

richvdh commented Nov 21, 2020

What would be your expected behavior when you run over that limit? An particular error during login?

the problem with this approach is that users could lock themselves out of their accounts by creating lots of devices and forgetting the access tokens for them. Then they can't log in to clear them out.

I think the new login should always succeed, but the oldest session is then logged out? That way you can never be locked out of your account, and old devices will be removed.

this doesn't seem like a great idea. A user with a long-running Element (or other) client, as well as a bot that logs in regularly, would suddenly find their Element logged out.

Deleting the least-recently-used device might work ok. I'm a little wary of letting people rely on that, but I can't think of many better ideas right now.

@auscompgeek
Copy link
Contributor

I would probably suggest deleting the LRU device without any device keys - those will be the most likely to be useless.

@notramo
Copy link

notramo commented Dec 23, 2020

Sometimes app reinstalls cause new devices

  • deleting app from mobile without logging out
  • closing private browser window

In this case, the device info should be taken into consideration:

  • one Element Android device
  • one Element Desktop device
  • several Element Web in Firefox

In this case, they are probably from private browsing mode, so even if the Element Desktop is the least recently active, the least recently active Firefox device should be deleted.

@aaronraimist
Copy link
Contributor

aaronraimist commented Dec 23, 2020

I do not think the server should be trying to parse device names to figure out which one it should log out. The server should not be picking which devices to log out at all unless the user has ignored many warnings. Logging out random device and possibly destroying E2E keys should be avoided as much as possible. The user should choose which device should be logged out.

I think there should be two configurable limits. One to start encouraging the user to log out of devices. For example when the user logs in to the 101st device let’s say then the server allows the login to proceed but provides a some message/error to the client which prompts the client to show an interface to encourage the user to log out of some sessions. If the user doesn’t delete any devices and stays above the limit then the error should continue to be given during every additional login.

For the case of a broken bot that continually logs in there should also be a second hard limit that can be set by the server admin where after that number of logins then the least recently used session is automatically logged out. I imagine this being set to 2500 or 5000, a high enough number that an account is not likely to hit it unless they are really doing something wrong. Maybe the server could provide additional notice of this limit by 403ing every other login attempt when the account reaches 90% of the limit or something.

@babolivier
Copy link
Contributor

Another alternative is something like #12855 that automatically logs out devices that haven't been active for a configured amount of time.

@squahtx squahtx added S-Minor Blocks non-critical functionality, workarounds exist. T-Enhancement New features, changes in functionality, improvements in performance, or user-facing enhancements. and removed z-p2 (Deprecated Label) A-Performance Performance, both client-facing and admin-facing labels May 24, 2022
@richvdh
Copy link
Member

richvdh commented Oct 7, 2022

It's maybe worth thinking about if OIDC (and also refresh tokens) will change the landscape here. For one thing, it will make it harder to write a hacky bash script which logs you in and forgets about the access token. (Any thoughts, @sandhose?)

I'm still not sure it solves the fundamental problem here, which is that it is impossible to distinguish between a shell script or incognito window which has long forgotten its access token (or refresh token), and a valid client which a user has chosen not to fire up for a few months.

@ptman
Copy link
Contributor

ptman commented Oct 7, 2022

One thing that could be done is to clean out devices that are older than x and haven't been used since the first y after being created

@richvdh
Copy link
Member

richvdh commented Oct 11, 2022

Another suggestion here:

  • Aggressively expire non-e2e devices (eg Delete stale non-e2e devices for users #14038)
  • Limit the number of devices which can have keys uploaded for them to N; if someone tries to call POST /_matrix/client/v3/keys/upload on an N+1th device, reject it with an error code; the client is then expected to take the user to the device-management panel to delete something.

@MadLittleMods MadLittleMods added the A-Device-List-Tracking Telling clients about other devices. Often related to E2EE. label Jun 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-Device-List-Tracking Telling clients about other devices. Often related to E2EE. S-Minor Blocks non-critical functionality, workarounds exist. T-Enhancement New features, changes in functionality, improvements in performance, or user-facing enhancements.
Projects
None yet
Development

No branches or pull requests