Skip to content

Stored XSS in PictureView figcaption via html_safe on User Caption

Moderate
tvdeyen published GHSA-pm72-wq9v-wvfh Jul 22, 2026

Package

bundler alchemy_cms (RubyGems)

Affected versions

< 8.3.5
< 8.2.9
< 8.1.15
< 8.0.16

Patched versions

8.3.5
8.2.9
8.1.15
8.0.16

Description

Summary

Alchemy::Ingredients::PictureView#caption calls ingredient.caption.html_safe and passes the result to content_tag(:figcaption, ...). The caption value is user-supplied (set via the ingredients_attributes[caption] parameter in the element save API) and is stored in a JSON data column with no sanitization. Because .html_safe is called before content_tag, Rails' automatic HTML escaping is suppressed and the raw user string is emitted into the published page, executing in every visitor's browser.

Details

Root cause

ingredient.caption is a store_accessor backed by the JSON data column of alchemy_ingredients. It returns a plain Ruby String. The view calls .html_safe on it unconditionally before passing it to content_tag:

# app/components/alchemy/ingredients/picture_view.rb, line 71
def caption
  return unless show_caption?

  @_caption ||= content_tag(:figcaption, ingredient.caption.html_safe)
  #                                                   ^^^^^^^^^^^
  #  .html_safe marks user input as trusted HTML; content_tag skips escaping
end

Rails' content_tag escapes its body argument by default — but only when the argument is not already html_safe. The .html_safe call on line 71 sets the html_safe? flag to true, so content_tag passes the string through unchanged. Any HTML tags in the caption appear verbatim in the rendered <figcaption> element.

No sanitizer is applied to the caption field in the model, the controller, or anywhere else in the request lifecycle. The data column accepts arbitrary JSON with no allow-list.

PoC

  1. Upload an image in article
image
  1. Insert a caption with payload
image
  1. Save the caption and save the page.
  2. Proceed to the page and observe the XSS popped.
image

Impact

Any authenticated CMS user with author role or above can plant persistent JavaScript in the caption of any picture ingredient. The payload executes in every anonymous visitor's browser when they load the affected page. Attack surface includes session hijacking, credential phishing overlays, drive-by malware delivery, and defacement. Because picture ingredients can appear on any page version, a single poisoned caption persists across re-publishes until explicitly cleared.

Severity

Moderate

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v3 base metrics

Attack vector
Network
Attack complexity
Low
Privileges required
Low
User interaction
Required
Scope
Changed
Confidentiality
Low
Integrity
Low
Availability
None

CVSS v3 base metrics

Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability.
Attack complexity: More severe for the least complex attacks.
Privileges required: More severe if no privileges are required.
User interaction: More severe when no user interaction is required.
Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope.
Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user.
Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user.
Availability: More severe when the loss of impacted component availability is highest.
CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:C/C:L/I:L/A:N

CVE ID

No known CVE

Weaknesses

Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')

The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users. Learn more on MITRE.

Credits