【问题标题】:Fortify Cross Site Scripting in File在文件中强化跨站点脚本
【发布时间】:2015-02-26 21:46:39
【问题描述】:

我在控制器中有以下代码。 参数 base64String、fileName 是从浏览器发送的。

var fileContent = Convert.FromBase64String(base64String);
return File(fileContent, contentType, fileName);

如何解决此处的 XSS 威胁?

以上代码基于此处推荐的修复程序 Kendo UI Grid Export to Excel / PDF not working on IE9

【问题讨论】:

    标签: security model-view-controller xss fortify


    【解决方案1】:

    我假设您没有将 HTML 返回给您的用户(您返回的是 PDF 或 Excel 文件,或其他供浏览器下载而不是呈现的内容)。

    一般准则如下:

    • 设置正确的Content-Type标头。

    • 设置以下响应标头:X-Content-Type-Options: nosniffInternet Explorer will try and auto detect the content type 之类的浏览器并忽略你刚刚设置的那个。

    • 设置Content-Disposition 标头以便浏览器下载文件而不是显示它:Content-Disposition: attachment; filename="bar.pdf"

    按照上述操作应确保文件中包含的任何脚本代码都不会被您的浏览器执行。请注意IE (again!) can sometimes process script in XML files,因此您应该对此进行测试。

    【讨论】:

      猜你喜欢
      • 2013-01-30
      • 2020-12-26
      • 2014-01-27
      • 2011-02-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-13
      • 1970-01-01
      相关资源
      最近更新 更多