mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-02 19:11:10 +00:00
Fixes plugin upload path traversal on non-Windows platforms
This commit is contained in:
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()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user