fix(contracts): set zod jitless before any schema is built so the production csp sees no eval (F-7, 13-08)

zod probed Function("") on its first object schema, which the production CSP
(no unsafe-eval) reported on every boot. Schema code now imports z from
src/contracts/zod.ts, enforced by a dependency-cruiser rule, and the CSP smoke
drops its init-script workaround.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
donghyeon-ka
2026-09-27 12:58:57 +09:00
co-authored by Claude Opus 5.5
parent 606c191941
commit 9dc95ca066
16 changed files with 74 additions and 32 deletions
+7 -8
View File
@@ -9,14 +9,13 @@ verification compares that declaration with live responses. CSP deliberately
omits `unsafe-inline` and `unsafe-eval`; production code and built assets must
remain compatible with that baseline. `tests/e2e/production-csp.spec.ts` (part of
`test:e2e`, FE-GATE-008) serves the build with these headers and fails on a
`securitypolicyviolation` event or console error (review 13-08). One
violation is known: zod probes `Function("")` on its first object schema and
the policy refuses it. Parsing still works, but the default build reports the
violation on every boot until zod is configured `jitless` before the first
schema is built. `z.config` in the entry module is too late, because the
bundler evaluates the shared chunks that build schemas first. The smoke sets
zod's global config before page scripts run so it can catch every other
violation; the spec comment names when to remove that. Features that are off by
`securitypolicyviolation` event or console error (review 13-08). zod probes
`Function("")` on its first object schema, which the policy would report on
every boot. `src/contracts/zod.ts` sets `jitless` to skip that probe, and every
module that builds a schema imports `z` from there, so the setting is applied
before the first schema whatever order the bundler evaluates chunks in.
`z.config` in the entry module would be too late. Import `z` from
`src/contracts/zod.ts`, not from `zod`, in new schema code. Features that are off by
default need CSP additions when a project selects them; see step 9 in
[optional adapter recipes](../architecture/optional-adapter-recipes.md).
`connect-src 'self' https:` lets script reach any HTTPS origin. Narrowing it to