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

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

@Sharparam

Description

@Sharparam

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-Validation500 (mostly) errors due to lack of event/parameter validationz-bug(Deprecated Label)z-p2(Deprecated Label)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions