Jenny A2
Findings¶
- [High]
src/Forge.Approvals.Core/Approvers.cs:98(and:124-125) —m-of-npolicies reject non-mandatory roles (TeamMember,QaSigner,UxSigner), deadlocking single-Owner quorums or forcing over-privileged roles - Problem:
ExecutorApprovalVerifier.VerifyAsyncrejects any signer whose roles do not intersectpolicy.RequiredRoles(!person.Roles.Intersect(policy.RequiredRoles).Any()), and line 125 callsperson.Roles.First(r => policy.RequiredRoles.Contains(r)). As a result,ApproverRole.TeamMember(line 3) can never participate in an Owner-requiredm-of-nquorum (MinimumApprovers > RequiredRoles.Count), nor can aQaSignerorUxSignerco-sign a 2-of-n Owner action. In an org with oneOwnerplusQaSigner/UxSigner/TeamMemberpeers,MinimumApprovers = 2, RequiredRoles = [Owner]permanently deadlocks unless non-owners are grantedApproverRole.Owner(breaking least privilege on 1-of-n Owner actions) orTeamMemberis added toRequiredRoles(which makesTeamMembermandatory inMatch(0)and rejects twoOwners orOwner+QaSigner). -
Fix: Allow any enrolled
ApproverinApproverRegistry(or an explicitAllowedRolesset onApprovalPolicydefaulting to all roles) to satisfy the remainingMinimumApprovers - RequiredRoles.Countquorum slots onceMatch(0)covers allpolicy.RequiredRoleswith distinct people. At line 125, assignperson.Roles.Where(policy.RequiredRoles.Contains).Cast<ApproverRole?>().FirstOrDefault() ?? person.Roles[0](do not use non-nullable.FirstOrDefault(), becausedefault(ApproverRole)isApproverRole.Owner == 0). -
[High]
src/Forge.Approvals.Cli/Stores.cs:35-55(andsrc/Forge.Approvals.Core/Approvers.cs:148-153) —FileApprovalClockfails closed asApprovalDecision.Invalidunder normal concurrency - Problem: Two races cause legitimate concurrent requests/verifications to fail terminally with
ApprovalDecision.Invalid:- Zero-wait lock contention:
FileApprovalClock.TryRecordAsyncopensclock.lockwithFileShare.None(line 35) while performingFileOptions.WriteThrough+Flush(flushToDisk: true)+File.Move, and immediately catchesIOException => false(line 54) without waiting or retrying. BecauseVerifyAsynccallsCheckTimetwice (lines 87 and 126), any overlappingstatus,request, orverifycall hitsERROR_SHARING_VIOLATIONand returnsApprovalDecision.Invalid. - Unlocked timestamp sampling race:
CheckTime(Approvers.cs:150) samplesvar now = clock.UtcNowbefore acquiringclock.lock. If Call A samples $t_1$ and Call B samples $t_2 > t_1$ and acquiresclock.lockfirst, Call A subsequently hitsnow < last($t_1 < t_2$ atStores.cs:40) and falsely triggers clock-rollback rejection (ApprovalDecision.Invalid).
- Zero-wait lock contention:
-
Fix: Acquire an in-process
SemaphoreSlimplus retryclock.lockon sharing-violationIOExceptionwith bounded async backoff + jitter honoringcancellationToken, and sampleUtcNowinside the critical section (e.g., an atomicTryObserveAsync(CancellationToken)onIApprovalClockreturning(bool Ok, DateTimeOffset UtcNow)). -
[Medium]
src/Forge.Approvals.Core/Approvers.cs:83-86(and:145) —Policy()deduplicatesconfigured.RequiredRolesviaEnumerable.Unionbefore validation, bypassing fail-closed checks - Problem:
VerifyAsynccheckspolicy.RequiredRoles.Count == 0(line 83) andpolicy.RequiredRoles.Distinct().Count() != policy.RequiredRoles.Count(line 85) afterPolicy()computesmandatory.Union(configured.RequiredRoles).ToArray()(line 145). Becausemandatoryis non-empty andEnumerable.Unionis a set union that strips duplicates, both fail-closed checks on lines 83 and 85 are unreachable dead code. A misconfigured policy such asnew ApprovalPolicy(MinimumApprovers: 1, RequiredRoles: [ApproverRole.Owner, ApproverRole.Owner])(expecting two Owners) orRequiredRoles: []silently collapses to[Owner]and approves with a single signer instead of returningApprovalDecision.Invalid. -
Fix: Validate
configuredbefore merging withmandatory(configured.MinimumApprovers < 1,configured.RequiredRoles is null or { Count: 0 },!Enum.IsDefined, andconfigured.RequiredRoles.Distinct().Count() != configured.RequiredRoles.Count->ApprovalDecision.Invalid), then union withmandatoryand enforceMath.Max(configured.MinimumApprovers, mergedRoles.Length). -
[Medium]
src/Forge.Approvals.Cli/Program.cs:21-22(and:31-36) —doctorbypasses notifier/port validation and invalidApprovals:Email:SmtpPortsilently falls back to587 - Problem:
- When
Approvals:Enabled=true,args.FirstOrDefault() == "doctor"returns at lines 21-22 before the notifier validation block (lines 29-36), soforge-approve doctorprintsapprovals enabled; configuration complete(exit0) even whenPavlokNotifier,SmtpEmailSender,EmailNotifier, orFileNotificationOutboxfails validation and every real command exits1(ProviderUnavailable). - 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") to587instead of failing closed.
- When
- Fix: Validate
Approvals:Email:SmtpPortup front as part ofcomplete(allownull/empty ->587; otherwise requireint.TryParse(rawPort, NumberStyles.None, CultureInfo.InvariantCulture, out int port) && port is >= 1 and <= 65535). Keep!enabledshort-circuited before touching disk/notifiers so disabled mode stays inert, while running notifier validation fordoctorwhenenabled == true.
Backend Concurrency & Async Test Gaps¶
- Missing — Parallel clock contention & sampling-order test: Exercise
Task.WhenAll(and multi-process callers) running concurrentExecutorApprovalVerifier.VerifyAsync/FileApprovalClockobservations across distinct valid JTIs to prove lock contention and thread scheduling interleavings never emit falseApprovalDecision.Invalid. - Required — Parallel replay race test: Exercise
NconcurrentVerifyAsyncandFileReplayStore.TryConsumeAsynccalls against the same approvedJtiand assert exactly oneApprovalDecision.ApprovedandN - 1ApprovalDecision.Denied. - Missing — Heterogeneous
m-of-n& malformed policy tests: ExerciseMinimumApprovers = 2withOwner+TeamMember(andOwner+QaSigner), and assert duplicateRequiredRoles([Owner, Owner]withMinimumApprovers = 1) fails closed withApprovalDecision.Invalid. - Missing — Cooperative cancellation contract test: Both
ExecutorApprovalVerifier.VerifyAsync(Approvers.cs:131) andApprovalCli.RunAsync(Program.cs:110) catchExceptionbroadly, converting caller-triggeredOperationCanceledException(cancellationToken.IsCancellationRequested) intoProviderUnavailable/"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.