Closed-loop multi-tenant security CLI using Kane CLI to catch cross-tenant IDOR/BOLA leaks in real browsers, patch via AI agent, and prove 403 isolation.
TenantFence is a closed-loop security verification CLI for teams shipping multi-tenant SaaS apps—especially with AI coding agents where one missing tenantId filter exposes customer data (OWASP API1:2023 BOLA/IDOR). What we built: - Declarative ownership manifest (specs/ownership.manifest.json) defining tenants, protected resources, and sensitive markers. - Multi-tenant SaaS target (InvoiceFlow at https://tenantfence.vercel.app) plus a zero-setup local replay mode and GitHub Actions CI guard. - TypeScript CLI orchestrator enforcing Owner(r) != Tenant(u) => 403 Denied while requiring owner positive control (HTTP 200) so a broken app never gets a false pass. What Kane CLI does in the flow: 1. Generates test.md specs from the manifest and runs @testmuai/kane-cli (kane-cli testmd run --agent --headless) in two isolated browser sessions: Tenant Alpha (positive control) and Tenant Beta (cross-tenant access check). 2. Drives real authenticated browser sessions, asserts cross-tenant markers never appear, and saves Result.md, screenshots, and .evidence artifacts. 3. Paired with a raw HTTP probe oracle using real login cookies, TenantFence confirms real leaks without false alarms, hands structured evidence to our AI coding agent (Muse) to patch the backend route, polls deployment, and replays Kane CLI until TENANT_ISOLATION_VERIFIED passes.
How the agent and Kane CLI talk to each other: When Kane CLI fails an isolation assertion and the HTTP probe confirms exposure, cli/agent-bridge.ts writes a structured evidence packet (artifacts/evidence/finding-bundle.json and muse-patch-prompt.md) containing the actor, target resource, HTTP status, leaked markers, Kane Result.md/screenshot paths, and the suspected backend route file. Our AI coding agent (Muse) consumes this packet (either via AGENT_CMD or watched file updates), patches target-saas/app/api/invoices/[id]/route.ts to enforce invoice.tenantId === user.tenantId (returning HTTP 403 Forbidden), and triggers an automatic replay. For live deploys, the orchestrator polls /api/health until the new commit SHA is live before re-running Kane CLI. What Kane CLI caught (committed proof): - Run 1 before patch (commit 91f7a67): Authenticated Tenant Beta navigated to Tenant Alpha's /invoices/INV-1001. Kane CLI captured the cross-tenant leak (HTTP 200 exposing "$15,000" and "CONFIDENTIAL-ALPHA-9921") in Result.md and .evidence bundles. - Real verifier bug caught & fixed (commit 27690cc): Our first post-patch run triggered a false alarm even though the server returned 403 because Kane's Result.md quoted our own assertion text ("assert page does NOT display CONFIDENTIAL-ALPHA-9921"). We fixed this permanently by making the authenticated HTTP probe the sole exposure oracle and adding 4 verifier self-tests (including a regression test for this exact case) plus mandatory owner positive control. - Run 2 after patch (commit 7d37cde & 27690cc): Beta -> INV-1001 returns HTTP 403 Forbidden with zero markers leaked, while Alpha -> INV-1001 and Beta -> INV-2001 both pass with HTTP 200 (FINAL: TENANT_ISOLATION_VERIFIED). How judges can run & replay it: Live demo: https://tenantfence.vercel.app Demo credentials (also in README.md): - Tenant Alpha: finance@alpha.test / AlphaPass123! (owns INV-1001) - Tenant Beta: finance@beta.test / BetaPass123! (owns INV-2001) Because main ships patched by default, judges can replay the full breach-to-fix loop locally with zero external DB setup: 1. git clone https://github.com/0xrard/tenantfence && cd tenantfence && npm install 2. npm run vuln:reopen # re-opens the controlled IDOR only in [id]/route.ts 3. npm run verify:local # boots local target, runs Kane CLI closed-loop, cleans up port 4. npm run vuln:patch # restores the 403 ownership check What's next: - Add OAuth/JWT/SSO session adapters beyond cookie-based auth. - Dynamic resource seeding (create-as-Tenant-A, probe-as-Tenant-B) for read-safe verification against real staging environments. - Automated GitHub PR comments attaching Kane CLI before/after proof directly from .github/workflows/tenantfence.yml.
Built in two weeks for the KaneCLI Online Hackathon.
See the hackathon →