RocketChat / RocketChat/Rocket.Chat
MIME type set by client ignored
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 46.1k
- Forks
- 13.9k
- Avg merge
- 3d 3h
- Merged PRs (30d)
- 130
Description
Description:
When using the rooms.upload endpoint, the MIME type sent along is ignored. Instead, the server will guess the MIME type based on the filename.
Steps to reproduce:
- Obtain the
ridfor a channel and theauthTokenand theuserIdfor a logged-in user. - Download this file and rename it to
pinksquare(without the.pngextension): https://github.com/RocketChat/Rocket.Chat/assets/404840/08a10e00-a0ff-4204-a8e2-9b8c75ae615d - Run this cURL snippet (with
<host>,<rid>,<userId>,<authToken>replaced by the actual values):
curl --request POST \
--url https://<host>/api/v1/rooms.upload/<rid> \
--header 'accept: application/json' \
--header 'content-type: multipart/form-data' \
--header 'x-user-id: <userId>' \
--header 'x-auth-token: <authToken>' \
-F "file=@pinksquare;type=image/png"
Expected behavior:
The file is stored with the MIME type image/png.
Actual behavior:
The file is stored with the MIME type application/octet-stream and therefore not treated as an image.
JSON response by the endpoint:
{
"message": {
"_id": "<id>",
"rid": "<rid>",
"ts": "2024-07-10T15:39:40.394Z",
"msg": "",
"file": {
"_id": "668eab3cc93d62f6f83b7662",
"name": "pinksquare",
"type": "application/octet-stream",
"size": 519,
"format": ""
},
"files": [
{
"_id": "668eab3cc93d62f6f83b7662",
"name": "pinksquare",
"type": "application/octet-stream",
"size": 519,
"format": ""
}
],
"attachments": [
{
"ts": "1970-01-01T00:00:00.000Z",
"title": "pinksquare",
"title_link": "/file-upload/668eab3cc93d62f6f83b7662/pinksquare",
"title_link_download": true,
"type": "file",
"format": "file",
"size": 519
}
],
"u": {
"_id": "<id>",
"username": "<username>",
"name": "<name>"
},
"_updatedAt": "2024-07-10T15:39:40.450Z",
"urls": []
},
"success": true
}
Server Setup Information:
- Version of Rocket.Chat Server: 6.10.0
- License Type: Starter
- Number of Users: 21 (why is this relevant?)
- Deployment Method: Docker
- Number of Running Instances: 1
- MongoDB Version: 6.0.16 / wiredTiger (oplog Disabled)
Client Setup Information
Any client that wants the MIME type to be stored on the server.
Additional context
This problem was introduced by #32471. At apps/meteor/app/api/server/lib/getUploadFormData.ts:86, the MIME sent by the client is discarded.
When using the filename pinksquare.png, the MIME type is determined correctly based on the extension .png:
curl --request POST \
--url https://<host>/api/v1/rooms.upload/<rid> \
--header 'accept: application/json' \
--header 'content-type: multipart/form-data' \
--header 'x-user-id: <userId>' \
--header 'x-auth-token: <authToken>' \
-F "file=@pinksquare.png;type=image/png"
{
"message": {
"_id": "<id>",
"rid": "<rid>",
"ts": "2024-07-10T15:40:34.266Z",
"msg": "",
"file": {
"_id": "668eab71c93d62f6f83b7663",
"name": "pinksquare.png",
"type": "image/png",
"size": 519,
"format": "png"
},
"files": [
{
"_id": "668eab71c93d62f6f83b7663",
"name": "pinksquare.png",
"type": "image/png",
"size": 519,
"format": "png"
}
],
"attachments": [
{
"ts": "1970-01-01T00:00:00.000Z",
"title": "pinksquare.png",
"title_link": "/file-upload/668eab71c93d62f6f83b7663/pinksquare.png",
"title_link_download": true,
"image_dimensions": {
"width": 1,
"height": 1
},
"image_preview": "/9j/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/2wBDAQcHBwoIChMKChMoGhYaKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wAARCAAgACADASIAAhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAX/xAAUEAEAAAAAAAAAAAAAAAAAAAAA/8QAFQEBAQAAAAAAAAAAAAAAAAAAAAf/xAAUEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwCAAsC9AAAAAAP/2Q==",
"image_url": "/file-upload/668eab71c93d62f6f83b7663/pinksquare.png",
"image_type": "image/png",
"image_size": 519,
"type": "file"
}
],
"u": {
"_id": "<id>",
"username": "<username>",
"name": "<name>"
},
"_updatedAt": "2024-07-10T15:40:34.661Z",
"urls": []
},
"success": true
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in apps/meteor/app/api/server/lib/getUploadFormData.ts around line 86, identified in PR #32471, and trace how the rooms.upload multipart file metadata is handled. Reproduce the extensionless pinksquare upload with the provided cURL command; done means the stored file and endpoint response retain the client-supplied image/png MIME type.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100