fix(federation): narrow trust-guard query to inbound rows only

The pre-existing trust-guard's query filtered peer_approval_requests by
origin only. After Task 3 added outbound rows to the same table, the
guard started matching the user's own queued outbound row on retry,
returning 'rejected' with a misleading 'admin must resolve pending
approval' copy instead of the intended 'admin_required'. The variable
name (pendingInbound) and comment block already described the intent
as inbound-only — the query just didn't match. Adding direction='inbound'
to the where clause restores the intended behavior.
This commit is contained in:
Jannis Braun
2026-04-26 21:23:55 +02:00
parent 50bc510e8d
commit 6ee8663e9e
+11 -1
View File
@@ -198,10 +198,20 @@ export async function ensurePeered(
// The legitimate approval flow (routes/federation.ts /approval-requests/:id/ // The legitimate approval flow (routes/federation.ts /approval-requests/:id/
// approve) does NOT call ensurePeered — it deletes the approval-request first // approve) does NOT call ensurePeered — it deletes the approval-request first
// and does its own fetch — so this guard does not block legitimate approvals. // and does its own fetch — so this guard does not block legitimate approvals.
//
// direction='inbound' filter: the table is bidirectional as of the outbound
// peering gate (Task 3); outbound rows live in the same table and must NOT
// trigger this guard. The outbound gate below (`if (!existing)` block) is
// responsible for outbound row state.
const pendingInbound = db const pendingInbound = db
.select({ id: schema.peerApprovalRequests.id }) .select({ id: schema.peerApprovalRequests.id })
.from(schema.peerApprovalRequests) .from(schema.peerApprovalRequests)
.where(eq(schema.peerApprovalRequests.origin, normalized)) .where(
and(
eq(schema.peerApprovalRequests.origin, normalized),
eq(schema.peerApprovalRequests.direction, 'inbound'),
),
)
.get(); .get();
if (pendingInbound) { if (pendingInbound) {