We recently discovered that AJV relies on eval which prevented us from using our framework due to its reliance on JsonForms but only on certain environments where eval is restricted due to CSP policy. This was like a landmine that exploded in our face after a year of investment into a json forms based framework.
This was a blocker for one org to use our framework, and we fought hard to allow eval in their CSP but we were forced to deliver a solution that was less than ideal which involved creating a custom AJV-like function which matches the signatures of AJV in its limited use by json forms but does not use eval.
Prior to creating our own AJV that doesn’t rely on eval, I did a search for solutions. The only thing I found was a possible precompiled validator function using ajv which, from what I understood, required a schema that was statically defined at build time. This of course would not work for us because the schemas are almost never static and come from APIs which are generated from customer-defined data models.
I’m writing here for a few purposes:
-
Check for any better solutions which don’t require schemas to be static
-
Check if someone can explain the reason why AJV uses eval? This might not be the best place to ask, but it seemed like a bad decision to use eval here, since json schemas don’t contain JavaScript snippets that need to evaluated, and now we just need to trust that ajv doesn’t accidentally evaluate XSS in user controllable schemas.
-
Check how well-known is this limitation of jsonforms, if it’s not prominently displayed anywhere that jsonforms depends on AJV which requires a certain CSP policy to run - that should probably be added in my opinion.
-
Check on interest for our custom ajv that can be substituted at least for limited usages of draft 7. I feel like if jsonforms came with this as an option it might help others who need to run json forms on a restricted CSP.