From ce7ad43e3c99fa2e1b32579074e1d72990eac3c0 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 23:31:35 -0500 Subject: [PATCH] Modes: reject non-hostable keywords (obscure) in mode rules; document card-input boundary Co-Authored-By: Claude Opus 5.5 --- docs/game/HOSTING.md | 5 ++++- server/game/engine-binding.ts | 4 ++++ tests/modes-api.test.ts | 3 +++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/docs/game/HOSTING.md b/docs/game/HOSTING.md index 3236548..73c50ac 100644 --- a/docs/game/HOSTING.md +++ b/docs/game/HOSTING.md @@ -153,7 +153,8 @@ A mode is rejected at node startup, never handed to the engine half-checked, if: - the merged ruleset fails the engine's strict `parseRuleset`, or - it fails the host-side checks in `server/game/engine-binding.ts`: `distinctStats` requires `topicCount` 3; every `portalReveal` turn ≤ `turns`; `energyByTurn` has an entry per turn; - `turns × turnSeconds ≤ 240`; `powerByCost` has 7 entries; or + `turns × turnSeconds ≤ 240`; `powerByCost` has 7 entries; no keyword whose hidden information + `viewFor` doesn't mask yet (`obscure`) is enabled; or - its deck policy can't produce legal decks (starter decks illegal under its rules, or a draft pool smaller than 2 × `deckSize`). @@ -184,6 +185,8 @@ requests in any request or match path**: - **Sybils and win-trading:** anyone can make a new player id, and two ids controlled by the same person can feed each other wins. Tonight's leaderboards are for fun. Accounts (#7) or wallet-signed identities would raise the cost. +- **Card input.** The host builds every deck from shipped engine data (starter decks and the + loaner pool). It never accepts cards, `check` values or pinned stats from client JSON. - **Card stats.** Card numbers come from the engine's card mapping. Minted stats are self-reported by the minter (see council-critic in #3); a mode can only pick a mapping preset, not supply numbers. diff --git a/server/game/engine-binding.ts b/server/game/engine-binding.ts index 5d7267e..695a994 100644 --- a/server/game/engine-binding.ts +++ b/server/game/engine-binding.ts @@ -21,6 +21,8 @@ export function previewPool(rules: Ruleset, seed: string, size: number): GameCar * The engine's strict parseRuleset, plus host-side checks that keep a hosted mode playable * (requested in review on #6). Anything that fails is rejected at startup, never passed on. */ +export const UNSAFE_KEYWORDS: readonly string[] = ['obscure']; + export function parseModeRuleset(value: unknown): Ruleset { const rules = parseRuleset(value); const problems: string[] = []; @@ -29,6 +31,8 @@ export function parseModeRuleset(value: unknown): Ruleset { if (rules.energyByTurn.length < rules.turns) problems.push('energyByTurn needs one entry per turn'); if (rules.turns * rules.turnSeconds > 240) problems.push('turns × turnSeconds must be ≤ 240'); if (rules.powerByCost.length !== 7) problems.push('powerByCost needs 7 entries'); + // Keywords whose hidden information viewFor doesn't mask yet would leak cards to the opponent (#6, #27). + for (const id of UNSAFE_KEYWORDS) if ((rules.keywordsEnabled as readonly string[]).includes(id)) problems.push(`keyword "${id}" is not hostable yet (viewFor does not mask it)`); if (problems.length) throw new Error(`Invalid mode rules: ${problems.join('; ')}`); return rules; } diff --git a/tests/modes-api.test.ts b/tests/modes-api.test.ts index bf8a574..4cc4faa 100644 --- a/tests/modes-api.test.ts +++ b/tests/modes-api.test.ts @@ -200,7 +200,10 @@ test('modes api: mode rules are checked beyond the engine schema and rejected, n { powerByCost: [0, 1, 2] }, { mulligan: true }, { keywordParams: { notAKeyword: { amount: 1 } } }, + { keywordsEnabled: [...DEFAULT_RULESET.keywordsEnabled, 'obscure'] }, ]; for (const rules of bad) assert.throws(() => resolveRuleset(DEFAULT_RULESET, rules as any, parseModeRuleset), JSON.stringify(rules)); + assert.throws(() => resolveRuleset(DEFAULT_RULESET, { keywordsEnabled: ['viral', 'obscure'] }, parseModeRuleset), /not hostable/); + assert.doesNotThrow(() => resolveRuleset(DEFAULT_RULESET, { keywordsEnabled: ['viral', 'edition', 'wildcard'] }, parseModeRuleset)); assert.doesNotThrow(() => resolveRuleset(DEFAULT_RULESET, {}, parseModeRuleset)); });