简体   繁体   English

文件下载-JavaScript中存储的XSS漏洞

[英]File download - stored XSS vulnerability in JavaScript

I have 3 types of files (XML, PDF, zip) that are stored in my server files and being send to user (client side) in base64 format by request (when the client clicks a button). 我有3种类型的文件(XML,PDF,zip)存储在服务器文件中,并通过请求(当客户端单击按钮时)以base64格式发送给用户(客户端)。
The files are download to users computer and not being displayed (on HTML page). 这些文件将下载到用户计算机,并且不会显示(在HTML页面上)。

I made a security test with Checkmarx service and received security issue: 我使用Checkmarx服务进行了安全测试,并收到了安全问题:
"Method function at line 58 of MyFile.js gets data from the database, for the readFileSync element. This element's value then flows through the code without being properly filtered or encoded and is eventually displayed to the user in method function at line 58 of MyFile.js . This may enable a Stored Cross-Site-Scripting attack (XSS).". MyFile.js的第58行的方法函数从数据库获取readFileSync元素的数据。然后,该元素的值流经代码,而没有经过适当的过滤或编码,最终在MyFile的第58行的方法函数中向用户显示。 .js 。这可能会启用存储的跨站点脚本攻击(XSS)。”。

The code on my server side is: 我服务器端的代码是:

var fs = require('fs');

downloadFile: function (req, res) {
  var params = req.allParams();
  var contents = fs.readFileSync(FilePathInTheProject).toString('base64');
  res.send(contents);
},

I don't understand how server stored files that are not accessible from client side can enable a Stored Cross-Site-Scripting attack (XSS) ? 我不了解无法从客户端访问的服务器存储文件如何启用存储的跨站点脚本攻击(XSS)?

How can i verify the vulnerability existence ? 我如何验证漏洞的存在?

And what is the right way to solve this security issue ? 解决此安全问题的正确方法是什么?

Checkmarx consider you take any contents from a source without any validation. Checkmarx认为您未经任何验证即从源中获取任何内容。 So the data is not tainted for it and if you sent it to a client this could got to XSS. 因此,数据不会因此受到污染,如果您将其发送给客户端,则可以转到XSS。

This is right if we have the view without your explaination. 如果我们的观点没有您的解释,这是正确的。

@Cilian Collins explaination is right. @Cilian Collins的解释是正确的。 With this, you could just mark the issue as 'Not Exploitable' and next scan, this will be not show to you. 这样,您可以将问题标记为“不可利用”,然后进行下一次扫描,这将不会显示给您。 Or If you have more time, you could extend the Cx rule to do it :) 或者,如果您有更多时间,可以扩展Cx规则来完成它:)

You have to check who have access to the files stored on the file system. 您必须检查谁有权访问存储在文件系统上的文件。 Are the files trustworthy? 文件值得信赖吗? How did you prevent the access to these files? 您如何阻止对这些文件的访问? Can they be modified (script injection)? 可以修改它们(脚本注入)吗? The DB or files on the file system should not be treated as source of trust worthy data by default. 默认情况下,不应将文件系统上的数据库或文件视为值得信任的数据源。 All data returned to the user should be validated. 返回给用户的所有数据都应进行验证。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM