-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1301 from yogeshojha/1202-bug-risk-of-leaking-the…
…-scan-result-files (Security) Fixes #1202 bug risk of leaking the scan result files
- Loading branch information
Showing
4 changed files
with
35 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import os | ||
import mimetypes | ||
from django.contrib.auth.decorators import login_required | ||
from django.http import HttpResponse, Http404 | ||
from django.conf import settings | ||
|
||
@login_required | ||
def serve_protected_media(request, path): | ||
file_path = os.path.join(settings.MEDIA_ROOT, path) | ||
if os.path.isdir(file_path): | ||
raise Http404("File not found") | ||
if os.path.exists(file_path): | ||
content_type, _ = mimetypes.guess_type(file_path) | ||
response = HttpResponse() | ||
# response['Content-Disposition'] = f'attachment; filename={os.path.basename(file_path)}' | ||
response['Content-Type'] = content_type | ||
response['X-Accel-Redirect'] = f'/protected_media/{path}' | ||
return response | ||
else: | ||
raise Http404("File not found") | ||
|