-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## The bug is the binary clause of `attributes_markup/1`\n\nCVE-2026-8467 is twelve lines of Elixir. The function lives in `lib/phoenix_storybook/rendering/component_renderer.ex` at commit `e35379d` (the parent of the fix commit, `56ab846`). It accepts a list of `{name, value}` tuples and returns a single string that becomes part of a HEEx template the renderer is about to compile and evaluate.\n\n```elixir\ndefp attributes_markup(attributes) do\n Enum.map_join(attributes, \" \", fn\n {name, {:eval, val}} ->\n ~s|#{name}={#{val}}|\n\n {name, val} when is_binary(val) ->\n ~s|#{name}=\"#{val}\"|\n\n {name, val} ->\n ~s|#{name}={#{inspect(val, structs: false, limit: :infinity, printable_limit: :infinity)}}|\n end)\nend\n```\n\nThree clauses, three destinations in HEEx's attribute grammar.\n\nThe first clause handles values the story author has tagged as `{:eval, val}` to mean \"this is Elixir source.\" It emits `name={val}`. The string between the braces is parsed by HEEx as an inline Elixir expression. Authors opt into this clause by writing it in the story file; the value is author-controlled at story-definition time, not runtime.\n\nThe third clause is the catch-all. It runs `inspect/2` over the value and emits `name={...}`, where the bytes between the braces are whatever `inspect/2` returned. `inspect/2` on a number returns the number's decimal form. `inspect/2` on an atom returns the atom literal with a leading colon. `inspect/2` on a list returns a bracket expression. Each of those is valid Elixir source that HEEx's expression slot accepts unmodified. The slot expects parseable Elixir; `inspect/2` produces parseable Elixir; the round-trip works. `inspect/2` would have worked on binaries too, returning a quoted Elixir string literal with `\"` characters escaped, but binaries do not reach this clause because the second one matches first.\n\nThe second clause is the bug. It matches binary values, the only attribute type the playground's WebSocket caller can produce as raw text. It emits `name=\"\"`. The two `\"` characters are typed directly into the source string by `~s|...|`. There is no escape over the value, no encoding pass, no call to a HEEx-attribute primitive of any kind. Whatever bytes are in `val` end up between two `\"` that the source string declared.\n\nTwo clauses route the value through HEEx's expression slot. The binary clause typed the quotes into the literal slot.\n\n## The exploit primitive\n\nThe entry point is `PhoenixStorybook.Story.PlaygroundPreviewLive.handle_event/3`. The function is plain LiveView code with no auth guard and no `on_mount` hook that checks a session:\n\n```elixir\ndef handle_event(\"psb-assign\", assign_params, socket = %{assigns: assigns}) do\n variation_attributes =\n for {variation_id, attributes} <- assigns.variations_attributes, into: %{} do\n {new_variation_id, new_attributes} =\n ExtraAssignsHelpers.handle_set_variation_assign(\n assign_params,\n assigns.variations_attributes,\n assigns.story\n )\n\n if new_variation_id == variation_id do\n {variation_id, new_attributes}\n else\n {variation_id, attributes}\n end\n end\n\n send_variations_attributes(assigns.topic, variation_attributes)\n {:noreply, assign(socket, variations_attributes: variation_attributes)}\nend\n```\n\n`handle_set_variation_assign/3` (in `lib/phoenix_storybook/helpers/extra_assigns_helpers.ex`) reads `params[\"variation_id\"]`, looks up the matching variation, iterates the rest of the params, and stores each `attr => value` pair in the variation's attribute map verbatim. The string value is now a binary attribute on the rendering context.\n\nThe renderer's next pass calls `ComponentRenderer.render/1`, which calls `component_heex/5`, which calls `attributes_markup/1`. The binary clause matches. The output is `=\"\"`. The renderer concatenates that string into a larger HEEx template, then:\n\n```elixir\ndefp render_component_heex(fun_or_mod, heex, opts) do\n quoted_code =\n EEx.compile_string(heex,\n engine: TagEngine,\n caller: __ENV__,\n source: heex,\n tag_handler: Phoenix.LiveView.HTMLEngine\n )\n\n # ... env with Kernel requires/macros ...\n\n {evaluated, _, _} =\n Code.eval_quoted_with_env(quoted_code, [assigns: %{}], env)\n\n LiveViewEngine.live_to_iodata(evaluated)\nend\n```\n\n`EEx.compile_string/2` parses the HEEx template. When it reaches the attribute the bug controls, the grammar reads the opening `\"`, scans bytes until the next unescaped `\"`, and treats whatever follows that next `\"` as a continuation of the tag, the next attribute, or the closing of the tag. The grammar's state machine does not know that the second `\"` was inside the value's source bytes; in the compiled string, the byte and the delimiter are the same character.\n\nThe regression test the fix added documents the canonical payload as one line:\n\n```elixir\npayload =\n ~s|safe\" injected={send(Process.whereis(#{inspect(process_name)}), :rce)} bar=\"|\n```\n\nWalk that across the compiler. The attribute the LiveView is rendering becomes:\n\n```\nlabel=\"safe\" injected={send(Process.whereis(:playground_rce_42), :rce)} bar=\"\"\n```\n\n`EEx.compile_string/2` sees: `label` set to the string `\"safe\"`, then a second attribute `injected` whose value is an inline Elixir expression, then a third attribute `bar` set to the empty string. The second attribute's expression is compiled into the quoted tree. `Code.eval_quoted_with_env/3` runs the tree with `Kernel` in scope. `send/2` is in `Kernel`. The test process receives `:rce`.\n\n`send/2` is the regression test's payload because it is the smallest verifiable side effect. The same slot accepts `System.cmd/2`, `File.write!/2`, `Code.eval_string/1`, or anything else `Kernel` exposes. The advisory's CVSS of 9.5 is the runtime authority of the BEAM process the storybook mounts inside.\n\nThe whole chain runs over a LiveView socket. Phoenix LiveView's mount-time CSRF token is enforced once during the WebSocket handshake; the `psb-assign` event after that is a regular `phx_event` frame the client sends whenever it wants. There is no per-event re-authentication.\n\n## The fix does not add an escape function\n\nThe patch in commit `56ab846` deletes the three-clause body of `attributes_markup/1` and replaces it with a version that splits the work between two destinations: the Elixir-source slot (for author-tagged `{:eval, _}` values, which stay compiled into the template) and a runtime data slot (for every other attribute, which is lifted out of the source string entirely).\n\n```elixir\ndefp attributes_markup(attributes, index, reserved_attrs \\\\ []) do\n {eval_attrs, runtime_attrs} =\n attributes\n |> Enum.reject(fn {name, _val} -> name in reserved_attrs end)\n |> Enum.split_with(fn\n {_name, {:eval, _val}} -> true\n _attr -> false\n end)\n\n eval_attrs_markup =\n Enum.map_join(eval_attrs, \" \", fn {name, {:eval, val}} ->\n ~s|#{name}={#{val}}|\n end)\n\n markup =\n [\"{Map.fetch!(@psb_variation_attrs, #{index})}\", eval_attrs_markup]\n |> Enum.reject(&(&1 == \"\"))\n |> Enum.join(\" \")\n\n {markup, Map.new(runtime_attrs)}\nend\n```\n\nThe runtime attrs are not interpolated into the source string at all. They are returned alongside the markup, eventually bound onto an assigns key called `psb_variation_attrs`, and the source string the compiler sees contains only this:\n\n```\n{Map.fetch!(@psb_variation_attrs, 0)}\n```\n\nThat is HEEx's component-attribute spread syntax. At compile time, the source carries an `assigns` reference. At runtime, the renderer hands the values in via `Code.eval_quoted_with_env(quoted_code, [assigns: assigns], env)`, where `assigns.psb_variation_attrs` is a plain map. The compiler never sees the attacker's bytes. The bytes never enter the source.\n\nThis is the part nobody else is going to explain.\n\nThe fix does not call a HEEx-attribute escape function over the binary value because no such function exists for the slot the binary clause was writing into. HEEx's attribute grammar offers two source-level slots: `name=\"literal\"` and `name={expr}`. The literal slot expects a string between two `\"` characters and provides no programmatic way to encode a `\"` inside that string from Elixir source. The expression slot expects parseable Elixir and accepts whatever `inspect/2` returns. The first clause and the third clause of the pre-patch function both routed values through the expression slot (the first with author-tagged source, the third with `inspect/2`) because that is the slot that admits a programmatic escape. The second clause routed through the literal slot and typed the `\"` by hand because the literal slot has no other option to offer.\n\nThe patch generalises the safe pattern by lifting all runtime values out of the source string entirely and into the assigns map. The third runtime-data slot, HEEx's component-attribute spread, accepts the assigns reference and resolves the attributes at render time from data, not from source.\n\nThe patch does not add an escape function. The literal slot has no function to call. The other two clauses had already routed around its absence.\n\nThis is the fourth exhibit on this site of the pattern catalogued as Quote Wrap Is Not Escape. AVideo wrote three apostrophes around a PHP shell argument while forty-seven `escapeshellarg` calls lived elsewhere in the same tree. GL.iNet wrote two double quotes around a C string while `execve` and a known-safe argv array were already in the binary. browser-tools-mcp wrote quotes around a Node child_process argument while `spawn` with an array was one import away. Phoenix Storybook wrote `\"` characters around an HEEx attribute on its binary clause while the other two clauses of the same function routed through HEEx's expression slot via `inspect/2` and developer-tagged source. Same defender frame, fourth dialect: a typed delimiter byte in the surrounding source language is not an escape, the destination provides one (or in this case has none for the chosen slot and one for the adjacent slot), and the bug site reached for the byte while a known-safe path sat next to it in the same function.\n\n## The patch closes four bugs, not one\n\nWhile the renderer fix is the headline, the same commit changes the WebSocket-side helper in three other ways the advisory's \"vulnerability involves three components\" sentence collapses into one bullet. Each of them is a separate BEAM-level bug.\n\nBefore the patch, `ExtraAssignsHelpers.to_variation_id/2` resolved the caller-supplied `variation_id` like this:\n\n```elixir\ndefp to_variation_id(%{\"variation_id\" => [group_id, variation_id]}, _ctx),\n do: {String.to_atom(group_id), String.to_atom(variation_id)}\n\ndefp to_variation_id(%{\"variation_id\" => variation_id}, _ctx),\n do: {:single, String.to_atom(variation_id)}\n```\n\n`String.to_atom/1` allocates a new entry in the global atom table for any string it has not seen before. The BEAM's atom table is capped at 1,048,576 entries by default and is never garbage-collected. Any WebSocket caller able to send `psb-assign` could enumerate a few hundred thousand variation_ids and exhaust the table, at which point the next allocation crashes the entire BEAM node. The routes that read this field accept the value through a frame the LiveView's `handle_event/3` calls without checking whether the variation_id corresponds to anything that exists.\n\nThe pre-patch `handle_set_variation_assign/3` then iterated the rest of the params and converted every attribute name through the same primitive:\n\n```elixir\nfor {attr, value} <- params, reduce: variation_extra_assigns do\n acc ->\n attr = String.to_atom(attr)\n value = to_value(value, attr, story.attributes(), context)\n Map.put(acc, attr, value)\nend\n```\n\nThat is one allocated atom per attribute name. A single `psb-assign` event can carry arbitrary fields and each unrecognised one is an entry into the table.\n\nThen `to_value` resolved typed attributes:\n\n```elixir\ndefp to_value(val, attr_id, attributes, context) when is_binary(val) do\n case declared_attr_type(attr_id, attributes) do\n :atom -> val |> String.to_atom() |> check_type!(:atom, context)\n :boolean -> val |> String.to_atom() |> check_type!(:boolean, context)\n ...\n```\n\nFor any attribute the story declared as type `:atom`, the value gets allocated. For any attribute declared `:boolean`, the value gets allocated first and then checked against `is_boolean/1`, with the check happening _after_ the table entry exists. A payload of `{\"boolean_attr\": \"psb_dos_000001\"}` produces a runtime error, and a permanent atom-table entry, on every send.\n\nThe patch replaces every one of those with `String.to_existing_atom/1` wrapped in a rescue that raises a controlled error, and adds a regex (`~r/^[A-Za-z_:][A-Za-z0-9_:\\.-]*[!?]?$/`) over attribute names before any conversion runs. It also reaches up into `to_variation_id` and changes it to look up the variation_id in the existing extra-assigns map rather than allocate a new atom for it.\n\nFour bugs, one commit. The renderer's code injection is the worst of them. The other three exist because the same handler decided that the LiveView WebSocket would only ever be driven by the same developer's browser, that the developer would only send variation_ids and attribute names that already existed in the story, and that the BEAM's atom table was not a thing for the design to worry about. The advisory mentions atom creation in passing. The commit message lists it as a secondary point. It is three separate denial-of-service primitives on the same handler that takes the same input from the same network frame.\n\n## The playground was the production deployment\n\nThe advisory's Impact section opens with this:\n\n> \"Any user able to reach the storybook endpoint, including unauthenticated internet users if the storybook is publicly deployed, can execute arbitrary operating system commands with the privileges of the server process.\"\n\n\"If the storybook is publicly deployed\" reads like a hypothetical. The same project's `README.md` lists it as a feature:\n\n```\n## Storybook in production\n\nA few storybooks running in production:\n\n- [Phenix Groupe](https://storybook.phenixgroupe.com/)\n- [SaladUI](https://salad-storybook.fly.dev/)\n- [DaisyUI Components](https://daisy-ui-components-site.fly.dev/storybook)\n- [Noora](https://storybook.noora.tuist.dev/)\n- [Bloom](https://bloom-ui.fly.dev/storybook)\n- [Doggo](https://doggo.wlyx.dev/)\n- [Tremorx](https://tremorx.fly.dev/)\n```\n\nThe router macro the library ships with mounts the storybook routes inside a `live_session` whose only `on_mount` hook is `PhoenixStorybook.Mount`. That module's entire body is:\n\n```elixir\ndef on_mount(:default, _params, session, socket) do\n socket =\n assign(socket,\n backend_module: Map.fetch!(session, \"backend_module\"),\n root_path: Map.fetch!(session, \"root_path\"),\n assets_path: Map.fetch!(session, \"assets_path\"),\n csp_nonces: Map.fetch!(session, \"csp_nonces\"),\n csrf: Map.fetch!(session, \"csrf\"),\n live_socket_path: Map.fetch!(session, \"live_socket_path\")\n )\n\n {:cont, socket}\nend\n```\n\nIt propagates configuration. It does not check a user. The router's installed pipeline is `:accepts [\"html\"], :fetch_session, :protect_from_forgery`. The canonical usage example in the macro's docstring mounts the storybook in a scope piped through `:browser` and nothing else:\n\n```elixir\nscope \"/\" do\n pipe_through :browser\n live_storybook \"/storybook\", backend_module: MyAppWeb.Storybook\nend\n```\n\n`live_storybook` does not accept an `on_mount` option for a host application's authenticated session. The library's data model for \"who is talking to the playground\" is \"the developer running `mix phx.server` locally.\" The library's deployment story has seven URLs above it and a section heading saying production.\n\nThe same developer who treated the LiveView WebSocket as a local-only channel was also the developer who reached for `String.to_atom/1` on every byte the channel delivered, and the developer who typed `\"` around binary attribute values in the HEEx source. Three choices read as correct under a single threat model: \"the only caller is me.\" Three choices read as four CVEs under the threat model the README is marketing.\n\nCVE-2026-8467. [GHSA-55hg-8qxv-qj4p](https://github.com/phenixdigital/phoenix_storybook/security/advisories/GHSA-55hg-8qxv-qj4p). [Patch commit `56ab846`](https://github.com/phenixdigital/phoenix_storybook/commit/56ab8464d4375fa52db806148a06cce126ad481d). Affected: phoenix_storybook 0.5.0 through 1.0.x. Patched in 1.1.0. Credit: ndelphit (finder), cblavier (remediation).","closing_line":"The fix does not add an escape function. The literal slot has none. The other two clauses had already routed around its absence by writing parseable Elixir into the expression form, which is what the patch generalises across every runtime attribute the playground accepts.","hook_md":"Phoenix Storybook 1.0.x ships a LiveView named `PlaygroundPreviewLive`. The LiveView handles a WebSocket event called `psb-assign`, accepts arbitrary attribute names and values from whatever client connected, hands them to a renderer called `ComponentRenderer`, and the renderer writes them into a HEEx template string that it then runs through `EEx.compile_string/2` and `Code.eval_quoted_with_env/3` with the full `Kernel` imports and no sandbox.\n\nCVE-2026-8467 is the function inside that renderer that did the writing. It is named `attributes_markup/1` and it has three pattern-match clauses. Two of them route the value through HEEx's expression slot `name={...}`, where the contents must parse as Elixir. The clause for binary values routes through the literal slot `name=\"...\"`, where the `\"` characters are typed into the source by hand and there is no escape function to encode a delimiter inside them.","post_id":597,"slug":"phoenix-storybook-cve-2026-8467-typed-the-quotes","title":"CVE-2026-8467: Phoenix Storybook's Playground Typed The Quotes Into Its HEEx Compiler","type":"initial","unreadable_sentence":"The patch does not add an escape function. The literal slot has no function to call, and the other two clauses had already routed around its absence through `inspect/2` and the expression slot."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCasVAhwAKCRDeZjl4jgkQ Jth/AQCUO5Z0kCkECoqo0fvznfdv/zEjfi5CKisyJiMtTNVxOgD+OGXefEJGPeCR j8e8aqzuKK9q8y3kqoZMutC4IK/PFwY= =XbBF -----END PGP SIGNATURE-----