asp.net core 中的路径遍历漏洞

问题描述

我已经尝试过这些解决方案

Does my code prevent directory traversal in C#?

Is Path Traversal Vulnerabilities possible in my below code?

How to prevent Path Traversal in .NET

How to avoid Directory Traversal in my code

但是,Checkmarx 扫描仍然存在安全问题,下面是代码

public FileContentResult GetImageFromFilePath(string filePath)
        {
            byte[] image = null;
            if (!string.IsNullOrEmpty(filePath))
            {
                image = System.IO.File.ReadAllBytes(filePath);
            }
            if (image == null)
                return null;
            return File(image,"image/jpeg");
        }

问题出在这行代码 image = System.IO.File.ReadAllBytes(filePath);

请告诉我如何解决这个安全问题。

提前致谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)