Skip to content

Commit f70326c

Browse files
author
Sososlik
authored
Fix for browsers sending the complete file path
Some browsers sends the full user local path to the file being uploaded. So I fixed the example because will not work and is a security risk if the webapp has too much rights. IE case: https://msdn.microsoft.com/en-us/library/ms535128%28v=vs.85%29.aspx
1 parent 76c478e commit f70326c

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

c#/HomeController.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ public ActionResult UploadFile()
2626
string category = HttpContext.Request.Params["category"];
2727

2828
DirectoryInfo di = Directory.CreateDirectory(Server.MapPath("~/Tmp/Files"));// If you don't have the folder yet, you need to create.
29-
string savedFileName = Path.Combine(di.FullName, hpf.FileName);
29+
string sentFileName = Path.GetFileName(hpf.FileName); //it can be just a file name or a user local path! it depends on the used browser. So we need to ensure that this var will contain just the file name.
30+
string savedFileName = Path.Combine(di.FullName, sentFileName);
3031
hpf.SaveAs(savedFileName);
3132

3233
var msg = new { msg = "File Uploaded", filename = hpf.FileName, url= savedFileName };
@@ -64,4 +65,4 @@ public ActionResult DeleteFile(string url)
6465
}
6566
}
6667
}
67-
}
68+
}

0 commit comments

Comments
 (0)