2

我在我的 Django Web 应用程序中有这样的视图:

def download_func(request, url):
    file_url = '/home/mylaptop/myproject/' + url
    file = open (file_url, "rb").read()
    response = HttpResponse(file, content_type="application/octect-
stream")
    response['Content-Disposition'] = 'attachment; filename = %s' %url
    return response

和这样的 url conf:

urlpatterns = [
...
url(r'^media/videos/(?P<url>[-._\w]+)/$', views.download_func),
...
]

下载之前上传的视频是完美的工作,但我的问题是:“我的应用程序中是否存在目录遍历攻击的风险?”

如果“是”,我该如何修复它(或者是否有更好的方法来编写视图以在开发时下载?)

我一直在测试目录遍历,并了解 Django 会自动清理包含“../../”的 url,对吗?

谢谢

4

0 回答 0