mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-08-02 04:26:02 -04:00
Limit the size of uploads
This commit is contained in:
parent
beaf50f5c6
commit
ee2bcdec65
3 changed files with 55 additions and 1 deletions
|
@ -56,6 +56,7 @@ class ContentRepoResource(resource.Resource):
|
|||
self.directory = directory
|
||||
self.auth = auth
|
||||
self.external_addr = external_addr.rstrip('/')
|
||||
self.max_upload_size = hs.config.max_upload_size
|
||||
|
||||
if not os.path.isdir(self.directory):
|
||||
os.mkdir(self.directory)
|
||||
|
@ -155,6 +156,19 @@ class ContentRepoResource(resource.Resource):
|
|||
@defer.inlineCallbacks
|
||||
def _async_render(self, request):
|
||||
try:
|
||||
# TODO: The checks here are a bit late. The content will have
|
||||
# already been uploaded to a tmp file at this point
|
||||
content_length = request.getHeader("Content-Length")
|
||||
if content_length is None:
|
||||
raise SynapseError(
|
||||
msg="Request must specify a Content-Length", code=400
|
||||
)
|
||||
if int(content_length) > self.max_upload_size:
|
||||
raise SynapseError(
|
||||
msg="Upload request body is too large",
|
||||
code=413,
|
||||
)
|
||||
|
||||
fname = yield self.map_request_to_name(request)
|
||||
|
||||
# TODO I have a suspcious feeling this is just going to block
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue