Skip to content

fix: validate forms without unsafe-eval - #30

Merged
Bhavesh-Suvalaka merged 2 commits into
mainfrom
fix/form-validation-without-eval
Nov 4, 2026
Merged

Bhavesh-Suvalaka merged 2 commits into
mainfrom
fix/form-validation-without-eval

Conversation

@Bhavesh-Suvalaka

Copy link
Copy Markdown
Contributor

What changed

  • The form validates with @cfworker/json-schema through a small adapter in src/lib/forms/validator.ts. It reads the schema instead of compiling it, so it runs under the container's Content Security Policy.
  • @rjsf/validator-ajv8 stays installed only because @rjsf/core imports it for a test helper without declaring it. Nothing in src uses it.
  • ADR-0001 records the decision. nginx.conf is unchanged.

Why

Ajv builds its validator with new Function. The container serves the client with script-src 'self', which refuses that, so every form submit failed with "Error compiling schema". The Vite dev server sets no policy, which is why this never showed locally.

How it was verified

  • npm test: 100 tests pass, including the existing form view tests that submit bad values and read the messages. Four new tests pin the adapter's error shape.
  • npm run typecheck, npm run lint, npm run knip pass.
  • Built the image with docker compose up --build, pointed it at a dev Experience API, and submitted a PMFBY grievance form under the real CSP. It submitted.

🤖 Generated with Claude Code

Bhavesh-Suvalaka and others added 2 commits November 3, 2026 17:24
Ajv builds its validator with new Function, which the container's CSP
refuses, so every form submit failed with "Error compiling schema".
The form now validates with @cfworker/json-schema, which reads the
schema instead of compiling it. The policy is unchanged. ADR-0001.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@Bhavesh-Suvalaka
Bhavesh-Suvalaka merged commit d6d4a2c into main Nov 4, 2026
4 checks passed
@Bhavesh-Suvalaka
Bhavesh-Suvalaka deleted the fix/form-validation-without-eval branch November 4, 2026 04:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant