# GHSA-wr2m-38xh-rpc9: Lemmy user purging users or communities or banning users can delete images they didn't upload/exclusively use

> Privileged users can inadvertently delete media files belonging to other users due to improper ownership checks during user or community purging.

- **Severity:** Not scored
- **Exploited in the wild:** Not known
- **Login needed:** An administrator
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 8 Apr 2025

## What is GHSA-wr2m-38xh-rpc9?

GHSA-wr2m-38xh-rpc9 is a missing authorization vulnerability in lemmy_server, published on 8 Apr 2025. An attacker needs administrator access to exploit it, with no action from the victim.

### Official description

### Summary
An improper uploaded media ownership check can result in inadvertent deletion of media when a user is banned with content removal or purged. This can lead to deletion of media that was not uploaded by the banned/purged user. This also applies to purged communities, in which case all media posted in that community will get deleted without proper ownership check.
This is limited to media with an `image/*` content-type returned by pict-rs.

### Details
Lemmy did not associate users with media uploads until version 0.19.0 ([#3927](https://github.com/LemmyNet/lemmy/pull/3927)).
Back when the first parts of content purging were implemented for 0.17.0 ([#1809](https://github.com/LemmyNet/lemmy/pull/1809)), it was therefore not possible to properly identify media belonging to a specific user for situations in which this data should get erased from pict-rs, Lemmy's media storage backend.

Pict-rs deduplicates uploaded files transparently. As a result, it has two types of media deletion. A regular deletion will only remove the referenced alias, and if there are not other aliases pointing to the same file, the backing file will also be deleted. A purge on the other hand will delete all aliases pointing to the specified file, as well as the file itself.

The logic implemented in 0.17.0 iterated over media URLs related to users and communities when purging them and purged them from pict-rs. This results in a full deletion of the backing media, even if either the same URL was the result of an upload by a different user, or the same media being uploaded by another user with a different alias.
For user purges, Lemmy iterated over all posts they created and applied this to all media referenced in post URLs and post thumbnails. For community purges, this applied to all posts within this community.

Additionally, the deletion of user avatars, banners, as well as the media from all their posts was implemented when users were banned with content removal. This includes local bans and also bans received via federation, when a user gets banned on their home instance.

The function for purging images from pict-rs performs a check at the start to verify that the media `Content-Type` header returned by pict-rs starts with `image/`, which limits this to not affect other media types supported by Lemmy and pict-rs, such as videos.

### Impact

#### Instances with open federation
The vast majority of Lemmy instances has open federation, which means that this can be exploited remotely without any authentication.

#### Instances with limited or no federation
Exploitation requires user interaction by an admin of the targeted instance or a federation-linked instance if federation is enabled.
It may also require authentication, as instances may not have open registrations.

## Which versions are affected by GHSA-wr2m-38xh-rpc9?

2 open source packages ship an affected version, including lemmy_server.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `lemmy_server` | crates.io | From 0.17.0 | 0.19.11 |
| `lemmy_server` | crates.io | From 0.17.0 | 0.19.11 |

## How do I fix GHSA-wr2m-38xh-rpc9?

Upgrade lemmy_server to 0.19.11 or later.

## Is GHSA-wr2m-38xh-rpc9 being exploited?

There is no known exploitation of GHSA-wr2m-38xh-rpc9 in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-wr2m-38xh-rpc9 and fix it if it is affected.

What it is: GHSA-wr2m-38xh-rpc9 is a missing authorization vulnerability in lemmy_server, published on 8 Apr 2025. An attacker needs administrator access to exploit it, with no action from the victim.
Exploitation: There is no known exploitation of GHSA-wr2m-38xh-rpc9 in the wild and no public exploit code.

Affected packages and fixed versions:
- lemmy_server (crates.io): affected from 0.17.0; fixed in 0.19.11
- lemmy_server (crates.io): affected from 0.17.0; fixed in 0.19.11

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/GHSA-wr2m-38xh-rpc9/ (Markdown: https://insights.sbomify.com/GHSA-wr2m-38xh-rpc9/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-wr2m-38xh-rpc9

---
From sbomify Insights: https://insights.sbomify.com/GHSA-wr2m-38xh-rpc9/
Summaries are generated and may contain mistakes; the official description above is the record.
