Skip to content

Jenny J2

Findings

  1. Medium — src/Forge.Approvals.Core/Approvers.cs:98 (also src/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)
  2. Problem: ApprovalEvidence(string PersonId, string ChallengeId) (src/Forge.Approvals.Core/Approvers.cs:8) is a positional record without required properties, so untrusted deserialized JSON payloads such as [null] or [{"challengeId":"YC..."}] can produce null elements or PersonId == null without throwing JsonException.
    • A null element in evidence throws NullReferenceException at src/Forge.Approvals.Core/Approvers.cs:98, which hits the catch-all at src/Forge.Approvals.Core/Approvers.cs:147 and returns ApprovalDecision.ProviderUnavailable instead of a terminal Denied/Invalid — allowing malformed untrusted input to trigger transient-outage retries/alerts.
    • A null PersonId passes Distinct(StringComparer.Ordinal) at src/Forge.Approvals.Core/Approvers.cs:98 and calls registry.Find(null!) at src/Forge.Approvals.Core/Approvers.cs:102, where people.GetValueOrDefault(personId) (src/Forge.Approvals.Core/Approvers.cs:36) throws ArgumentNullException (returning Invalid via src/Forge.Approvals.Core/Approvers.cs:146, whereas unknown/empty PersonId returns Denied, and direct callers of ApproverRegistry.Find get an unexpected exception instead of null).
  3. Fix: Guard ApproverRegistry.Find at src/Forge.Approvals.Core/Approvers.cs:36 with string.IsNullOrWhiteSpace(personId) ? null : people.GetValueOrDefault(personId), and check evidence.Any(e => e is null || string.IsNullOrWhiteSpace(e.PersonId) || string.IsNullOrWhiteSpace(e.ChallengeId)) at src/Forge.Approvals.Core/Approvers.cs:97 before .Select(...) and provider calls.

  4. Low — src/Forge.Approvals.Core/Approvers.cs:103 (also src/Forge.Approvals.Core/Approvers.cs:110, src/Forge.Approvals.Core/Approvers.cs:135)

  5. Problem: The pre-flight guard at src/Forge.Approvals.Core/Approvers.cs:101 (// Reject an impossible quorum before provider fan-out.) only checks candidates.Length >= policy.MinimumApprovers and per-role presence (policy.RequiredRoles.Any(r => !candidates.Any(p => p!.Roles.Contains(r))) at src/Forge.Approvals.Core/Approvers.cs:104), not bipartite matchability. If one multi-role approver holds multiple required roles (e.g., ActionKind.Release requiring [Owner, QaSigner, UxSigner], and evidence submits 1 user holding all 3 roles plus 2 [TeamMember]-only users), src/Forge.Approvals.Core/Approvers.cs:103 passes even though a 1-person-per-role assignment is impossible, fanning out external GetDecisionAsync calls (src/Forge.Approvals.Core/Approvers.cs:111) that are guaranteed to fail !Match(0) at src/Forge.Approvals.Core/Approvers.cs:135. Likewise, whitespace ChallengeId on element $k > 0$ is not rejected until src/Forge.Approvals.Core/Approvers.cs:110 inside the fan-out loop after $k - 1$ provider calls have already executed.
  6. Fix: Validate !string.IsNullOrWhiteSpace(e.ChallengeId) and run the bipartite Match helper against candidates at src/Forge.Approvals.Core/Approvers.cs:103 prior to the foreach provider fan-out loop at src/Forge.Approvals.Core/Approvers.cs:107.

  7. Low — src/Forge.Approvals.Core/ApprovalGate.cs:7 and src/Forge.Approvals.Core/Approvers.cs:22 (also src/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)

  8. Problem:
    • ApprovalGate (src/Forge.Approvals.Core/ApprovalGate.cs:7) and ExecutorApprovalVerifier (src/Forge.Approvals.Core/Approvers.cs:56) do not guard required dependencies (provider, clock, notifier, registry, verifierFactory, replay) against null when enabled == true; a miswired dependency throws NullReferenceException inside RequestAsync/Evaluate/VerifyAsync and is masked as a transient ApprovalDecision.ProviderUnavailable by 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 in NotifyPersistedAsync (src/Forge.Approvals.Core/ApprovalGate.cs:49).
    • ApproverRegistry (src/Forge.Approvals.Core/Approvers.cs:22) does not null-check approvers, person, person.FactorSids, or person.Roles (throwing NullReferenceException rather than ArgumentException/ArgumentNullException), and enumerates FactorSids and Roles multiple times before snapshotting .ToArray() at src/Forge.Approvals.Core/Approvers.cs:31.
  9. Fix: Fail fast with ArgumentNullException.ThrowIfNull on required constructor dependencies (when enabled is true, and on approvers), null-check person / FactorSids / Roles in ApproverRegistry (src/Forge.Approvals.Core/Approvers.cs:24) to throw ArgumentException, and snapshot FactorSids.ToArray() and Roles.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 pass GetDecisionAsync (src/Forge.Approvals.Core/Approvers.cs:111) simultaneously before reaching replay.TryCommitEffectAsync (src/Forge.Approvals.Core/Approvers.cs:142). Exercise Task.WhenAll against the SQLite IExecutorApprovalLedger for both identical request.Jti and distinct Jtis attempting to reuse a ChallengeId, asserting exactly one Approved and all peers Denied.
  • Mid-flight expiry and clock rollback (Evaluate_And_VerifyAsync_ExpireOrRollbackDuringProviderCall_FailsClosed): Both ApprovalGate.Evaluate (src/Forge.Approvals.Core/ApprovalGate.cs:65, src/Forge.Approvals.Core/ApprovalGate.cs:74) and ExecutorApprovalVerifier.VerifyAsync (src/Forge.Approvals.Core/Approvers.cs:95, src/Forge.Approvals.Core/Approvers.cs:138) re-check IApprovalClock after provider I/O; test advancing past ExpiresUtc and simulating clock failure (Ok = false / now < CreatedUtc - 2m) during an awaited GetDecisionAsync.
  • Notification timeout isolation, unobserved faults, and cancellation propagation (NotifyPersistedAsync_TimeoutVsCallerCancellation): Exercise (1) a hung non-IIndependentNotificationChannels notifier timing out via the 10s linked CancellationTokenSource (src/Forge.Approvals.Core/ApprovalGate.cs:40) and faulting asynchronously afterwards without raising TaskScheduler.UnobservedTaskException (src/Forge.Approvals.Core/ApprovalGate.cs:44), (2) an IIndependentNotificationChannels notifier bypassing the 10s aggregate deadline (src/Forge.Approvals.Core/ApprovalGate.cs:40), and (3) caller cancellationToken cancellation rethrowing OperationCanceledException (src/Forge.Approvals.Core/ApprovalGate.cs:48, src/Forge.Approvals.Core/Approvers.cs:145) while internal/provider OperationCanceledException (when !cancellationToken.IsCancellationRequested) maps to ProviderUnavailable.
  • 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 assert Denied with zero verifierFactory invocations.