Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion internal/api/httpapi/security_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,16 @@ func TestGetPlayerHidesCrossTenant(t *testing.T) {
t.Fatalf("do: %v", err)
}
defer func() { _ = resp.Body.Close() }()
b, _ := io.ReadAll(resp.Body)
if resp.StatusCode != http.StatusNotFound {
b, _ := io.ReadAll(resp.Body)
t.Fatalf("status=%d want 404 body=%s", resp.StatusCode, b)
}
if json.Valid(b) {
t.Fatalf("cross-tenant body is JSON: %s", b)
}
if bytes.Contains(b, []byte("vip")) || bytes.Contains(b, []byte("balance")) || bytes.Contains(b, []byte("acme-casino")) {
t.Fatalf("cross-tenant body leaked snapshot: %s", b)
}
}

func newSecurityTestServer(t *testing.T) (*store.Store, *httptest.Server) {
Expand Down
2 changes: 1 addition & 1 deletion web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Next.js App Router console for the Go service. HMAC is signed in the BFF. The br
| --- | --- |
| `/` | Arena. Dual-tenant stage (`acme-casino` VIP vs `nova-sports` velocity). Ignite runs HMAC, outbox, Kafka, worker tx, then GET player. |
| `/architecture` | Live counters and the event path. Select a node. Dead letters: last N from Kafka; Redrive is a human-clicked signed ingest of the same event_id. |
| `/contract` | `make replay` snapshot contract. Tools tab: `ingest` / `get_player` / `get_metrics`. Not tools: `credit` / `set_vip`. Shadow tab: mock vs velocity disagreements. |
| `/contract` | Run contract: duplicate credit-once, `credit`/`set_vip` 404, Nova cannot read an Acme player, shadow no-write, poison→DLQ when inject is on. Replay / tools / shadow tabs. |

Tab URLs: `/contract?tab=tools`, `/contract?tab=shadow`.

Expand Down
25 changes: 25 additions & 0 deletions web/app/api/contract/route.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { NextResponse } from "next/server";
import {
fetchPlayer,
getPlayerRaw,
ingestEvent,
parseMetrics,
postTool,
} from "@/lib/engagepulse";
import { getTenants } from "@/lib/tenants";
import { scoreShadowBoard } from "@/lib/shadow-score";

export const dynamic = "force-dynamic";
Expand Down Expand Up @@ -130,6 +132,23 @@ export async function POST() {
};
}

const isolationPlayerId = `probe-iso-${suffix}`;
await ingestEvent("acme-casino", {
event_id: `probe-iso-${suffix}`,
player_id: isolationPlayerId,
type: "deposit",
amount: 50,
occurred_at: new Date().toISOString(),
});
const nova = getTenants()["nova-sports"];
const cross = await getPlayerRaw(nova.apiKey, isolationPlayerId);
const lower = cross.body.toLowerCase();
const isolationPass =
cross.status === 404 &&
!lower.includes("vip") &&
!lower.includes("balance") &&
!lower.includes("acme-casino");

return NextResponse.json({
llm: "The LLM is not on the credit path.",
hmac: "HMAC is signed in the BFF and verified in Go.",
Expand All @@ -155,6 +174,12 @@ export async function POST() {
pass: shadowPass,
},
dlq: dlqProbe,
isolation: {
player_id: isolationPlayerId,
status: cross.status,
body_empty: cross.body.trim() === "player not found",
pass: isolationPass,
},
});
} catch (err) {
const message = err instanceof Error ? err.message : "contract probe failed";
Expand Down
16 changes: 15 additions & 1 deletion web/components/contract-run.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ type Probe = {
balance: number | null;
pass: boolean;
};
isolation: {
player_id: string;
status: number;
body_empty: boolean;
pass: boolean;
};
error?: string;
};

Expand Down Expand Up @@ -72,7 +78,8 @@ export function ContractRun() {
<CardTitle>Run contract</CardTitle>
<p className="mt-1 w-full text-pretty break-words text-sm text-muted-foreground">
Duplicate event_id, 404 on credit/set_vip, sparse-bets vs velocity,
and poison retry to DLQ when inject is on.
Nova cannot read an Acme player, and poison retry to DLQ when inject
is on.
</p>
</div>
<Button
Expand Down Expand Up @@ -128,6 +135,13 @@ export function ContractRun() {
? "Inject off. Poison event not sent."
: `Poison ${result.dlq.event_id}: retries Δ ${result.dlq.retries_delta}, DLQ Δ ${result.dlq.dlq_delta}. Balance ${result.dlq.balance ?? "—"}.`}
</li>
<li>
<Badge variant={result.isolation.pass ? "success-light" : "destructive-light"}>
{result.isolation.pass ? "pass" : "fail"}
</Badge>{" "}
Nova GET {result.isolation.player_id} → {result.isolation.status}
{result.isolation.body_empty ? ", no snapshot" : ""}.
</li>
</ul>
) : null}
</CardContent>
Expand Down
14 changes: 14 additions & 0 deletions web/lib/engagepulse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ export async function fetchPlayer(
return (await res.json()) as PlayerSnapshot;
}

export async function getPlayerRaw(
apiKey: string,
playerId: string,
): Promise<{ status: number; body: string }> {
const res = await fetch(
`${apiBase()}/v1/players/${encodeURIComponent(playerId)}`,
{
headers: { "X-API-Key": apiKey },
cache: "no-store",
},
);
return { status: res.status, body: await res.text() };
}

export async function ingestEvent(
tenantId: TenantId,
evt: Omit<EventPayload, "tenant_id"> & { tenant_id?: string },
Expand Down
Loading