Repository navigation
feat: strict CSP, read-only, host policies, i18n and tree-shakable entries (2.2.0) - #4
Merged
Merged
Conversation
The required `typescript: ^5` peer made TypeScript 6 hosts fail strict peer resolution although the library only needs TypeScript for type-checking and the `./source` export. Declare it as an optional `^5 || ^6 || ^7` peer, the range Nuxt UI uses, and enforce that contract in the package audit.
TypeScript 6 enables `strict` by default, which surfaced three strict-mode errors in shipped sources (also reachable through the `./source` export). Fix them, make `strict` explicit so both majors agree, and add a CI matrix that type-checks and builds the library under TypeScript 5.9 and 6.0.
THIRD_PARTY_NOTICES.md stayed in the repository although the tarball contains JSON Forms derived code and bundles Day.js, whose MIT licenses require the notice to travel with every copy. Publish the file, add the missing Day.js notice and make the package audit require a notice section for every package bundled into dist.
`isDisabled` is false for a read-only control so that widgets with a `readonly` prop stay readable, but checkbox, switch, radio group, select menus, autocomplete, multi-enum and the oneOf variant selector only bound `disabled` and stayed editable. Expose `isLocked` (disabled or read-only), bind it on widgets without `readonly`, refuse user writes from a locked control and hide the WYSIWYG toolbar when the editor cannot edit. Also honour JSON Forms 3.8's separate `readonly` state (READONLY rules, `config.separateReadonlyFromDisabled`) and pass it to nested renderers.
…rors `enableFilterErrorsBeforeTouch` hid every error until blur, including the ones the host passes through `additional-errors`, and only filtered the input color: the wrapper still showed the message. Widgets without blur never revealed their errors. Split errors by origin (`localErrors`, `serverErrors`), keep host errors visible, filter the wrapper message and count a user change as a touch.
A `oneOf: [{ const, title }]` without `options.format` matched the
combinator renderer (rank 3), which rendered each constant as an object
variant with a sub-form, although the guide promised a select menu. Rank
it 5 on the searchable `USelectMenu` renderer, using JSON Forms' oneOf
enum mapping for its items.
The date-time control parsed values with a naive `YYYY-MM-DDTHH:mm:ss` pattern: an RFC 3339 value such as `…T10:30:00+05:30` or `…Z` rendered empty and an edit dropped its offset. Show the wall time in the stored offset with a `UTC±HH:mm` hint, write edits back with that offset, keep naive values naive and stamp new values with the browser's offset at that wall time, as JSON Forms does (`options.dateTimeOffset: 'none'` opts out).
Hosts running offline or under a `connect-src 'self'` CSP must bundle every icon up front, but had to grep the sources to find them. Export `CONTROL_ICONS`, `WYSIWYG_ICONS`, `BUILDER_ICONS` and `LIBRARY_ICONS`, kept in sync with the sources by a test, from the root and from a dependency-free `./icons` entry that a `nuxt.config` can import. Its CJS build uses `.cjs`, since the package is `"type": "module"`.
Nothing proved that the renderers run under a CSP without 'unsafe-inline' or 'unsafe-eval'. Build a page covering every core renderer against the published dist, serve it under a strict CSP and edit every field in Chromium: no violation attributable to the library, no request leaving the origin, and a read-only form (form flag or config) whose data never moves. The recipe showed that JSON Forms compiles every oneOf/anyOf/allOf variant with Ajv on each render, whatever the validation mode, and that file previews are data: URLs. Export `strictCspRenderers`, which leaves those renderers out; two counter-tests keep the 'unsafe-eval' requirement of combinators and Ajv validation visible.
Nuxt UI 4.12 requires Tiptap ^3.31.4 while the lockfile kept the library's extensions on 3.29.2: a 4.12 host got two @tiptap/pm and prosemirror-view copies, which broke the search plugin types and the Markdown round trip. Require ^3.30.5 and relock every @tiptap and prosemirror package on one version each.
Replace the TypeScript-only matrix with the supported host range: the @nuxt/ui peer floor and the current minor, crossed with both TypeScript majors. Each cell type-checks, builds, runs the unit tests and the strict CSP and read-only browser recipe against that Nuxt UI.
A UI schema could make the library fetch any URL, cookies included for the page's origin, although schemas may come from less trusted sources than the host. Read a host policy from JSON Forms `config.apiPolicy`, never from the UI schema: a `resolve` callback runs every request, or `allowedOrigins` lists the origins the library may fetch without cookies. Without a policy, same-origin requests behave as before and other origins are refused. Relative URLs without `base` now resolve against the page.
The oneOf/anyOf renderer read its state through useJsonFormsOneOfControl, which compiles every variant with Ajv on each render to find the matching one: a CSP without 'unsafe-eval' refused it, whatever the validation mode. The renderer already picks its variant with detectOneOfVariant, so read the plain control state instead. strictCspRenderers now only leaves file upload out (blob: previews). Tighten the browser recipe after review: allow only the exact hash of Nuxt UI's colors style and require zero violations, compare full origins, check the served CSP, add the same-origin autocomplete, a label, a LEAF rule, host errors through additional-errors and deterministic edits, and replace the combinator counter-test with a schema-condition rule one.
…fused
Review of the host policy found gaps: an allowed endpoint could redirect
the typed term to another origin, the page's own routes stayed reachable
with its cookies whatever the policy, merged options could pair host
config.api headers with a URL the schema chose, schemas could send any
header, and the host resolver received unchecked URLs.
Send nothing without a policy ('self' allows the page's origin with its
cookies), refuse redirects, take the api object whole from the schema or
from the raw config, keep only CORS-safelisted schema headers unless the
host allows more, check scheme and embedded credentials before both the
resolver and fetch, ignore a mistyped allowedOrigins and set the search
term after fixed params.
The library shipped one bundle without `sideEffects`: a form without rich text still pulled the WYSIWYG renderer and Tiptap into the host bundle. Build one entry per area with shared chunks, declare `"sideEffects": false` and publish `./core` (renderers without any Tiptap import), `./advanced` (WYSIWYG, `allRenderers`) and `./builder`; the root keeps re-exporting everything. CommonJS entries use `.cjs`. The strict CSP recipe now loads `./core` and checks that its bundle holds no Tiptap or ProseMirror code; it shrank from 591 kB to 376 kB gzipped.
Categorization wrote `#tab=…` into the page URL, which belongs to the host: it clashes with hash-based routers and lets a UI schema alter the URL. Keep the active category in memory and sync with location.hash only with `options.urlHash: true` (also read from the JSON Forms config). BREAKING CHANGE: the active category no longer survives a reload or a shared link unless `options.urlHash: true` is set.
<FormBuilder> saved every draft (schema, UI schema and preview data) to localStorage under a fixed key, so a host embedding it left form data in the browser without asking. Persist nothing by default; `storage-key` takes a key, or `true` for the historical one. The playground opts in. BREAKING CHANGE: pass `:storage-key="true"` (or a key) to keep saving drafts in localStorage.
radash has not been published since 2025-06-18 and the library used nine trivial functions from it. Replace them with internal helpers that keep the exact radash 12.1.1 contracts, covered by tests, and drop the runtime dependency.
The WYSIWYG renderer imports @tiptap/core, pm, vue-3 and extension-image without declaring them, relying on Nuxt UI's install: a strict installer such as pnpm could not resolve them, nor share Nuxt UI's instance. Declare them as optional ^3.30.5 peers and make the package audit reject any runtime import of src that the manifest does not declare.
Buttons, confirmations, placeholders, date pickers, upload, WYSIWYG, AI assistant and builder texts were hardcoded in French. Route them through the JSON Forms translator under `jsonformsBuilder.*` keys, with French and English catalogs (`UI_MESSAGES`): `createJsonFormsTranslator` returns them once given a `locale`, host `messages` override any of them, and the French texts stay the default without translator. Calendars follow the `jsonformsBuilder.locale` key. `<FormBuilder>` gains `locale` and `translate` props, also passed to its preview. Label helpers take an optional translator; exported constants keep their French values. The browser recipe renders the form in English and checks that no French library text remains.
The tree-shakable entries ship one ES and one CommonJS chunk set, each with source maps and declarations, and the interface texts now come in French and English: the library tarball grows from 688 kB to 815 kB packed and 3.88 MB unpacked. Hosts load less code, though: a page on the ./core entry drops from 591 kB to 387 kB gzipped. Raise the budgets to 900 kB packed and 4.25 MB unpacked.
Welcome to Codecov 🎉Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests. ℹ️ You can also turn on project coverage checks and project coverage reporting on Pull Request comment Thanks for integrating Codecov - We've got you covered ☂️ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Prepares the 2.2.0 minor release. Stacked on #3 (2.1.1): merge #3 first; this PR then shows only its own 19 commits. It targets
mainso that CI runs.Behavior changes (each with an opt-in back to the former behavior, listed in the changelog):
options.apisends no request without a host policy inconfig.apiPolicy('self'/ exact origins inallowedOrigins, or aresolvecallback); redirects refused, UI-schema headers limited to CORS-safelisted ones unlessallowedHeaderssays otherwise.Categorizationno longer writes#tab=…into the page URL (options.urlHash: truerestores it).<FormBuilder>persists no draft by default (:storage-key="true"restores the historical key).date-timevalues get the browser's offset, as JSON Forms does (options.dateTimeOffset: 'none'keeps naive values).createJsonFormsTranslator({ locale })now also returns the interface texts.Features
/core(no Tiptap import),/advanced,/builder,/icons, with"sideEffects": false; the root keeps re-exporting everything. A page on/coregoes from 591 kB to 387 kB gzipped.strictCspRenderersand a documented strict CSP recipe (no'unsafe-inline','unsafe-eval',data:orblob:).jsonformsBuilder.*keys);<FormBuilder>getslocaleandtranslate.CONTROL_ICONS…) from a dependency-free/iconsentry.useUiControlexposesisLocked,localErrors,serverErrors.Fixes
oneOfselector stayed editable), JSON Forms 3.8readonlystate included.additional-errorskept apart from local errors and visible before touch;enableFilterErrorsBeforeTouchnow hides the message, not only the color.oneOfof constants rendered as a searchable select;oneOf/anyOfno longer compile every variant with Ajv on each render.date-timevalues with an offset were shown empty and lost their offset.^3.30.5peers; Tiptap floor raised to^3.30.5on a single relocked version.Internal:
radashreplaced by internal helpers; CI matrix Nuxt UI 4.10/4.12 × TypeScript 5.9/6.0, each cell running type-check, build, unit tests and a Chromium recipe (strict CSP, read-only, server errors, English UI,/corewithout Tiptap); package audit checks entries,sideEffectsand undeclared imports; size budgets raised to 900 kB packed / 4.25 MB unpacked.Not in this PR: moving the five Tiptap extensions (
highlight,list,table,text-align,text-style) from dependencies to optional peers. The root still imports them, so it would break hosts importing the root; it belongs with a 3.0 where the root becomes/core.Verification
Locally:
yarn lint,yarn typecheck,yarn test:coverage(746 tests, 95.5 % lines),yarn test:scripts,yarn docs:build,yarn changelog:check,yarn package:check,yarn test:browser(10/10), all green. The Nuxt UI 4.12.2 × TypeScript 6.0.3 cell was replayed in a clean copy: one@tiptap/pmcopy, build, unit tests and browser recipe green. The browser recipe fails on the code before the read-only andoneOffixes (data edited in aconfig.readonlyform, 460evalviolations).