Repository navigation
Zod 4 under a strict CSP: jitless to stop securitypolicyviolation reports (CurlShot) #6671
SergiuPogor
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
A small Zod 4 tip from production, in case someone else sees the same console noise.
Symptom. On CurlShot (a screenshot API; the site is Next.js), the production Content-Security-Policy has no
'unsafe-eval'. Zod 4 compiles a fast object parser withnew Functionand first probes whether eval is allowed. The probe is blocked and the error is swallowed, so parsing works, but the browser still fires asecuritypolicyviolation(and CSP reports) on every page that parses a schema.Fix. Turn on
jitlessonce, before the first schema is parsed:jitlessskips both the probe and the compiled path. Two details that mattered for us:instrumentation-client.ts), the root client provider, the serverinstrumentation.ts, and the schema entry points.configfromzod/v4/core(the module that owns the config object Zod reads) keeps this file to a few hundred bytes in the shared client chunk, instead of pulling the whole schema library into every page.Since then there are no CSP violations from Zod. Thanks for Zod 4 and for making this a one-line option.
All reactions