Am having a image Gallery and am rendering the image in following ways
<a href="/Gallery/GetImage?Name=sample.jpg>Imagename</a> //user clicks hyperlink to download file
<img src=""/Gallery/GetImage?Name=sample.jpg"> //Displaying the image
and my GetImage() function is below where i will get the image and return it.
public ActionResult GetImage(string Name)
{
..
...
return File(FilePath, Type, Name); //Filepath - server folder where image located
//Name is File name
}
Is this a security Violation. The Error is shown at the Line where am returning the File.
Is there a better way i can handle this ?
How can i avoid this violation ?
Any suggestions are much appreciated
Thanks
Independent from the "security violation" passing file name trough query strings isn't a good practice. It might allow to file inclusion attacks allowing attackers to view source code of your application or disclose internal information such as 'etc/passwd' file in a Linux environment.
Even if you hardcode the filepath and type, this are protections that might be bypassed.
For more information on "External Control of File Name or Path possible" check out: http://cwe.mitre.org/data/definitions/73.html
Regarding your security violation, in what specific context is that error being trowed?