You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Lands the second half of #217: bound the JSON-Schema compiler so a
malicious per-field json_schema constraint cannot hang the server on
first compile. Sits on top of #254, which already caps schema doc bytes
and field count at the ingest layer.
- internal/validation/limits.go — new Limits struct (CompileTimeout,
MaxDepth) + DefaultLimits (5 s, depth 64) + shared Option/WithLimits
pattern usable by both the factory and individual field validators.
- internal/validation/json_schema.go — newJSONSchemaValidator now takes
Limits. A pre-compile depth scan rejects pathological nesting before
invoking the compiler; the Compile call itself runs in a goroutine
and is bounded by CompileTimeout. jsonschema/v6 has no CompileContext,
so the timeout is a wall-clock backstop — the goroutine may continue
past the deadline, but the depth scan + upstream MaxDocBytes cap
bound the worst-case work.
- NewValidatorFactory(store, opts...) and NewFieldValidator(..., opts...)
accept the shared Option type; existing zero-opt call sites continue
to compile unchanged.
- cmd/server reads SCHEMA_COMPILE_TIMEOUT (Go duration) and
SCHEMA_MAX_REF_DEPTH env vars and threads them through WithLimits on
the shared validator factory.
Closes#217.
Copy file name to clipboardExpand all lines: docs/server/configuration.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,6 +20,8 @@ OpenDecree is configured entirely through environment variables. No config files
20
20
|`GRPC_MAX_SEND_MSG_BYTES`| Maximum size of an outbound gRPC message, in bytes. Responses above this return `ResourceExhausted` to the client. Set to `0` for the default. |`20971520` (20 MiB) | No |
21
21
|`SCHEMA_MAX_FIELDS`| Maximum number of fields per schema accepted by `CreateSchema` and `ImportSchema`. Requests above this return `InvalidArgument`. Set to `0` to disable. |`10000`| No |
22
22
|`SCHEMA_MAX_DOC_BYTES`| Maximum serialized YAML document size accepted by `ImportSchema`, in bytes. Requests above this return `InvalidArgument`. Set to `0` to disable. |`5242880` (5 MiB) | No |
23
+
|`SCHEMA_COMPILE_TIMEOUT`| Wall-clock cap on a single JSON-Schema compile (per-field constraint). Format: Go duration (e.g., `5s`, `2s`). Set to `0` to disable the timeout. |`5s`| No |
24
+
|`SCHEMA_MAX_REF_DEPTH`| Maximum structural nesting depth of a JSON-Schema constraint document. Schemas deeper than this are rejected before compilation. Set to `0` to disable. |`64`| No |
0 commit comments