Skip to content

Fix the blank environment page: precompile the config validator for the CSP - #189

Merged
samuelmbabhazi merged 1 commit into
mainfrom
fix/config-validator-csp
Nov 7, 2026
Merged

samuelmbabhazi merged 1 commit into
mainfrom
fix/config-validator-csp

Conversation

@samuelmbabhazi

Copy link
Copy Markdown
Collaborator

What changed

The shipkeep.yml validator is now compiled at generation time (pnpm gen:config → packages/config-schema/src/gen/validator.ts) instead of at runtime. Ajv's standalone output needs two small helpers, which live in validator-runtime.ts, so Ajv itself no longer reaches the web bundle.

Why

The environment page has been blank in real browsers since #169. That page holds application creation, and everything after it is reached through it.

Ajv's runtime compiler builds functions from strings. The production CSP (script-src 'self', no unsafe-eval) refuses that, so the module threw EvalError when loaded and the route rendered nothing. jsdom does not enforce CSP, so every unit test passed, and with CI off the browser suite never ran. A real Chromium run caught it today.

Allowing unsafe-eval was not considered: the CSP is doing its job, and that would weaken it for the whole UI.

How it was tested

  • Guard test csp.spec.ts: refuses Function and eval, then loads and validates. It fails on the old code with EvalError and passes now, so jsdom can no longer hide this.
  • All golden fixtures, valid and invalid, pass through the generated validator (89 tests).
  • Real Chromium, against the production build, API and a local PostgreSQL 18.4: the environment page renders under the production CSP. That spec arrives in the next PR, with M2.3f2.
  • Local gate, including the generation drift check.

The same schema now validates on the API through the generated code, which the integration suite exercised before this change only through the old path. The fixtures cover the new path; the suite should be rerun with CI-1.

Security considerations

The CSP is unchanged. The generator refuses output containing require(, new Function or eval(. deepEqual and ucs2length are new hand-written code on validation paths, with their own tests, including lone surrogates.

Checklist

  • Tests, including a regression guard
  • No new shell invocation, no new secret exposure path
  • Generated code comes from the schema, not edited by hand (rule 9)
  • No new state change

… CSP

Ajv's runtime compiler builds functions from strings. The web UI's CSP refuses that, so the environment page threw at load and rendered blank in real browsers. jsdom does not enforce CSP, so every unit test passed.

Signed-off-by: review <[email protected]>
@samuelmbabhazi
samuelmbabhazi merged commit 618c732 into main Nov 7, 2026
@samuelmbabhazi
samuelmbabhazi deleted the fix/config-validator-csp branch November 7, 2026 12:32
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