0
이미지를 업로드하고 디렉터리에 저장하는 C# 응용 프로그램이 있습니다. 업로드하기 전에 한 이미지 형식을 허용하도록 파일을 검사하고 있습니다. 내가 베라 코드 내 모듈을 테스트입니다 때 디렉토리 탐색 문제 CWE ID 73을 보여줍니다 .. 나는디렉터리 통과 문제 C#
을 업로드하기 전에 파일 형식을 확인하고 있기 때문에 올바른 경우 확실하지 않다파일을 업로드 내 코드
if (filebigimage.HasFile)
{
if ((((((this.filebigimage.PostedFile.ContentType == "image/gif") | (this.filebigimage.PostedFile.ContentType == "image/pjpeg")) | (this.filebigimage.PostedFile.ContentType == "image/jpeg")) | (this.filebigimage.PostedFile.ContentType == "image/jpg")) | (this.filebigimage.PostedFile.ContentType == "image/png")) | (this.filebigimage.PostedFile.ContentType == "image/bmp"))
{
// string StrBigImageName = (ConfigurationManager.AppSettings["offerImagePath"] + "BigImages/Temp/");
if ((this.filebigimage.PostedFile.ContentType == "image/gif"))
{
strBigimgformat = ".gif";
objBigImgFormat = System.Drawing.Imaging.ImageFormat.Gif;
}
else if ((this.filebigimage.PostedFile.ContentType == "image/pjpeg") | (this.filebigimage.PostedFile.ContentType == "image/jpeg") | (this.filebigimage.PostedFile.ContentType == "image/jpg"))
{
strBigimgformat = ".jpg";
objBigImgFormat = System.Drawing.Imaging.ImageFormat.Jpeg;
}
else if ((this.filebigimage.PostedFile.ContentType == "image/png"))
{
strBigimgformat = ".png";
objBigImgFormat = System.Drawing.Imaging.ImageFormat.Png;
}
filebigimage.SaveAs(Server.MapPath(ConfigurationManager.AppSettings["offerImagePath"] + "BigImages/Temp/") + filebigimage.FileName);
strbigimagename = filebigimage.FileName;
}
}
이하
그럼 난
if (File.Exists(Server.MapPath(ConfigurationManager.AppSettings["offerImagePath"]
+ "BigImages/Temp/" + strbigimagename)))
{
File.Move(Server.MapPath("../" + ConfigurationManager.AppSettings["offerImagePath"] + "BigImages/Temp/"
+ strbigimagename), Server.MapPath("../" + ConfigurationManager.AppSettings["offerImagePath"] + "BigImages/" + strorderid + "_bigimage" + strBigimgformat));
}
가 뭐죠 그것을 잘못 알려 주시기 바랍니다 데이터베이스에 값을 저장하고 행의 ID 번호를 얻고 파일 이름을 생성하고 기본 폴더에 임시에서이 파일을 이동하고 ... 그것은 디렉토리 트래버 설 I에 취약한가요? ssue
내가 살균 기능을 사용하고 현재 –
개인 정적 MakeValidFileName 문자열 (캐릭터 명) { 문자열 invalidChars = Regex.Escape (새로운 캐릭터 (Path.GetInvalidFileNameChars())); string invalidReStr = string.Format (@ "[{0}] +", invalidChars); return Regex.Replace (name, invalidReStr, "_"); } ......... 문제 해결에 도움이 되겠습니까? –
입력을 삭제해도 충돌 문제가 발생할 수 있습니다 (예 : 다른 사용자가 동일한 파일 이름 사용). 대신 서버에 파일을 저장하기 위해 데이터베이스 행 ID 또는 GUID를 사용할 수 있습니다. 필요한 경우 사용자가 원래 파일 이름을 복구 할 수 있도록 데이터베이스의 다른 위치에 사용자의 원래 파일 이름을 저장하십시오. – RogerN