Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

500 Internal Server error if uploading without Content-Length #5114

Closed
Sharparam opened this issue Apr 30, 2019 · 5 comments
Closed

500 Internal Server error if uploading without Content-Length #5114

Sharparam opened this issue Apr 30, 2019 · 5 comments
Labels
A-Validation 500 (mostly) errors due to lack of event/parameter validation z-bug (Deprecated Label) z-p2 (Deprecated Label)

Comments

@Sharparam
Copy link

Description

If the API /_matrix/media/{apiVersion}/upload is called without a Content-Length header set, Synapse will throw an internal server error as it tries to access the header value without verifying that it exists first.

Relevant message in #matrix-dev:matrix.org

Steps to reproduce

  • Perform the following cURL request:
    curl -X POST --insecure "http://localhost:8008/_matrix/media/r0/upload?filename=test.txt
  • Supply authorization in some way

Expected behaviour

Synapse responds with some kind of 4xx client failure telling me i need to provide data and relevant headers.

Actual behaviour

Synapse responds with a 500 Internal Server Error.

Log/stacktrace

2019-04-30 15:49:33,896 - synapse.http.server - 112 - ERROR - POST-67594- Failed handle request via 'UploadResource': <XForwardedForRequest at 0x7fa0a18e0a20 method='POST' uri='/_matrix/media/r0/upload?filename=1111.jpg&access_token=<redacted>' clientproto='HTTP/1.1' site=8008>
Traceback (most recent call last):
  File "/home/matrix/synapse/env/lib/python3.6/site-packages/synapse/http/server.py", line 81, in wrapped_request_handler
    yield h(self, request)
  File "/home/matrix/synapse/env/lib/python3.6/site-packages/twisted/internet/defer.py", line 1418, in _inlineCallbacks
    result = g.send(result)
  File "/home/matrix/synapse/env/lib/python3.6/site-packages/synapse/rest/media/v1/upload_resource.py", line 58, in _async_render_POST
    content_length = request.getHeader(b"Content-Length").decode('ascii')
AttributeError: 'NoneType' object has no attribute 'decode'

Version information

  • Homeserver: matrix.sharparam.com

If not matrix.org:

  • Version: 0.99.3

  • Install method: pip

  • Platform: Ubuntu 18.04
@neilisfragile neilisfragile added z-bug (Deprecated Label) z-p2 (Deprecated Label) labels May 7, 2019
@nikhiltechzillaindiacom

It worked from backed.

@richvdh richvdh added the A-Validation 500 (mostly) errors due to lack of event/parameter validation label Mar 19, 2020
@richvdh
Copy link
Member

richvdh commented Apr 24, 2020

related: #1610

@DataBeaver
Copy link

I would like to add that the Matrix client-server spec makes no mention of the Content-Length header and the HTTP spec allows using Transfer-Encoding: chunked as an alternative to Content-Length.

@dalcde
Copy link
Contributor

dalcde commented Apr 10, 2021

This is fixed by df3e6a2

@richvdh
Copy link
Member

richvdh commented Apr 12, 2021

... which was part of #8862.

@richvdh richvdh closed this as completed Apr 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-Validation 500 (mostly) errors due to lack of event/parameter validation z-bug (Deprecated Label) z-p2 (Deprecated Label)
Projects
None yet
Development

No branches or pull requests

6 participants