this post was submitted on 10 Jul 2023
231 points (100.0% liked)

Lemmy Administration

698 readers
3 users here now

Anything about running your own Lemmy instance. Including how to install it, maintain and customise it.

Be sure to check out the docs: https://join-lemmy.org/docs/en/administration/administration.html

If you have any problems, describe them here and we will try to help you fixing them.

founded 4 years ago
MODERATORS
 

UPDATE: The latest RC version of Lemmy-ui (0.18.2-rc.2) contains fixes for the issue, but if you believe you were vulnerable, you should still rotate your JWT secret after upgrading! Read below for instructions. Removing custom emoji is no longer necessary after upgrading.

Original post follows:


This post is intended as a central place that admins can reference regarding the XSS incident from this morning.

What happened?

A couple of the bigger Lemmy instances had several user accounts compromised through stolen authentication cookies. Some of these cookies belonged to admins, these admin cookies were used to deface instances. Only users that opened pages with malicious content during the incident were vulnerable. The malicious content was possible due to a bug with rendering custom emojis.

Stolen cookies gave attackers access to all private messages and e-mail addresses of affected users.

Am I vulnerable?

If your instance has ANY custom emojis, you are vulnerable. Note that it appears only local custom emojis are affected, so federated content with custom emojis from other instances should be safe.

I had custom emojis on my instance, what should I do?

This should be enough to mitigate now:

  1. Remove custom emoji
DELETE FROM custom_emoji_keyword;
DELETE FROM custom_emoji;
  1. Rotate your JWT secret (invalidates all current login sessions)
-- back up your secret first, just in case
SELECT * FROM secret;
-- generate a new secret
UPDATE secret SET jwt_secret = gen_random_uuid();
  1. Restart Lemmy server

If you need help with any of this, you can reach out to me on Matrix (@sunaurus:matrix.org) or on Discord (@sunaurus)

Legal

If your instance was affected, you may have some legal obligations. Please check this comment for more info: https://lemmy.world/comment/1064402

More context:

https://github.com/LemmyNet/lemmy-ui/issues/1895

https://github.com/LemmyNet/lemmy-ui/pull/1897

you are viewing a single comment's thread
view the rest of the comments
[–] db0@lemmy.dbzer0.com 28 points 1 year ago (2 children)

Thanks for posting. There really should be a button which allows the admins to log everyone out for crisis situations like there I think

[–] MarcellusDrum@lemmy.ml 20 points 1 year ago (1 children)

Changing the JWT secret does this. So instead of a button, its a line of code, making it less likely to be done by mistake.

[–] db0@lemmy.dbzer0.com 6 points 1 year ago (1 children)

True as that is, not every admin has DB access and those with DB access might be AFK.

[–] StudioLE@programming.dev 12 points 1 year ago (1 children)

Surely this exploit proves that it's best to minimise the number of administrative actions available in the UI?

[–] db0@lemmy.dbzer0.com 5 points 1 year ago

Destructive actions, sure. This would not be one such actions and it would be self-defeating.

[–] BaconIsAVeg@lemmy.ml 5 points 1 year ago* (last edited 1 year ago) (1 children)

In crisis situations like this, the last thing you want is to rely on some portion of the application UI working.

[–] db0@lemmy.dbzer0.com 0 points 1 year ago (1 children)

If the UI doesn't work, there's always the DB directly. But it's good to have that option.

[–] Dark_Arc@lemmy.world 2 points 1 year ago* (last edited 1 year ago) (1 children)

JWT secret keys are not in the DB (speaking typically, maybe for Lemmy they are, but that would be very surprising), that's typically an environment variable or configuration file sort of thing.

In any case, this isn't the part that's broken, it doesn't need fixed.

[–] db0@lemmy.dbzer0.com 2 points 1 year ago* (last edited 1 year ago) (1 children)
Rotate your JWT secret (invalidates all current login sessions)

-- back up your secret first, just in case SELECT * FROM secret; -- generate a new secret UPDATE secret SET jwt_secret = gen_random_uuid();

It's in the DB. Check the OP

I am also not suggesting a fix. I am suggesting an improvement

[–] Dark_Arc@lemmy.world 2 points 1 year ago (2 children)

Oof, okay well that's not how I would've done it. The JWT secret in the database itself could be a vulnerability (e.g., someone that gains read only access to the database could then use that as a wedge to create any JWT they wanted). I'm not sure if that's actually worth bringing up or not (it's a bit of an odd case).

[–] Caoldence222@lemmy.world 1 points 1 year ago (1 children)

It used to be in a config file but they moved it to the db so it could be autogenerated on first startup I believe. I guess it's better than newb instances running around with a jwt secret of "changeme" but still...

[–] Dark_Arc@lemmy.world 2 points 1 year ago

Hm... They could've edited the config or just exit(1) if the credential is the default, but very fair.

[–] PunchEnergy@lemmy.dbzer0.com 0 points 1 year ago* (last edited 1 year ago) (1 children)

afaik to generate those tokens, you configure a secret in an enviroment variable. You cannot generate tokens from looking at valid tokens within the database. Thus storing active tokens in the database is fine since you can always purge all active tokens as this post has also suggested.

[–] Dark_Arc@lemmy.world 1 points 1 year ago* (last edited 1 year ago) (2 children)

This is the secret, not the tokens.

[–] PunchEnergy@lemmy.dbzer0.com 1 points 1 year ago (1 children)

oh i see, they want to delete the secret instead of the active tokens. Yeah now i get what you mean. Seems kinda odd.

[–] Dark_Arc@lemmy.world 2 points 1 year ago (1 children)

I don't know enough about Lemmy's JWT design, but some JWT designs don't store the JWT in a database at all, so the only correct response is to regenerate the secret and kill all the sessions by them failing the validity checks.

[–] PunchEnergy@lemmy.dbzer0.com 0 points 1 year ago* (last edited 1 year ago) (1 children)
[–] Dark_Arc@lemmy.world 1 points 1 year ago

No, you said you can't generate valid tokens within the database. I just told you this is the secret, not the tokens (that is present in the database).