Skip to content

Jenny A2

Findings

  1. [High] src/Forge.Approvals.Core/Approvers.cs:98 (and :124-125) — m-of-n policies reject non-mandatory roles (TeamMember, QaSigner, UxSigner), deadlocking single-Owner quorums or forcing over-privileged roles
  2. Problem: ExecutorApprovalVerifier.VerifyAsync rejects any signer whose roles do not intersect policy.RequiredRoles (!person.Roles.Intersect(policy.RequiredRoles).Any()), and line 125 calls person.Roles.First(r => policy.RequiredRoles.Contains(r)). As a result, ApproverRole.TeamMember (line 3) can never participate in an Owner-required m-of-n quorum (MinimumApprovers > RequiredRoles.Count), nor can a QaSigner or UxSigner co-sign a 2-of-n Owner action. In an org with one Owner plus QaSigner/UxSigner/TeamMember peers, MinimumApprovers = 2, RequiredRoles = [Owner] permanently deadlocks unless non-owners are granted ApproverRole.Owner (breaking least privilege on 1-of-n Owner actions) or TeamMember is added to RequiredRoles (which makes TeamMember mandatory in Match(0) and rejects two Owners or Owner + QaSigner).
  3. Fix: Allow any enrolled Approver in ApproverRegistry (or an explicit AllowedRoles set on ApprovalPolicy defaulting to all roles) to satisfy the remaining MinimumApprovers - RequiredRoles.Count quorum slots once Match(0) covers all policy.RequiredRoles with distinct people. At line 125, assign person.Roles.Where(policy.RequiredRoles.Contains).Cast<ApproverRole?>().FirstOrDefault() ?? person.Roles[0] (do not use non-nullable .FirstOrDefault(), because default(ApproverRole) is ApproverRole.Owner == 0).

  4. [High] src/Forge.Approvals.Cli/Stores.cs:35-55 (and src/Forge.Approvals.Core/Approvers.cs:148-153) — FileApprovalClock fails closed as ApprovalDecision.Invalid under normal concurrency

  5. Problem: Two races cause legitimate concurrent requests/verifications to fail terminally with ApprovalDecision.Invalid:
    1. Zero-wait lock contention: FileApprovalClock.TryRecordAsync opens clock.lock with FileShare.None (line 35) while performing FileOptions.WriteThrough + Flush(flushToDisk: true) + File.Move, and immediately catches IOException => false (line 54) without waiting or retrying. Because VerifyAsync calls CheckTime twice (lines 87 and 126), any overlapping status, request, or verify call hits ERROR_SHARING_VIOLATION and returns ApprovalDecision.Invalid.
    2. Unlocked timestamp sampling race: CheckTime (Approvers.cs:150) samples var now = clock.UtcNow before acquiring clock.lock. If Call A samples $t_1$ and Call B samples $t_2 > t_1$ and acquires clock.lock first, Call A subsequently hits now < last ($t_1 < t_2$ at Stores.cs:40) and falsely triggers clock-rollback rejection (ApprovalDecision.Invalid).
  6. Fix: Acquire an in-process SemaphoreSlim plus retry clock.lock on sharing-violation IOException with bounded async backoff + jitter honoring cancellationToken, and sample UtcNow inside the critical section (e.g., an atomic TryObserveAsync(CancellationToken) on IApprovalClock returning (bool Ok, DateTimeOffset UtcNow)).

  7. [Medium] src/Forge.Approvals.Core/Approvers.cs:83-86 (and :145) — Policy() deduplicates configured.RequiredRoles via Enumerable.Union before validation, bypassing fail-closed checks

  8. Problem: VerifyAsync checks policy.RequiredRoles.Count == 0 (line 83) and policy.RequiredRoles.Distinct().Count() != policy.RequiredRoles.Count (line 85) after Policy() computes mandatory.Union(configured.RequiredRoles).ToArray() (line 145). Because mandatory is non-empty and Enumerable.Union is a set union that strips duplicates, both fail-closed checks on lines 83 and 85 are unreachable dead code. A misconfigured policy such as new ApprovalPolicy(MinimumApprovers: 1, RequiredRoles: [ApproverRole.Owner, ApproverRole.Owner]) (expecting two Owners) or RequiredRoles: [] silently collapses to [Owner] and approves with a single signer instead of returning ApprovalDecision.Invalid.
  9. Fix: Validate configured before merging with mandatory (configured.MinimumApprovers < 1, configured.RequiredRoles is null or { Count: 0 }, !Enum.IsDefined, and configured.RequiredRoles.Distinct().Count() != configured.RequiredRoles.Count -> ApprovalDecision.Invalid), then union with mandatory and enforce Math.Max(configured.MinimumApprovers, mergedRoles.Length).

  10. [Medium] src/Forge.Approvals.Cli/Program.cs:21-22 (and :31-36) — doctor bypasses notifier/port validation and invalid Approvals:Email:SmtpPort silently falls back to 587

  11. Problem:
    1. When Approvals:Enabled=true, args.FirstOrDefault() == "doctor" returns at lines 21-22 before the notifier validation block (lines 29-36), so forge-approve doctor prints approvals enabled; configuration complete (exit 0) even when PavlokNotifier, SmtpEmailSender, EmailNotifier, or FileNotificationOutbox fails validation and every real command exits 1 (ProviderUnavailable).
    2. Line 31 (int.TryParse(Read("Approvals:Email:SmtpPort"), out int configuredPort) ? configuredPort : 587) uses current-culture parsing without port-range bounds and silently defaults non-numeric typos (e.g., "tls") to 587 instead of failing closed.
  12. Fix: Validate Approvals:Email:SmtpPort up front as part of complete (allow null/empty -> 587; otherwise require int.TryParse(rawPort, NumberStyles.None, CultureInfo.InvariantCulture, out int port) && port is >= 1 and <= 65535). Keep !enabled short-circuited before touching disk/notifiers so disabled mode stays inert, while running notifier validation for doctor when enabled == true.

Backend Concurrency & Async Test Gaps

  • Missing — Parallel clock contention & sampling-order test: Exercise Task.WhenAll (and multi-process callers) running concurrent ExecutorApprovalVerifier.VerifyAsync / FileApprovalClock observations across distinct valid JTIs to prove lock contention and thread scheduling interleavings never emit false ApprovalDecision.Invalid.
  • Required — Parallel replay race test: Exercise N concurrent VerifyAsync and FileReplayStore.TryConsumeAsync calls against the same approved Jti and assert exactly one ApprovalDecision.Approved and N - 1 ApprovalDecision.Denied.
  • Missing — Heterogeneous m-of-n & malformed policy tests: Exercise MinimumApprovers = 2 with Owner + TeamMember (and Owner + QaSigner), and assert duplicate RequiredRoles ([Owner, Owner] with MinimumApprovers = 1) fails closed with ApprovalDecision.Invalid.
  • Missing — Cooperative cancellation contract test: Both ExecutorApprovalVerifier.VerifyAsync (Approvers.cs:131) and ApprovalCli.RunAsync (Program.cs:110) catch Exception broadly, converting caller-triggered OperationCanceledException (cancellationToken.IsCancellationRequested) into ProviderUnavailable / "Invalid"; add a cancellation test locking down whether caller cancellation should propagate (catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested) { throw; }) or map to a fail-closed decision without triggering provider-outage retry loops.

Jira FLT-359 · Vikunja · BOARD.md