From 82fd409ab53bb61faaf44cd705e36491e44d1e85 Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Thu, 9 Apr 2026 09:31:37 +1000 Subject: [PATCH] Detect and drop all-zero trace/span/parent ids --- src/SeqCli/Apps/Hosting/AppContainer.cs | 12 ++++++------ test/SeqCli.Tests/Apps/AppContainerTests.cs | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/SeqCli/Apps/Hosting/AppContainer.cs b/src/SeqCli/Apps/Hosting/AppContainer.cs index 4b233f1..2f52c58 100644 --- a/src/SeqCli/Apps/Hosting/AppContainer.cs +++ b/src/SeqCli/Apps/Hosting/AppContainer.cs @@ -15,6 +15,7 @@ using System; using System.Globalization; using System.IO; +using System.Linq; using System.Text.RegularExpressions; using System.Threading.Tasks; using Newtonsoft.Json; @@ -35,7 +36,7 @@ partial class AppContainer : IAppHost, IDisposable readonly SeqApp _seqApp; readonly AppLoader _loader; - static readonly Regex HexDigits = HexDigitsRegex(); + static readonly Regex NonZeroHex = NonZeroHexRegex(); readonly JsonSerializer _serializer = JsonSerializer.Create(new JsonSerializerSettings { @@ -183,7 +184,7 @@ static bool IsValidHexIdentifier(JToken? value, int requiredChars) if (value?.Value() is not { } id) return false; - return id.Length == requiredChars && HexDigits.IsMatch(id); + return id.Length == requiredChars && NonZeroHex.IsMatch(id); } public void StartPublishing(TextWriter inputWriter) @@ -198,7 +199,6 @@ public void StopPublishing() pjson.Stop(); } - // Technically, - [GeneratedRegex("^[0-9a-f]*$")] - private static partial Regex HexDigitsRegex(); -} \ No newline at end of file + [GeneratedRegex("^0*[1-9a-f][0-9a-f]*$")] + private static partial Regex NonZeroHexRegex(); +} diff --git a/test/SeqCli.Tests/Apps/AppContainerTests.cs b/test/SeqCli.Tests/Apps/AppContainerTests.cs index c316884..e9cfdec 100644 --- a/test/SeqCli.Tests/Apps/AppContainerTests.cs +++ b/test/SeqCli.Tests/Apps/AppContainerTests.cs @@ -67,6 +67,20 @@ public void RemovesShortTraceAndSpanIds() Assert.Empty(jo); } + [Fact] + public void RemovesZeroTraceAndSpanIds() + { + var jo = new JObject + { + ["@tr"] = "00000000000000000000000000000000", + ["@sp"] = "0000000000000000", + ["@ps"] = "0000000000000000" + }; + Assert.NotEmpty(jo); + AppContainer.SanitizeTraceIdentifiers(jo); + Assert.Empty(jo); + } + [Fact] public void PreservesValidTraceAndSpanIds() {