From 846bf9129e932624ccc928df228ad8b29bc841f4 Mon Sep 17 00:00:00 2001 From: Evan Sosenko Date: Tue, 17 Nov 2026 13:24:33 -0800 Subject: [PATCH 1/3] feat: read webhook secret from SEAM_WEBHOOK_SECRET when omitted --- README.md | 8 +++- src/Seam/SeamWebhook.cs | 20 ++++++-- test/Seam.Test/SeamWebhookTests.cs | 76 ++++++++++++++++++++++++++++++ test/Seam.Test/Support/EnvGuard.cs | 1 + 4 files changed, 101 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d82cb515..800c197a 100644 --- a/README.md +++ b/README.md @@ -253,7 +253,7 @@ await seam.Devices.UpdateAsync(new() Verify and parse incoming Seam webhook events with `SeamWebhook`: ```csharp -var webhook = new SeamWebhook(Environment.GetEnvironmentVariable("SEAM_WEBHOOK_SECRET")!); +var webhook = new SeamWebhook(); // Reads SEAM_WEBHOOK_SECRET. var seamEvent = webhook.Verify(requestBody, requestHeaders); @@ -261,6 +261,12 @@ if (seamEvent is Seam.Models.EventDeviceConnected connected) Console.WriteLine(connected.DeviceId); ``` +Omitting the secret (or passing `null`) reads `SEAM_WEBHOOK_SECRET` when +the helper is constructed. Pass `new SeamWebhook("whsec_...")` to override +the environment. A missing or empty secret raises `InvalidOperationException` +at construction; an explicit empty string never falls back to the environment. +Svix also rejects secrets that decode to an empty signing key. + Verification failures raise Svix's `WebhookVerificationException`: treat the payload as forged and respond with an error status so Svix retries. A payload that is correctly signed but unreadable raises a diff --git a/src/Seam/SeamWebhook.cs b/src/Seam/SeamWebhook.cs index 5430aaab..15cea059 100644 --- a/src/Seam/SeamWebhook.cs +++ b/src/Seam/SeamWebhook.cs @@ -12,7 +12,7 @@ namespace Seam /// by the API. Verification failures raise /// . /// - /// var webhook = new SeamWebhook(Environment.GetEnvironmentVariable("SEAM_WEBHOOK_SECRET")!); + /// var webhook = new SeamWebhook(); // Reads SEAM_WEBHOOK_SECRET. /// var seamEvent = webhook.Verify(requestBody, requestHeaders); /// /// @@ -20,9 +20,23 @@ public sealed class SeamWebhook { private readonly Svix.Webhook _webhook; - /// The webhook secret from the Seam Console. - public SeamWebhook(string secret) + /// + /// The webhook secret from the Seam Console. When omitted or null, reads + /// SEAM_WEBHOOK_SECRET at construction time. An explicit empty string never falls back. + /// + /// + /// When the secret is missing or empty. + /// + public SeamWebhook(string? secret = null) { + secret ??= Environment.GetEnvironmentVariable("SEAM_WEBHOOK_SECRET"); + if (string.IsNullOrEmpty(secret)) + { + throw new InvalidOperationException( + "Provide a webhook secret or set SEAM_WEBHOOK_SECRET to a non-empty value." + ); + } + _webhook = new Svix.Webhook(secret); } diff --git a/test/Seam.Test/SeamWebhookTests.cs b/test/Seam.Test/SeamWebhookTests.cs index 835b891d..0056628c 100644 --- a/test/Seam.Test/SeamWebhookTests.cs +++ b/test/Seam.Test/SeamWebhookTests.cs @@ -3,6 +3,7 @@ namespace Seam.Test; using System.Security.Cryptography; using System.Text; using System.Text.Json; +using Seam.Test.Support; using Svix.Exceptions; public class SeamWebhookTests @@ -36,6 +37,81 @@ private static Dictionary SignedHeaders( }; } + [Theory] + [InlineData(false)] + [InlineData(true)] + public void OmittedOrNullSecretReadsEnvironment(bool passNull) + { + using var env = new EnvGuard(); + env.Set("SEAM_WEBHOOK_SECRET", Secret); + + var webhook = passNull ? new SeamWebhook(null) : new SeamWebhook(); + var seamEvent = webhook.Verify(Payload, SignedHeaders(Payload)); + + Assert.Equal("device.connected", seamEvent.EventType); + } + + [Fact] + public void ExplicitSecretOverridesEnvironment() + { + using var env = new EnvGuard(); + env.Set("SEAM_WEBHOOK_SECRET", "whsec_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="); + + var seamEvent = new SeamWebhook(Secret).Verify(Payload, SignedHeaders(Payload)); + + Assert.Equal("device.connected", seamEvent.EventType); + } + + [Theory] + [InlineData(null)] + [InlineData("")] + public void MissingOrEmptyEnvironmentSecretIsRejected(string? secret) + { + using var env = new EnvGuard(); + if (secret is not null) + env.Set("SEAM_WEBHOOK_SECRET", secret); + + var exception = Assert.Throws(() => new SeamWebhook()); + Assert.Contains("SEAM_WEBHOOK_SECRET", exception.Message); + Assert.Throws(() => new SeamWebhook(null)); + } + + [Fact] + public void ExplicitEmptySecretDoesNotFallBackToEnvironment() + { + using var env = new EnvGuard(); + env.Set("SEAM_WEBHOOK_SECRET", Secret); + + Assert.Throws(() => new SeamWebhook("")); + } + + [Theory] + [InlineData("whsec_")] + [InlineData("whsec_ ")] + [InlineData(" ")] + public void EnvironmentSecretWithEmptyDecodedKeyIsRejected(string secret) + { + using var env = new EnvGuard(); + env.Set("SEAM_WEBHOOK_SECRET", secret); + + Assert.Throws(() => new SeamWebhook()); + } + + [Fact] + public void EachConstructionReadsCurrentEnvironment() + { + using var env = new EnvGuard(); + env.Set("SEAM_WEBHOOK_SECRET", Secret); + var first = new SeamWebhook(); + + env.Set("SEAM_WEBHOOK_SECRET", "whsec_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="); + var second = new SeamWebhook(); + var headers = SignedHeaders(Payload); + + Assert.Equal("device.connected", first.Verify(Payload, headers).EventType); + Assert.Throws(() => second.Verify(Payload, headers)); + } + [Fact] public void VerifyReturnsTheEvent() { diff --git a/test/Seam.Test/Support/EnvGuard.cs b/test/Seam.Test/Support/EnvGuard.cs index 34eca79c..436d6a30 100644 --- a/test/Seam.Test/Support/EnvGuard.cs +++ b/test/Seam.Test/Support/EnvGuard.cs @@ -12,6 +12,7 @@ public sealed class EnvGuard : IDisposable "SEAM_PERSONAL_ACCESS_TOKEN", "SEAM_WORKSPACE_ID", "SEAM_ENDPOINT", + "SEAM_WEBHOOK_SECRET", }; private readonly Dictionary _saved = new(); From db08122e29f3633895f7d50ba98d6be21a5d753c Mon Sep 17 00:00:00 2001 From: Evan Sosenko Date: Tue, 17 Nov 2026 13:43:57 -0800 Subject: [PATCH 2/3] no-mistakes(review): Reject explicit null webhook secrets --- .../.dotnet/10.0.400.aspNetCertificateSentinel | 0 .dotnet/.dotnet/10.0.400.dotnetFirstUseSentinel | 0 .dotnet/.dotnet/10.0.400.toolpath.sentinel | 0 README.md | 4 ++-- src/Seam/SeamWebhook.cs | 16 ++++++++++++---- test/Seam.Test/SeamWebhookTests.cs | 17 ++++++++--------- 6 files changed, 22 insertions(+), 15 deletions(-) create mode 100644 .dotnet/.dotnet/10.0.400.aspNetCertificateSentinel create mode 100644 .dotnet/.dotnet/10.0.400.dotnetFirstUseSentinel create mode 100644 .dotnet/.dotnet/10.0.400.toolpath.sentinel diff --git a/.dotnet/.dotnet/10.0.400.aspNetCertificateSentinel b/.dotnet/.dotnet/10.0.400.aspNetCertificateSentinel new file mode 100644 index 00000000..e69de29b diff --git a/.dotnet/.dotnet/10.0.400.dotnetFirstUseSentinel b/.dotnet/.dotnet/10.0.400.dotnetFirstUseSentinel new file mode 100644 index 00000000..e69de29b diff --git a/.dotnet/.dotnet/10.0.400.toolpath.sentinel b/.dotnet/.dotnet/10.0.400.toolpath.sentinel new file mode 100644 index 00000000..e69de29b diff --git a/README.md b/README.md index 800c197a..018cf391 100644 --- a/README.md +++ b/README.md @@ -261,10 +261,10 @@ if (seamEvent is Seam.Models.EventDeviceConnected connected) Console.WriteLine(connected.DeviceId); ``` -Omitting the secret (or passing `null`) reads `SEAM_WEBHOOK_SECRET` when +Omitting the secret reads `SEAM_WEBHOOK_SECRET` when the helper is constructed. Pass `new SeamWebhook("whsec_...")` to override the environment. A missing or empty secret raises `InvalidOperationException` -at construction; an explicit empty string never falls back to the environment. +at construction; explicit null or empty strings never fall back to the environment. Svix also rejects secrets that decode to an empty signing key. Verification failures raise Svix's `WebhookVerificationException`: treat the diff --git a/src/Seam/SeamWebhook.cs b/src/Seam/SeamWebhook.cs index 15cea059..a9aa88e8 100644 --- a/src/Seam/SeamWebhook.cs +++ b/src/Seam/SeamWebhook.cs @@ -20,16 +20,24 @@ public sealed class SeamWebhook { private readonly Svix.Webhook _webhook; + /// + /// Reads SEAM_WEBHOOK_SECRET at construction time. + /// + /// + /// When the environment secret is missing or empty. + /// + public SeamWebhook() + : this(Environment.GetEnvironmentVariable("SEAM_WEBHOOK_SECRET") ?? "") { } + /// - /// The webhook secret from the Seam Console. When omitted or null, reads - /// SEAM_WEBHOOK_SECRET at construction time. An explicit empty string never falls back. + /// The webhook secret from the Seam Console. Null and empty strings never fall back + /// to SEAM_WEBHOOK_SECRET. /// /// /// When the secret is missing or empty. /// - public SeamWebhook(string? secret = null) + public SeamWebhook(string secret) { - secret ??= Environment.GetEnvironmentVariable("SEAM_WEBHOOK_SECRET"); if (string.IsNullOrEmpty(secret)) { throw new InvalidOperationException( diff --git a/test/Seam.Test/SeamWebhookTests.cs b/test/Seam.Test/SeamWebhookTests.cs index 0056628c..73424b4c 100644 --- a/test/Seam.Test/SeamWebhookTests.cs +++ b/test/Seam.Test/SeamWebhookTests.cs @@ -37,15 +37,13 @@ private static Dictionary SignedHeaders( }; } - [Theory] - [InlineData(false)] - [InlineData(true)] - public void OmittedOrNullSecretReadsEnvironment(bool passNull) + [Fact] + public void OmittedSecretReadsEnvironment() { using var env = new EnvGuard(); env.Set("SEAM_WEBHOOK_SECRET", Secret); - var webhook = passNull ? new SeamWebhook(null) : new SeamWebhook(); + var webhook = new SeamWebhook(); var seamEvent = webhook.Verify(Payload, SignedHeaders(Payload)); Assert.Equal("device.connected", seamEvent.EventType); @@ -73,16 +71,17 @@ public void MissingOrEmptyEnvironmentSecretIsRejected(string? secret) var exception = Assert.Throws(() => new SeamWebhook()); Assert.Contains("SEAM_WEBHOOK_SECRET", exception.Message); - Assert.Throws(() => new SeamWebhook(null)); } - [Fact] - public void ExplicitEmptySecretDoesNotFallBackToEnvironment() + [Theory] + [InlineData(null)] + [InlineData("")] + public void ExplicitNullOrEmptySecretDoesNotFallBackToEnvironment(string? secret) { using var env = new EnvGuard(); env.Set("SEAM_WEBHOOK_SECRET", Secret); - Assert.Throws(() => new SeamWebhook("")); + Assert.Throws(() => new SeamWebhook(secret!)); } [Theory] From c5a99d33667d7f7c7d7e510c4458504ac85ad738 Mon Sep 17 00:00:00 2001 From: Evan Sosenko Date: Tue, 17 Nov 2026 13:46:33 -0800 Subject: [PATCH 3/3] no-mistakes(review): Remove accidental .NET first-run artifacts --- .dotnet/.dotnet/10.0.400.aspNetCertificateSentinel | 0 .dotnet/.dotnet/10.0.400.dotnetFirstUseSentinel | 0 .dotnet/.dotnet/10.0.400.toolpath.sentinel | 0 3 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .dotnet/.dotnet/10.0.400.aspNetCertificateSentinel delete mode 100644 .dotnet/.dotnet/10.0.400.dotnetFirstUseSentinel delete mode 100644 .dotnet/.dotnet/10.0.400.toolpath.sentinel diff --git a/.dotnet/.dotnet/10.0.400.aspNetCertificateSentinel b/.dotnet/.dotnet/10.0.400.aspNetCertificateSentinel deleted file mode 100644 index e69de29b..00000000 diff --git a/.dotnet/.dotnet/10.0.400.dotnetFirstUseSentinel b/.dotnet/.dotnet/10.0.400.dotnetFirstUseSentinel deleted file mode 100644 index e69de29b..00000000 diff --git a/.dotnet/.dotnet/10.0.400.toolpath.sentinel b/.dotnet/.dotnet/10.0.400.toolpath.sentinel deleted file mode 100644 index e69de29b..00000000