Check the tmpimg path is in the expected folder

This commit is contained in:
Bjarke Berg
2023-03-14 08:27:17 +01:00
parent daff9884a3
commit 4e3ac66865

View File

@@ -74,6 +74,7 @@ public sealed class RichTextEditorPastedImages
// we have already processed to avoid dupes
var uploadedImages = new Dictionary<string, GuidUdi>();
foreach (HtmlNode? img in tmpImages)
{
// The data attribute contains the path to the tmp img to persist as a media item
@@ -84,6 +85,11 @@ public sealed class RichTextEditorPastedImages
continue;
}
if (IsValidPath(tmpImgPath) == false)
{
continue;
}
var absoluteTempImagePath = _hostingEnvironment.MapPathContentRoot(tmpImgPath);
var fileName = Path.GetFileName(absoluteTempImagePath);
var safeFileName = fileName.ToSafeFileName(_shortStringHelper);
@@ -184,4 +190,6 @@ public sealed class RichTextEditorPastedImages
return htmlDoc.DocumentNode.OuterHtml;
}
private bool IsValidPath(string imagePath) => imagePath.StartsWith(Constants.SystemDirectories.TempImageUploads);
}