Full-stack audit — 2026-10-01
Scope: dev at 8fa82ee — frontend (Next.js static export on Cloudflare
Workers), backend (Fastify on Render), SDK, and the Anchor program as deployed
to devnet. Findings are ordered by severity. "Fixed" items ship in the
accompanying PR; "Open" items need a program upgrade or an operator decision.
Critical
C1. Match links always opened the "placeholder" match — Fixed
app/play/[matchId] was statically exported with one param
(placeholder), and the worker served placeholder.html for every
/play/<id>. Pages read params, which come from the prerendered payload, so
every deep link, refresh, invite and spectate URL loaded match placeholder
and showed "Match unavailable". Verified locally against the dev build.
Fix: match pages are static routes reading the ID from the query string
(/play?id=…, /spectate?id=…); the worker 302-redirects legacy
/play/<id>[/spectate] links and returns a real 404 for unknown paths instead
of silently rendering the home page.
C2. Sponsor relay could be drained — Fixed (backend)
The fee payer that makes embedded-wallet play gasless:
- paid rent for standalone associated-token-account creation, for any
mint (
hasAppInstructionwas set by the ATA instruction alone); - passed any Magic Chess instruction it didn't recognise without checks;
- let
process_match_settlementsend escrow rent (paid by the sponsor) to an arbitrarypayer, andclose_matchhand match rent to the caller; - rate-limited per
userId:walletAddress, so a single Privy user could rotate throwaway keys without limit.
Fix: per-instruction allowlist with signer/role checks; ATA creation must
be consumed by a Magic Chess instruction in the same transaction; settlement
and close_match must refund rent to the sponsor; per-Privy-user rate limit,
per-user hourly cap on rent-heavy operations, and a global hourly lamport
budget. Frontend now bundles wager/payout ATAs into the operation itself.
High
H1. Index never learned game results, payouts or aborts — Fixed
Only match-created, player-joined and move-made were ever reported by
browsers; nothing called game-ended, payout or match-aborted. Finished
games stayed Active forever, stats/leaderboard never updated, and the lobby
showed dead games as live.
Fix: backend chain indexer scans the program on the base layer and each
live match's PDA on its MagicBlock ER, ingesting every event through one
idempotent path shared with /api/sync/*.
H2. Missed move events shifted all later moves — Fixed
move_number = MAX(move_number) + 1 meant one unreported move renumbered the
rest of the game (and out-of-order delivery was rejected).
Fix: ply is derived from the on-chain FEN in the event; inserts are
idempotent on (match_id, move_number).
H3. "Your live games" was always empty during play — Fixed
The arena listed the player's matches via program.account.chessMatch.all()
on the base layer, but an in-progress match is owned by the delegation program
there. Fix: merge indexer results with the chain scan.
H4. Fast-play sessions rarely worked — Fixed
SessionTokenV2 was created on the base layer after delegation, so the ER
often hadn't cloned it and every move fell back to a wallet prompt; external
wallets couldn't create sessions at all.
Fix: after creating the session signer, register it on the delegated match
with set_session_key (authorization then comes from the match account the ER
already has). External wallets self-pay the session top-up. Gameplay-only
transactions (move, session key, commit/undelegate) sign without a modal for
embedded wallets; anything that moves funds still shows the approval screen.
Medium
- M1 — No way to cancel an open match (creator's wager stuck until someone
joins). Fixed: "Cancel match and refund" (
abort_match). - M2 — Match creation took two wallet approvals (ATA prep, then create). Fixed: one transaction. Settlement likewise.
- M3 —
/api/matchesreturned 500 onpage=0/bad paging (no schema). Fixed: validated query. - M4 — First win never set
longest_win_streak. Fixed. - M5 — CORS didn't allow
DELETE. Fixed (needed for cancelling predictions). - M6 — Delegation polling every 500 ms with up to 3 RPC calls per tick. Raised to 1 s.
Open — needs a program upgrade
These can't be fixed from the client or backend; the sponsor policy above contains them for sponsored transactions, but self-paid transactions are still exposed.
- P1 —
close_matchhas no authorization. Anyone can close a settled match and take its rent (close = payer, payer unconstrained). Store the rent payer onChessMatchand require it (or the sponsor) as the destination. - P2 —
process_match_settlement.payeris unchecked. Anyone can settle (fine) but also redirect the escrow's rent. Constrain the rent destination to the original funder. - P3 —
abort_matchrefunds escrow rent to the creator even when the sponsor paid it, and theChessMatchaccount is never closed on abort, so its rent is locked forever. Close it on abort and refund rent to the funder. - P4 —
DelegateConfig::default()leaves the validator unspecified; pin the intended ER validator (or pass it in) so routing is deterministic.
Operational notes
- The backend's default
RPC_ENDPOINTis the public devnet RPC, which rate-limits; the chain indexer polls live matches every 3 s, so pointRPC_ENDPOINTat a dedicated devnet RPC on Render. window.__magicChessdebug hooks remain for the automated cross-browser scripts; they only act as the signed-in user in their own browser.