Skip to content

Entities 0.2.11: Crafted form data can no longer break a record

Entities 0.2.11 closes a set of holes where a crafted request could store a value that made a record impossible to display, or crash the public form before any check ran.

A text, text area or rich text field could be sent a structured value instead of text. It was saved, and from then on every page showing that record crashed for every viewer, with no fix short of editing the database. Such values are now dropped when they enter the form and refused when saved, from the admin, the embedded form and the public form alike. The “Other” answer of choice fields must now be text too, and the embedded form no longer takes file, image or relation values from a submission.

The read-only view now shows an odd stored value as plain text instead of crashing, so records already affected can be opened again.

The public form, which needs no sign-in, also crashed with a server error on four kinds of malformed requests before its checks ran. They are now treated as empty values, as are malformed autosave and submit messages in the embedded form.

Full release notes: Entities 0.2.11

0.2.11 · 6 August 2026

Fixed

  • Crafted data payloads could store a non-scalar value that then permanently broke rendering for a record. LiveDataForm.whitelist_known_fields/2 filtered submitted params by key only, and FormBuilder.validate_type/2‘s catch-all accepts any term for the types it doesn’t special-case, so a map (or a list of maps) could land under a text/textarea/rich_text key. Every surface that renders one stringifies it naively — to_string/1 in the readonly view, bare {@value} inside <textarea> in the edit form — and both raise Protocol.UndefinedError on a map, crashing the page for every subsequent viewer with no fix short of a manual DB edit. Closed at two layers: a new per-field-type value-shape gate (LiveDataForm.sanitize_values/2) drops a mis-shaped value at the point data enters the component, leaving the previously-stored value intact, and EntityData.changeset/2 — the final, caller-independent word on what lands in data, also reachable from the admin DataForm and the public form — now rejects a non-scalar for those types outright. (#25)
  • The allow_other escape hatch accepted any term as a “custom” answer. EntityData.validate_choice_field/3 and validate_checkbox_field/3, plus FormBuilder.validate_type/2’s checkbox clause, waved through any out-of-options value once allow_other was set — a map included. allow_other means one free-text custom entry, so an out-of-options value (or list element) must now also be a binary. This path is reachable from the public, unauthenticated form, where the changeset is the only gate. (#25)
  • A malformed "autosave"/"submit" payload crashed the whole LiveView process, not just the component. %{"phoenix_kit_entity_data" => data_params} constrains only the outer payload, so a crafted pushEventTo with a non-map data_params reached Map.get/3 and raised BadMapError; a present-but-non-map "data" value raised the same way inside normalize_absent_checkboxes/2. Both now fall through to the existing empty-autosave clause. (#25)
  • The error message that rejects a bad checkbox value crashed while being built. Enum.join(invalid_values, ", ") in both EntityData.validate_checkbox_field/3 and FormBuilder.validate_type/2 called to_string/1 on the very non-binary term the new guards route into that list — trading a stored bad value for an attacker-triggered Protocol.UndefinedError. Now Enum.map_join/3 with an inspect/1 fallback. (#25)
  • file fields were the one field type both new shape gates missed, and they are rendered. Nothing in this library produces file data (the build_field/3 clause is an upload placeholder), so every value under a file key arrives from outside — including the unauthenticated /entities/:entity_slug/submit POST when the field is listed in public_form_fields. A stored map reached LiveDataForm’s readonly catch-all (to_string/1), and a stored list of plain strings reached file["filename"] in the edit form, where the Access syntax raises FunctionClauseError on a binary — the same permanent, un-renderable record the rest of this release closes. LiveDataForm now drops values submitted under file/image/relation keys (none render a submittable input), and FormBuilder.build_field/3’s file clause skips non-map entries. (#25 follow-up)
  • LiveDataForm’s readonly view now degrades instead of raising on any already-stored value. The write-side gates above only govern new writes — rows poisoned before them, rows written by a parent app calling EntityData directly, and anything under a file key still hold whatever they hold, and the readonly view is where those get rendered. readonly_text/1, readonly_value/1, readonly_list/1’s join and the select/radio clause (whose translated_option_label/3 deliberately falls back to the raw stored value) all route through a total safe_string/1 — inspect/1 for anything without a String.Chars implementation. This is what makes an already-poisoned record viewable again. (#25 follow-up)
  • Four crafted-payload crashes in the public form controller, all reached before the changeset gate. EntityFormController.submit/2 is un-authed by design, so the whole body is attacker-shaped and nested params arrive as maps: get_in(params, ["phoenix_kit_entity_data", "data"]) raised on a non-map phoenix_kit_entity_data, a non-map "data" hit merge_other_params/2’s is_map/1 clause head, a map under name/title/subject/email reached String.downcase/1 via generate_slug/1, and a non-string _form_loaded_at reached DateTime.from_iso8601/1 inside the security-check phase. Each was an unauthenticated 500 before EntityData.changeset/2 — the gate this path relies on — ever ran. All four now degrade to the ordinary empty/absent-value path. (#25 follow-up)
  • Removed eight orphaned mix.lock entries (igniter, sourceror, rewrite, spitfire, owl, glob_ex, ex_ast, text_diff) left by the previous dependency bump, which had mix deps.unlock --check-unused — and therefore mix precommit — failing on main.
  • test/phoenix_kit_entities/html_sanitizer_test.exs no longer pins the exact byte output of PhoenixKit.Utils.HtmlSanitizer (a dependency). The upgraded sanitizer adds rel="noopener noreferrer" to links and inserts the implied <tbody> in tables — both upstream hardening, not regressions — which had two tests failing on main. They now assert that the element and its safe attributes survive.

Entities 0.2.11. Install or update: {:phoenix_kit_entities, "~> 0.2"}, then mix deps.get && mix phoenix_kit.update. Full history: CHANGELOG.