element-hq / element-hq/synapse

Chunked transfer encoding for media upload not possible

Open
#18,414 0 comments 0 reactions 0 assignees View on GitHub
A-Media-Repository good first issue S-Tolerable T-Defect
Dominant language
Python
Stars
4.6k
Forks
600
Avg merge
5d 22h
Merged PRs (30d)
51

Description

### Description

If a client uses Chunked Transfer Encoding for media upload, the Homeserver refuses the upload since Content-Length is not set.

See https://github.com/element-hq/synapse/blob/ae877aa101796a0cd57c3637a875140ddb25ed51/synapse/rest/media/upload_resource.py#L57

### Steps to reproduce

Send "POST /_matrix/media/v3/upload" for an authorized client:

```
POST /_matrix/media/v3/upload HTTP/1.1
Transfer-encoding: chunked
Content-Type: application/octet-stream
accept: */*
accept-language: de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7
authorization: Bearer syt_xxxxxxxxxxxxxxxxxx_3susg5
host: localhost
referer: http://localhost:9280/
request-id: 7e19e972-f5c5-4517-910d-1f09031cea21
sec-ch-ua: "Chromium";v="136", "Google Chrome";v="136", "Not.A/Brand";v="99"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "Windows"
sec-fetch-dest: empty
sec-fetch-mode: cors
sec-fetch-site: cross-site
user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36
x-forwarded-for: 192.168.143.2,localhost
x-forwarded-host: localhost
x-forwarded-proto: https

6
···tw·
0

```

leads to:

```
2025-05-08 13:57:46,734 - synapse.access.http.8008 - 463 - DEBUG - POST-e5aa0a44-3462-4272-816b-605e2f6e53ad - 192.168.143.2 - 8008 - Received request: POST /_matrix/media/v3/upload
2025-05-08T13:57:46.737763265Z 2025-05-08 13:57:46,737 - synapse.http.server - 130 - INFO - POST-e5aa0a44-3462-4272-816b-605e2f6e53ad - SynapseError: 400 - Request must specify a Content-Length
```

### Homeserver

matrix.org

### Synapse Version

v1.121.1

### Installation Method

Docker (matrixdotorg/synapse)

### Database

PostgreSQL

### Workers

Single process

### Platform

RedHat Openshift
RancherDesktop on Windows WSL

### Configuration

_No response_

### Relevant log output

```shell
2025-05-08 13:57:46,734 - synapse.access.http.8008 - 463 - DEBUG - POST-e5aa0a44-3462-4272-816b-605e2f6e53ad - 192.168.143.2 - 8008 - Received request: POST /_matrix/media/v3/upload
2025-05-08T13:57:46.737763265Z 2025-05-08 13:57:46,737 - synapse.http.server - 130 - INFO - POST-e5aa0a44-3462-4272-816b-605e2f6e53ad - SynapseError: 400 - Request must specify a Content-Length
```

### Anything else that would be useful to know?

_No response_

Contributor guide

Open the contributing guide

Research direction

Start at synapse/rest/media/upload_resource.py around the Content-Length validation and trace how POST /_matrix/media/v3/upload reads request bodies. Determine how chunked transfer encoding should be accepted without a declared length, then verify that authorized media uploads using the shown request format complete successfully and retain the existing rejection behavior for invalid requests.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.