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
This question is pretty old but since karma is suppose to go around, I would like to show you how I solved this problem.
I tend to take advantage of the ESAPI api. The veracode scanner seems to look for assignments to "sanitized" values that are deemed safe. Check the ESAPI library here https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&cad=rja&uact=8&ved=0CCcQFjABahUKEwiCv-PvuIXGAhWNL4gKHYUBDmA&url=http%3A%2F%2Fcode.google.com%2Fp%2Fowasp-esapi-java%2Fdownloads%2Flist&ei=FFh4VYLlBo3foASFg7iABg&usg=AFQjCNGT7pjqMzlKl2yM1K_uM7GFwwYiDA&sig2=rK3zE8o2znde3bf66Q8Q_w . While there are utility methods, I always find myself falling back on the getValidInput method because it is low level enough to sanitize and flexible enough to plugin to existing funcitonality.
Here's what that would look like:
You can check the doc for the complete specification of the API.
This pattern seems to work well with most of the problems I've come across not only for CWE-73 but others as well.