ExodusMovement / schemasafe

A reasonably safe JSON Schema validator with draft-04/06/07/2019-09/2020-12 support.
https://npmjs.com/@exodus/schemasafe
MIT License
155 stars 12 forks source link

Does not work with proper CSP settings #153

Open heinerlamprecht opened 2 years ago

heinerlamprecht commented 2 years ago

After applying proper CSP-settings, the validator does not work anymore. Console shows:

EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script

Unfortunately, "unsafe-eval" is prohibited in lots of governmental organisations or Top-500 companies.

Note: The application connects to a REST-Service and the schemas are not known at build-time. Instead they are downloaded from the REST-API.

ChALkeR commented 1 year ago

@heinerlamprecht Hi! Sorry for the late response.

This can be used with CSP via pre-compiling, as mentioned in the documentation: https://github.com/ExodusMovement/schemasafe#generate-modules

To do this, the schemas should be known prior to runtime, and pre-built. This way, runtime won't need to execute dynamically built validators.

ChALkeR commented 1 year ago

Note: The application connects to a REST-Service and the schemas are not known at build-time. Instead they are downloaded from the REST-API.

Ah, I see.

Are the schemas trusted or not? If yes, they could perhaps be shipped in pre-compiled form via a proxy (perhaps even a separate host)?

Using untrusted schemas could cause DoS even with all the checks, regardless of the validator used.

heinerlamprecht commented 1 year ago

To do this, the schemas should be known prior to runtime, and pre-built. This way, runtime won't need to execute dynamically built validators.

How can I use this compiled module in an application?

ChALkeR commented 1 year ago

How can I use this compiled module in an application?

I'm not sure about the nature of the question, that depends on the exact setup.