
vS116732 (Community Member) asked a question.
Veracode Static Analysis report flaw with CWE 918 when it detect data from outside of the application. Here is my code spinet
protected virtual void RetrieveFile(string filePath) {
string downloadURL = ConfigurationManager.AppSettings["FileDownloadURL"];
HttpWebResponse response = null;
System.IO.Stream dataStream = null;
try {
System.Net.WebRequest request = System.Net.WebRequest.Create(downloadURL + "?FilePath=" + Server.UrlEncode(filePath));
response = (HttpWebResponse)request.GetResponse();
dataStream = response.GetResponseStream();
Response.ClearHeaders();
Response.ClearContent();
Response.Flush();
Response.End();
}
catch (System.Threading.ThreadAbortException ex) { }
catch (Exception ex) {
WSApplication.Application.Report(CommonMessages.ErrorWhileDownload, ex.ToString(), "RetrieveFile");
throw ex;
}
finally {
if (dataStream != null)
dataStream.Close();
if (response != null)
response.Close();
}
}
.png)
Hi @vS116732 (Community Member) ,
For more information on this flaw category please see the answer in this post: https://community.veracode.com/s/question/0D52T00004i1UiSSAU/how-to-fix-cwe-918-veracode-flaw-on-webrequest-getresponce-method .
Looking at the provided code snippet if you are unable to change filePath to be hardcoded you should propose a mitigation by design ( https://help.veracode.com/reader/DGHxSJy3Gn3gtuSIN2jkRQ/~p4MSKOS8F8X8h0KwFTKoQ ) and have this reviewed by your security team.
Thank you,
Boy Baukema