Added explicit validation for '..' path segments

This commit is contained in:
Thorsten Sommer 2026-05-22 15:44:51 +02:00
parent 8cc24a27f7
commit 0fc78939b7
Signed by untrusted user who does not match committer: tsommer
GPG Key ID: 371BBA77A02C0108

View File

@ -220,6 +220,13 @@ public record ChatTemplate(
var relativePath = filePath var relativePath = filePath
.Replace('/', Path.DirectorySeparatorChar) .Replace('/', Path.DirectorySeparatorChar)
.Replace('\\', Path.DirectorySeparatorChar); .Replace('\\', Path.DirectorySeparatorChar);
if (relativePath.Split(Path.DirectorySeparatorChar, StringSplitOptions.RemoveEmptyEntries).Any(segment => segment == ".."))
{
LOGGER.LogWarning("The relative FileAttachments entry {AttachmentNum} in chat template {IdxChatTemplate} contains '..' path segments and will be ignored.", attachmentNum, idx);
return false;
}
var combinedPath = Path.GetFullPath(Path.Combine(pluginRoot, relativePath)); var combinedPath = Path.GetFullPath(Path.Combine(pluginRoot, relativePath));
var pluginRootWithSeparator = pluginRoot.EndsWith(Path.DirectorySeparatorChar) var pluginRootWithSeparator = pluginRoot.EndsWith(Path.DirectorySeparatorChar)
? pluginRoot ? pluginRoot