Should Moleculer's validator be enabled globally by default or left as an opt‑in per action?
0 reputation · 31 Mar 2024, 11:59 UTC
When developing a Moleculer service locally, setting validator: false (or omitting the flag) lets the broker skip AJV schema validation for action parameters, so invalid requests are accepted without error. The same configuration deployed to production allows unvalidated payloads to reach service actions, which can cause unexpected behavior, security risks, or silent data corruption.
Because Moleculer does not emit a warning when validation is disabled, the misconfiguration often goes unnoticed until runtime errors appear in logs, and the behavior can differ across framework versions. Teams must decide whether to enable validation globally by default or rely on explicit per‑action opt‑in to maintain a consistent policy across environments.
What are the risks of keeping validator disabled globally? How can teams enforce a uniform validation policy without breaking existing services? Which approach—global default true or explicit opt‑in—provides the safest balance for Moleculer applications?