Skip to content
New issue

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

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

Already on GitHub? # to your account

more checks when handling uploads #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions xmpp_http_upload/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
from rest_framework.response import Response
from rest_framework.views import APIView

from urllib.parse import unquote

from .models import Upload
from .utils import get_config
from .utils import ws_download
Expand Down Expand Up @@ -181,15 +183,16 @@ def get(self, request, hash, filename):
"""Download a file."""
if ws_download() is True:
return HttpResponseForbidden()
upload = Upload.objects.uploaded().get(hash=hash, name=filename)
upload = Upload.objects.uploaded().get(hash=hash, name=get_valid_filename(filename))

resp = FileResponse(upload.file, content_type=upload.type, filename=filename)
resp = FileResponse(upload.file, content_type=upload.type, filename=get_valid_filename(filename))
resp['Content-Length'] = upload.file.size
return resp

def put(self, request, hash, filename):
try:
upload = Upload.objects.for_upload().get(hash=hash, name=filename)
# some clients doublequote
upload = Upload.objects.for_upload().get(hash=hash, name=get_valid_filename(unquote(filename)))
except Upload.DoesNotExist:
return HttpResponseForbidden()
content_type = request.META.get('CONTENT_TYPE', 'application/octet-stream')
Expand Down