feat(world-builder): stage 5 user map sandbox with ownership and quotas (#88) - #108
feat(world-builder): stage 5 user map sandbox with ownership and quotas (#88)#108Rodrigoue9 wants to merge 2 commits into
Conversation
| export async function getUserMapQuota(accountId: number): Promise<UserMapQuota> { | ||
| const res = await pool.query( | ||
| `SELECT COUNT(*)::int AS "mapsCount", | ||
| COALESCE(SUM(asset_bytes), 0)::bigint AS "totalAssetBytes", | ||
| COALESCE(SUM(npc_count), 0)::int AS "totalNpcs", | ||
| COALESCE(SUM(object_count), 0)::int AS "totalObjects" | ||
| FROM user_maps | ||
| WHERE account_id = $1 AND status != 'archived'`, | ||
| [accountId] | ||
| ); | ||
| const row = res.rows[0] || {}; | ||
| return { | ||
| mapsUsed: row.mapsCount || 0, | ||
| maxMaps: DEFAULT_MAX_USER_MAPS, | ||
| assetBytesUsed: Number(row.totalAssetBytes || 0), |
There was a problem hiding this comment.
💡 Quality: Asset/NPC/object quotas computed but never enforced
getUserMapQuota reports maxAssetBytes, maxNpcCount, and maxObjectCount, and the PR description claims these limits are enforced, but createUserMap only checks mapsUsed >= maxMaps. The asset/NPC/object limits are never actually enforced on any write path. Either enforce them when maps/assets are added or remove the misleading claim.
Was this helpful? React with 👍 / 👎
Code Review 👍 Approved with suggestions 6 resolved / 7 findingsAdds user map sandbox with ownership controls and database migrations, resolving multiple security flaws and race conditions. Consider enforcing computed asset, NPC, and object quotas during map creation, as only the map count limit is currently checked. 💡 Quality: Asset/NPC/object quotas computed but never enforced📄 api/src/repositories/userMaps.ts:34-48 📄 api/src/repositories/userMaps.ts:71-74
✅ 6 resolved✅ Security: requireAuth never sets request.user; all maps use accountId 1
✅ Bug: createUserMap id allocation & quota check are racy (TOCTOU)
✅ Bug: user_maps table has no migration/schema definition
✅ Security: GET /internal/user-maps/:id lacks ownership check (IDOR)
✅ Bug: status transition value is not validated
...and 1 more resolved from earlier reviews 🤖 Prompt for agentsOptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Gitar |
Title
feat(world-builder): stage 5 user map sandbox with ownership and quotas (#88)
Description
api/src/repositories/userMaps.tssupporting creation and lifecycle of custom maps in isolated range (600-1999).checkMapOwnership.Closes #88