fix: cap wall flags and scene extra as opaque objects (#35)

One shared validator next to the property caps: 8 KB serialized, 64 keys
per object, depth 8 (top-level object = 1). At a cap is accepted; over
is invalid and applies nothing. Both call sites use it, and a refusal is
logged once with the field and limit, never the value. Token flags and
props keep their existing rules; stored over-cap rows still load as
stored.
This commit is contained in:
2026-11-20 21:46:53 +01:00
parent 41c2fe695b
commit b0e1633aa9
9 changed files with 264 additions and 8 deletions
+12
View File
@@ -541,6 +541,12 @@ proc declared(env: Envelope, key: string): bool =
## `vision_radius: null` means "the scene default" (6.1), so both are real patch fields.
not env.node.isNil and env.node.hasKey(key)
proc opaqueRefused(field: string, node: JsonNode) =
## #35: one structured line naming the field and the limit it broke, never the contents.
let limit = props.checkOpaqueObject(node)
if limit != props.olOk:
app.lg.log(lvInfo, "opaque_refused", [("field", field), ("limit", props.limitName(limit))])
# Wall payload fields (DESIGN 6.1, proto 2, #54). `kind` and (in an update) `open` are never read:
# they are unknown fields and ignored (6.2). Absent and JSON null are the same field-absent for
# every wall field except `height` and `label`, where an explicit null means "clear it".
@@ -638,6 +644,8 @@ proc parseWallPatch(env: Envelope, patch: var WallPatch, allowOpen = false): boo
if present(env, "flags"):
let f = parseFlags(env.node{"flags"})
if f.isNone: return false
# #35: wall `flags` is opaque but bounded (token `flags` keeps its old, uncapped path).
if props.checkOpaqueObject(f.get) != props.olOk: return false
patch.flags = f
true
@@ -1993,6 +2001,8 @@ proc dispatch(conn: Conn, env: Envelope) {.gcsafe.} =
if not sceneOk(conn, env): return
var patchOpt = parseScenePatch(env.node)
if patchOpt.isNone:
if not env.node.isNil and env.node.hasKey("extra"):
opaqueRefused("extra", env.node{"extra"})
ackErr(conn, env.reqId, CodeInvalid)
return
var patch = patchOpt.get
@@ -2056,6 +2066,7 @@ proc dispatch(conn: Conn, env: Envelope) {.gcsafe.} =
# #55); `a` and `b` are the only required fields here.
var patch: WallPatch
if not parseWallPatch(env, patch, allowOpen = true):
if present(env, "flags"): opaqueRefused("flags", env.node{"flags"})
ackErr(conn, env.reqId, CodeInvalid)
return
if patch.a.isNone or patch.b.isNone:
@@ -2112,6 +2123,7 @@ proc dispatch(conn: Conn, env: Envelope) {.gcsafe.} =
return
var patch: WallPatch
if not parseWallPatch(env, patch):
if present(env, "flags"): opaqueRefused("flags", env.node{"flags"})
ackErr(conn, env.reqId, CodeInvalid)
return
if not wallPatchHasField(patch):