Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FtpClient throws exception from log masking when Credentials.UserName is empty #1649

Closed
ssg opened this issue Sep 22, 2024 · 0 comments
Closed
Labels
bug Merged to master ...but not yet released to Nuget

Comments

@ssg
Copy link
Contributor

ssg commented Sep 22, 2024

FluentFTP Version: 51.1.0
Framework: Happens on both .NET Framework 4.8 and .NET 8.0

Summary

LogMaskModule tries to replace UserName instances with a fixed mask string, but if UserName is empty, then String.Replace throws an exception saying "System.ArgumentException: 'The value cannot be an empty string. (Parameter 'oldValue')'".

Applicability

FTP spec (RFC 959) doesn't allow an empty username, but there's nothing that prevents an FTP client from sending an empty USER command, and the server from accepting it.

Ideally, LogMaskModule should check for empty UserName and skip processing. FtpClient should reject an empty UserName directly in the constructor preferably with a manual override for exotic use cases.

Workarounds

  • Enable LogUserName = true in configuration (which isn't ideal)

Repro:

Here's a simple test program. Removing NetworkCredential parameter fixes this issue:

using System.Net;
using FluentFTP;

namespace FtpTest
{
    internal class Program
    {
        static async Task Main(string[] args)
        {
            string path = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
            Directory.CreateDirectory(path);
            Console.WriteLine($"Server path: {path}");
            var server = new Zhaobang.FtpServer.FtpServer(new IPEndPoint(IPAddress.Loopback, 4444), path);
            var cancelTokenSource = new CancellationTokenSource();
            var cancelToken = cancelTokenSource.Token;
            var task = Task.Run(() => server.RunAsync(cancelToken));

            var client = new AsyncFtpClient("127.0.0.1", new NetworkCredential()
            {
                UserName = "",
                Password = "",
            },4444, new FtpConfig()
            {
                LogToConsole = true,                
            });
            if (!await client.DirectoryExists("test/mest"))
            {
                await client.CreateDirectory("test/mest", force: true);
            }
            await client.UploadFile("D:\\test.txt", "test/test.txt");
            Console.WriteLine("DONE! ");
            cancelTokenSource.Cancel();
            Console.WriteLine("CANCELLED TOO! ");
            await task;
        }
    }
}
FanDjango added a commit that referenced this issue Sep 23, 2024
fix LogMaskModule throwing exception when UserName is empty (fixes #1649)
@FanDjango FanDjango added Merged to master ...but not yet released to Nuget and removed work in progress labels Sep 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Merged to master ...but not yet released to Nuget
Projects
None yet
Development

No branches or pull requests

2 participants