Skip to content

Commit 282e47d

Browse files
jchrisclaude
andcommitted
fix: enforce strict policy - verify user in LedgerUsers before issuing token
When an existing AppIdBinding is found, we must verify the user is actually in LedgerUsers with active status before granting access. Users must accept the invite first. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 448e6cf commit 282e47d

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

dashboard/backend/public/ensure-cloud-token.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,21 @@ export async function ensureCloudToken(
9797
.where(and(eq(sqlAppIdBinding.appId, req.appId), eq(sqlAppIdBinding.env, req.env ?? "prod")))
9898
.get();
9999
if (existingBinding) {
100-
// Use the existing ledger - the user should have been added via invite redemption
100+
// Verify the user is actually in LedgerUsers before granting access (strict policy)
101+
const userInLedger = await ctx.db
102+
.select()
103+
.from(sqlLedgerUsers)
104+
.where(
105+
and(
106+
eq(sqlLedgerUsers.ledgerId, existingBinding.Ledgers.ledgerId),
107+
eq(sqlLedgerUsers.userId, req.auth.user.userId),
108+
eq(sqlLedgerUsers.status, "active"),
109+
),
110+
)
111+
.get();
112+
if (!userInLedger) {
113+
return Result.Err(`user not authorized for ledger - please accept the invite first`);
114+
}
101115
ledgerId = existingBinding.Ledgers.ledgerId;
102116
tenantId = existingBinding.Ledgers.tenantId;
103117
} else {

0 commit comments

Comments
 (0)