Jenny J2
Findings¶
- Medium —
src/Forge.Approvals.Core/Approvers.cs:98(alsosrc/Forge.Approvals.Core/Approvers.cs:8,src/Forge.Approvals.Core/Approvers.cs:36,src/Forge.Approvals.Core/Approvers.cs:102,src/Forge.Approvals.Core/Approvers.cs:147) - Problem:
ApprovalEvidence(string PersonId, string ChallengeId)(src/Forge.Approvals.Core/Approvers.cs:8) is a positional record withoutrequiredproperties, so untrusted deserialized JSON payloads such as[null]or[{"challengeId":"YC..."}]can producenullelements orPersonId == nullwithout throwingJsonException.- A
nullelement inevidencethrowsNullReferenceExceptionatsrc/Forge.Approvals.Core/Approvers.cs:98, which hits the catch-all atsrc/Forge.Approvals.Core/Approvers.cs:147and returnsApprovalDecision.ProviderUnavailableinstead of a terminalDenied/Invalid— allowing malformed untrusted input to trigger transient-outage retries/alerts. - A
nullPersonIdpassesDistinct(StringComparer.Ordinal)atsrc/Forge.Approvals.Core/Approvers.cs:98and callsregistry.Find(null!)atsrc/Forge.Approvals.Core/Approvers.cs:102, wherepeople.GetValueOrDefault(personId)(src/Forge.Approvals.Core/Approvers.cs:36) throwsArgumentNullException(returningInvalidviasrc/Forge.Approvals.Core/Approvers.cs:146, whereas unknown/emptyPersonIdreturnsDenied, and direct callers ofApproverRegistry.Findget an unexpected exception instead ofnull).
- A
-
Fix: Guard
ApproverRegistry.Findatsrc/Forge.Approvals.Core/Approvers.cs:36withstring.IsNullOrWhiteSpace(personId) ? null : people.GetValueOrDefault(personId), and checkevidence.Any(e => e is null || string.IsNullOrWhiteSpace(e.PersonId) || string.IsNullOrWhiteSpace(e.ChallengeId))atsrc/Forge.Approvals.Core/Approvers.cs:97before.Select(...)and provider calls. -
Low —
src/Forge.Approvals.Core/Approvers.cs:103(alsosrc/Forge.Approvals.Core/Approvers.cs:110,src/Forge.Approvals.Core/Approvers.cs:135) - Problem: The pre-flight guard at
src/Forge.Approvals.Core/Approvers.cs:101(// Reject an impossible quorum before provider fan-out.) only checkscandidates.Length >= policy.MinimumApproversand per-role presence (policy.RequiredRoles.Any(r => !candidates.Any(p => p!.Roles.Contains(r)))atsrc/Forge.Approvals.Core/Approvers.cs:104), not bipartite matchability. If one multi-role approver holds multiple required roles (e.g.,ActionKind.Releaserequiring[Owner, QaSigner, UxSigner], andevidencesubmits 1 user holding all 3 roles plus 2[TeamMember]-only users),src/Forge.Approvals.Core/Approvers.cs:103passes even though a 1-person-per-role assignment is impossible, fanning out externalGetDecisionAsynccalls (src/Forge.Approvals.Core/Approvers.cs:111) that are guaranteed to fail!Match(0)atsrc/Forge.Approvals.Core/Approvers.cs:135. Likewise, whitespaceChallengeIdon element $k > 0$ is not rejected untilsrc/Forge.Approvals.Core/Approvers.cs:110inside the fan-out loop after $k - 1$ provider calls have already executed. -
Fix: Validate
!string.IsNullOrWhiteSpace(e.ChallengeId)and run the bipartiteMatchhelper againstcandidatesatsrc/Forge.Approvals.Core/Approvers.cs:103prior to theforeachprovider fan-out loop atsrc/Forge.Approvals.Core/Approvers.cs:107. -
Low —
src/Forge.Approvals.Core/ApprovalGate.cs:7andsrc/Forge.Approvals.Core/Approvers.cs:22(alsosrc/Forge.Approvals.Core/ApprovalGate.cs:30,src/Forge.Approvals.Core/ApprovalGate.cs:80,src/Forge.Approvals.Core/Approvers.cs:56,src/Forge.Approvals.Core/Approvers.cs:147) - Problem:
ApprovalGate(src/Forge.Approvals.Core/ApprovalGate.cs:7) andExecutorApprovalVerifier(src/Forge.Approvals.Core/Approvers.cs:56) do not guard required dependencies (provider,clock,notifier,registry,verifierFactory,replay) againstnullwhenenabled == true; a miswired dependency throwsNullReferenceExceptioninsideRequestAsync/Evaluate/VerifyAsyncand is masked as a transientApprovalDecision.ProviderUnavailableby the catch-all handlers (src/Forge.Approvals.Core/ApprovalGate.cs:30,src/Forge.Approvals.Core/ApprovalGate.cs:80,src/Forge.Approvals.Core/Approvers.cs:147) or swallowed inNotifyPersistedAsync(src/Forge.Approvals.Core/ApprovalGate.cs:49).ApproverRegistry(src/Forge.Approvals.Core/Approvers.cs:22) does not null-checkapprovers,person,person.FactorSids, orperson.Roles(throwingNullReferenceExceptionrather thanArgumentException/ArgumentNullException), and enumeratesFactorSidsandRolesmultiple times before snapshotting.ToArray()atsrc/Forge.Approvals.Core/Approvers.cs:31.
- Fix: Fail fast with
ArgumentNullException.ThrowIfNullon required constructor dependencies (whenenabledistrue, and onapprovers), null-checkperson/FactorSids/RolesinApproverRegistry(src/Forge.Approvals.Core/Approvers.cs:24) to throwArgumentException, and snapshotFactorSids.ToArray()andRoles.ToArray()once before validation.
Backend Concurrency & Test Verification (Jenny Focus)¶
No test projects are included in this diff slice; confirm the suite exercises these concurrency, retry/idempotency, and cancellation paths (or add the named missing tests):
- Concurrent ledger consumption / replay race (
VerifyAsync_ParallelSameJtiOrOverlappingChallenge_CommitsExactlyOnce): Two concurrent callers can passGetDecisionAsync(src/Forge.Approvals.Core/Approvers.cs:111) simultaneously before reachingreplay.TryCommitEffectAsync(src/Forge.Approvals.Core/Approvers.cs:142). ExerciseTask.WhenAllagainst the SQLiteIExecutorApprovalLedgerfor both identicalrequest.Jtiand distinctJtis attempting to reuse aChallengeId, asserting exactly oneApprovedand all peersDenied. - Mid-flight expiry and clock rollback (
Evaluate_And_VerifyAsync_ExpireOrRollbackDuringProviderCall_FailsClosed): BothApprovalGate.Evaluate(src/Forge.Approvals.Core/ApprovalGate.cs:65,src/Forge.Approvals.Core/ApprovalGate.cs:74) andExecutorApprovalVerifier.VerifyAsync(src/Forge.Approvals.Core/Approvers.cs:95,src/Forge.Approvals.Core/Approvers.cs:138) re-checkIApprovalClockafter provider I/O; test advancing pastExpiresUtcand simulating clock failure (Ok = false/now < CreatedUtc - 2m) during an awaitedGetDecisionAsync. - Notification timeout isolation, unobserved faults, and cancellation propagation (
NotifyPersistedAsync_TimeoutVsCallerCancellation): Exercise (1) a hung non-IIndependentNotificationChannelsnotifier timing out via the 10s linkedCancellationTokenSource(src/Forge.Approvals.Core/ApprovalGate.cs:40) and faulting asynchronously afterwards without raisingTaskScheduler.UnobservedTaskException(src/Forge.Approvals.Core/ApprovalGate.cs:44), (2) anIIndependentNotificationChannelsnotifier bypassing the 10s aggregate deadline (src/Forge.Approvals.Core/ApprovalGate.cs:40), and (3) callercancellationTokencancellation rethrowingOperationCanceledException(src/Forge.Approvals.Core/ApprovalGate.cs:48,src/Forge.Approvals.Core/Approvers.cs:145) while internal/providerOperationCanceledException(when!cancellationToken.IsCancellationRequested) maps toProviderUnavailable. - Malformed evidence rejection without provider fan-out (
VerifyAsync_NullOrIncompleteEvidence_RejectsWithoutProviderCalls): Pass[null!],[new ApprovalEvidence(null!, "YC1")], and an impossible multi-role Release quorum (src/Forge.Approvals.Core/Approvers.cs:98,src/Forge.Approvals.Core/Approvers.cs:103) and assertDeniedwith zeroverifierFactoryinvocations.