0

当我们在 fortify 安全修复扫描工具中扫描代码时。我们收到以下有关路径操纵攻击的消息“攻击者能够控制 FileInfo() 的文件系统路径参数,这允许他们访问或修改受保护的文件。允许用户输入控制文件系统操作中使用的路径可以启用攻击者访问或修改其他受保护的系统资源。”

[RoutePrefix("api/v1/file")]
public class FileController: ApiController
{
    [Route("pdf")]
    public IHttpActionResult GetPdf(string path = "")
{ 
            var fileInfo  = new FileInfo(path);

            if (fileInfo.Extension == ".pdf")
            {
                using (FileStream fs = File.OpenRead(path))
                {
                    response.Content = new StreamContent(fs);
                    response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
                }
            }
            return ResponseMessage(response);
}

}

有什么方法可以解决上述问题。?

4

0 回答 0