FreeAndNil commented on PR #355: URL: https://github.com/apache/logging-log4net/pull/355#issuecomment-6962889624
Implementation plan for #355, kept here for the record. Written up to describe the change as it stands on the branch. <details> <summary>Plan</summary> # Fixes from the 2026-11 audit, part 1 ## Context An automated scan of log4net (Anthropic OSS Scanner, November 2026) reported findings in the XML layout, the file, UDP, mail, trace, debug, ADO.NET, Telnet, local syslog and pickup directory appenders, and `%aspnet-request`. This PR fixes twelve of them, one public issue each (#343 to #354). Three are vulnerabilities, fixed with [CVE-2026-129510](https://www.cve.org/CVERecord?id=CVE-2026-129510) (#350), [CVE-2026-129511](https://www.cve.org/CVERecord?id=CVE-2026-129511) (#351) and [CVE-2026-129512](https://www.cve.org/CVERecord?id=CVE-2026-129512) (#346); the rest are bugs or hardening. The rule behind every fix: configuration is trusted, log content is not. Content is escaped, never rejected, and an event is never lost to its content. Decisions taken with the maintainer: one PR, one commit per issue; released as 3.6.0, since `MaxRecordSize` and `MaxBodySize` are new public API; the finding ids appear in commit messages and changelog entries. ## Constraints that shape the design - `ContentEscape` (internal) holds every escape. `log4net.Ext.Mail` compiles it in with `<Compile Include>`, since the strong-named core does not expose it. - Escapes use the `\0`, `\r`, `\uXXXX` forms already used by `EventLogAppender` and `OutputDebugStringAppender`. - Escaping belongs to the sink, with one exception: lone surrogates are escaped centrally in `AppenderSkeleton`, for every appender, third-party ones included. `AGENTS.md` and the threat model say so, or the next scan puts sink-by-sink calls back. NUL stays per sink. - Escapes can lengthen the text, so every size cut comes after the escape and keeps characters and surrogate pairs whole. - `CountingQuietTextWriter` counts per write call, so a wrapper must not split one write into two, or rolling sizes drift. - `BeginAccept` runs its callback inline when a connection is already waiting. - glibc's `syslog(3)` drops a datagram over the socket send buffer minus 32 bytes (212960 with the default `net.core.wmem_default`) and reports nothing. - MailKit writes a CR without LF raw into a 7bit or 8bit body; Sendmail refuses such a mail with `421 4.5.0 Bare carriage return`. System.Net.Mail (core `SmtpAppender`) already sends base64 or quoted-printable. - Reading `Request.Form` before the application has read the body waits for the client, inside the appender lock. ## Changes 1. #350 `Transform.WriteEscapedXmlString`: `StringComparison.Ordinal` on both `IndexOf` calls for the CDATA end marker. Culture-sensitive search skipped ignorable characters between `]]` and `>`, and a later event could disappear inside the CDATA section. 2. #351 `ContentEscape`: a clone of the configured encoding with an escaping `EncoderFallback` (`\uXXXX`), applied at all four hand-offs: `FileAppender.SetQWForFiles`, `UdpAppender` (built in the `Encoding` setter, escapes count against `MaxDatagramSize`), core `SmtpAppender` (escapes the string, keeps the configured `BodyEncoding`), Ext.Mail `SmtpAppender`. Best-fit substitutes such as U+FF1C to `<` can no longer forge XML. `RemoteSyslogAppender` stays as it was, with a test. 3. #344 `ContentEscape` as C# 14 extension members, analyzers 10.0.114. 4. #343 `TraceAppender` and `DebugAppender` escape NUL as `\0` in message and category: the default listener ends in a native call that stops at the first NUL. 5. #346 `AdoNetAppenderParameter.FormatValue`, string values only: escape NUL, then lone surrogates, then cut to `Size` when `Size > 0` without splitting a pair. `Size = -1` stays untouched. A database that stores U+0000 now receives `\0`. The legacy path without `CommandText` is out. 6. #345 `SendBufferPerEvent` gives up after five failures in a row only while the database has not accepted an insert since activation. Accepted gaps, documented: five rejected events as the very first inserts still lose the batch; a database that fails later costs one round trip per event. 7. #344 `AppenderSkeleton.RenderLoggingEvent`: a per-event `TextWriter` wrapper that escapes lone surrogates in `Write(char)`, `Write(string)` and `Write(char[], int, int)`, holds a trailing high surrogate until the next write or the end of the event, is never disposed, and forwards clean text whole. The string overload goes through it. Categories of Trace, Debug and AspNetTrace too. The `%.N` width cut keeps pairs whole. Trace and Debug report a failed flush through `ErrorHandler` and return `false`. The now redundant calls in `TelnetAppender` and `SmtpPickupDirAppender` go. 8. #348 `ContentEscape.TruncateToBytes`, moved out of `UdpAppender`: cuts by bytes without splitting a character or pair, marker included in the budget, returns the kept text and its byte count. `UdpAppender.Encoding` docs name both defaults (ANSI code page on .NET Framework, UTF-8 on .NET); the broken VB.NET receiver sample is removed, the C# one sets the encoding. 9. #347 `TelnetAppender.SocketHandler`: accepts through `Task.Factory.FromAsync(...).ContinueWith(...)` as before 3.0.0, so each callback runs on a fresh stack. A failed accept is logged and retried after 100 ms through `Task.Delay`; a socket accepted after `Dispose` is closed. 10. #348 `LocalSyslogAppender.MaxRecordSize`, UTF-8 bytes, default 204800, at least 512: cut before `EscapePercent`, per line in `Split` mode, each cut reported. The records are computed by a private method, tested by reflection; the native call is the one untested line. 11. #349 `MaxBodySize` on both `SmtpAppender`s, bytes of the body encoding, default 1 MiB, at least 4096: a batch over it goes out as several mails, header and footer in each, each sent on its own. An oversized record is cut; header and footer without room are reported at activation. One enqueue deadline per batch. 12. #352 Ext.Mail sets the transfer encoding by `BodyEncoding`: quoted-printable, base64 for UTF-16 and UTF-32. A bare CR goes out as `=0D`. The body can be up to three times larger on the wire. 13. #353 `SmtpPickupDirAppender` renders each event to a string and escapes a CR not followed by LF as `\r`; CRLF and lone LF stay. Header and footer are configuration and stay as they are. 14. #354 `%aspnet-request` by `ReadEntityBodyMode`: `Classic` takes the form, `Buffered` tries it, `None` and `Bufferless` leave it out, so query string, cookies and server variables still render instead of `NOT AVAILABLE`. The keyed form looks up query string, form, cookies, server variables. A form field logged before the application reads the body is no longer shown. Docs: the trace, ADO.NET, local syslog, UDP, SMTP, console and appenders overview pages, the Ext.Mail README, `layouts.adoc` and the affected XML doc comments. One changelog entry per issue in `src/changelog/3.6.0`, two for #344. ## Sequencing 1. #350 and #351 first, the two vulnerabilities in the default write paths. 2. #344 refactoring, then #343, #346, #345 (its PostgreSQL rerun needs #346), #344. 3. #348 helper, #347, #348, #349. 4. #352, #353, #354. 5. Each commit: test against the unfixed code first, fix, mutate each changed line, review loop. 6. Commits and pushes are the maintainer's. ## Verification - `dotnet build` of all targets with 0 warnings, tests on net10 and, on the Windows job, net462. - The scanner's reproducers in a container before and after each fix. - .NET Framework encoding behaviour measured on Windows (code page 1252): default file and UDP encodings, best-fit bytes, the forged event, the CDATA cases on en-US and th-TH threads. - PostgreSQL through Npgsql for #346 and #345: NUL, lone surrogate, cut inside a pair, all stored. - A Sendmail container for #352 and #353: the bare CR mail is accepted after the fix. - Telnet: nesting depth exactly 1, deterministic. - `%aspnet-request`: a `SimpleWorkerRequest` fake for all four body modes, net462 only. </details> -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
