Fixes plugin upload path traversal on non-Windows platforms

This commit is contained in:
BinaryAlley committed 2026-08-23 08:31:47 -07:00
1 parent b3ffb5dfab
commit 862c76c00b
2 files changed
+61 -9

No files matched your search

@@ -72,6 +72,40 @@ public class PluginInstallerTests : IDisposable
Assert.False(File.Exists(Path.Combine(_pluginsDirectory, "readme.txt")));
}
[Fact]
public async Task InstallAsync_WhenUploadingZipWithBackslashTraversalEntry_ShouldFlattenItInsidePluginsDirectory()
{
// Arrange
await using MemoryStream zipStream = new();
// a backslash is not a directory separator on non-Windows platforms, so it must be neutralized explicitly
CreateZipArchive(zipStream, [(@"..\evil.dll", ReadTestAssembly())]);
zipStream.Position = 0;
// Act
Result<Success> result = await _sut.InstallAsync(zipStream, "plugin.zip", CancellationToken.None);
// Assert
Assert.False(result.IsFailure);
Assert.True(File.Exists(Path.Combine(_pluginsDirectory, "evil.dll")));
Assert.False(File.Exists(Path.Combine(AppContext.BaseDirectory, "evil.dll")));
}
[Fact]
public async Task InstallAsync_WhenUploadingSingleAssemblyWithTraversalFileName_ShouldFlattenItInsidePluginsDirectory()
{
// Arrange
const string TRAVERSAL_FILE_NAME = "traversal-test-plugin.dll";
await using FileStream stream = File.OpenRead(Path.Combine(AppContext.BaseDirectory, "Lumina.TestPlugin.dll"));
// Act
Result<Success> result = await _sut.InstallAsync(stream, $@"..\{TRAVERSAL_FILE_NAME}", CancellationToken.None);
// Assert
Assert.False(result.IsFailure);
Assert.True(File.Exists(Path.Combine(_pluginsDirectory, TRAVERSAL_FILE_NAME)));
Assert.False(File.Exists(Path.Combine(AppContext.BaseDirectory, TRAVERSAL_FILE_NAME)));
}
[Fact]
public async Task InstallAsync_WhenUploadingUnsupportedFileType_ShouldReturnError()
{