fix: reject unknown recipient BaseType in BuildPolicyJson#20
Merged
Conversation
Convert internal BaseType from string to a RecipientBaseType enum and switch BuildPolicyJson to an exhaustive switch expression with a default arm that throws ArgumentException. Previously, any BaseType value other than "email" or "emailDomain" silently fell through both branches and produced a policy entry whose con array contained only the recipient's Extras — a security-sensitive failure mode if a new builder were ever added without updating BuildPolicyJson. Add InternalsVisibleTo for the test project and unit tests covering the two known base types, ExtraAttribute appending, multi-recipient construction, the EmailDomain no-at fallback, and the new guard. Closes #13.
Contributor
Author
There was a problem hiding this comment.
Self-review (cannot formally approve own PR):
What I verified:
- Built and ran the full test suite locally on net10.0: 19/19 pass (6 new + existing).
- CI is green.
BaseTypebecoming an internal enum is non-breaking (no public API touched).- Switch expression with
_ => throw new ArgumentException(...)is the right shape: the compiler will not enforce exhaustiveness on enums, but the runtime guard plus the newUnknownBaseType_Throwstest catches a future builder being added without updatingSealPipeline.BuildPolicyJson. - Test coverage is sensible: both base types, the no-
@fallback forEmailDomain,ExtraAttributeordering, multi-recipient, and the new guard.
Minor nits (non-blocking):
SealPipeline.cs:84—nameof(recipients)as the param name is technically accurate but the offending value isr.BaseType; either is fine.- The new enum could live in its own file for tidiness, but co-locating with
RecipientBuilderis reasonable given it's internal-only.
Ready for human review. Closes #13.
rubenhensen
approved these changes
May 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
BuildPolicyJsononly handledBaseType == "email"and"emailDomain"; any other value silently produced a policy entry with an emptycon(only the recipient'sExtras). Today this is unreachable but represents a footgun — adding a new builder without updatingBuildPolicyJsonwould yield broken/permissive encryption policies.This PR converts
BaseTypefrom a stringly-typed field to an internalRecipientBaseTypeenum, rewritesBuildPolicyJsonas aswitchexpression with an explicit default arm that throwsArgumentException, and adds a regression-test suite.Changes
src/Models/Recipients.cs— newinternal enum RecipientBaseType { Email, EmailDomain };BaseTypeis now that enum.src/PostGuard.cs—RecipientBuilders.Email/EmailDomainfactories pass enum values.src/Crypto/SealPipeline.cs— exhaustive switch with_ => throw new ArgumentException(...)default.src/E4A.PostGuard.csproj—InternalsVisibleTo("E4A.PostGuard.Tests")so tests can callBuildPolicyJsondirectly.tests/E4A.PostGuard.Tests/BuildPolicyJsonTests.cs— six tests covering both known base types, theEmailDomainno-@fallback,ExtraAttributeappending, multi-recipient construction, and the new guard against an unknown enum value.No public API change —
BaseTypeisinternal.Test plan
dotnet build E4A.PostGuard.slnx -c Release— greendotnet test --no-build --framework net10.0— 19/19 pass (net8.0 runtime not installed locally; CI covers it)Reviewer quickstart
Closes #13.