我收到了来自 Brakeman 的警告。正如他们所说,依赖于用户提供的值的重定向可用于“欺骗”网站或将恶意链接隐藏在看起来无害的 URL 中。如果目的地未经验证,他们还可以允许访问站点的受限区域。
| Confidence | Class | Method | Warning Type | Message
| High | DocumentsController | download | Redirect | Possible unprotected redirect near line 46: redirect_to(+Document.find(params[:id]).f
在我的控制器中,我创建了一个方法,该方法download
获取文件 URL(存储在 Amazon S3 上的文件和我的数据库中的 URL,感谢 Paperclip)并创建一个document_url
持续 3 秒(供用户下载)的 URL(即 ),这要归功于.expiring_url(3)
def download
@document = Document.find(params[:id])
document_url = @document.file.expiring_url(3)
if URI.parse(document_url).host.include? "domain.com"
redirect_to document_url, only_path: true
else
document_url = nil
end
end
我一直在尝试通过 Brakeman 的验证,但没有成功。正如您在上面看到的,我尝试检查我的域是否存在于 URL 中,但它没有更改有关 Brakeman 的报告。
知道如何进行吗?