所以这是设置:
我有一个带有 Flask-WTF 的简单 Flask 应用。
用户提交了一个带有一个文本字段的表单 - filename。
表单有一个 CSRF token (来自 Flask-WTF。)
如果用户提交表单并进行验证,则浏览器会下载一个自动生成的文件(即不是来自服务器文件系统的文件)以及提交的文件名。
重要的代码是:
response.headers['Content-Disposition'] = 'attachment; filename={0}.lsc'.format(filename)
这有多安全?
换句话说,如果恶意用户可以在 Content-Disposition header 中插入任意文本,他们可能会做什么?
请您参考如下方法:
他们将无法对服务器做任何事情,如果他们实现RFC 2616,在客户端应该是安全的。正确地:
The receiving user agent SHOULD NOT respect any directory path information present in the filename-parm parameter, which is the only parameter believed to apply to HTTP implementations at this time. The filename SHOULD be treated as a terminal component only.
但是,要全面考虑此问题,请参阅 RFC 2183: Communicating Presentation Information in Internet Messages: The Content-Disposition Header Field ,特别是安全注意事项部分。 (RFC 2183 适用于邮件消息,但同样适用于 HTTP 用户代理。)
