I already tried these solutions
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
But still, Checkmarx scanning giving a security issue, below is the code
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");
}
The issue is on this line of code image = System.IO.File.ReadAllBytes(filePath);
Please let me known how to solve this security issue.
Thanks in advance.