fix(net): cap the length of a server line

A hostile server could stream an endless line with no newline and exhaust
the client's memory. A single reply is now capped at 16 MiB (configurable
via maxLineBytes in ConnectAsync); on excess the connection fails with
InvalidDataException. See ADR 0035.
This commit is contained in:
davide committed 2026-11-03 13:52:49 +01:00
1 parent 3be761d97e
commit 65c515bf7a
7 files changed
+121 -3

No files matched your search

@@ -79,6 +79,19 @@ public sealed class FakeElectrumServer : IAsyncDisposable
await WriteLineAsync(stream, writeLock, bytes);
}
/// <summary>Sends raw bytes with no trailing newline (an unterminated, still-growing line).</summary>
public async Task SendUnterminatedAsync(string text)
{
var bytes = System.Text.Encoding.UTF8.GetBytes(text);
foreach (var (stream, writeLock, _) in _clients)
{
await writeLock.WaitAsync();
try { await stream.WriteAsync(bytes); await stream.FlushAsync(); }
catch (Exception) { }
finally { writeLock.Release(); }
}
}
/// <summary>Abruptly closes every accepted connection (tests the client's failure paths).</summary>
public void DropClients()
{