Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MIME type set by client ignored #32754

Open
paulchen opened this issue Jul 10, 2024 · 1 comment
Open

MIME type set by client ignored #32754

paulchen opened this issue Jul 10, 2024 · 1 comment

Comments

@paulchen
Copy link

paulchen commented Jul 10, 2024

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:

  1. Obtain the rid for a channel and the authToken and the userId for a logged-in user.
  2. Download this file and rename it to pinksquare (without the .png extension): https://github.com/RocketChat/Rocket.Chat/assets/404840/08a10e00-a0ff-4204-a8e2-9b8c75ae615d
  3. 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 "[email protected];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
}
@reetp
Copy link

reetp commented Jul 13, 2024

Thanks for the report.

I'll ask someone to take a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants