/

CVE-2026-78847

Severity:

CRITICAL RISK

(9.8)

Code Injection (CWE-95) in gray-matter JavaScript Engine

CVE-2026-78847

Deferred

Vulnerability type

Category:

Code Injection

CWE:

CWE-95

Impact:

Arbitrary Code Execution

Severity:

CRITICAL RISK

(9.8)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

A critical code injection vulnerability in gray-matter uses JavaScript's eval() to parse front matter when the declared language is js or javascript.

If an attacker can influence the parsed front matter, arbitrary JavaScript may execute within the application's process, potentially leading to full application compromise.

Affected context

The issue occurs in gray-matter's JavaScript front matter engine, including deployments using the affected parsing behavior verified in version 4.0.3. Risk is present when application-controlled or attacker-influenced content is processed as JavaScript front matter rather than as inert data, particularly in systems that parse untrusted documents.

Exploit preconditions

  • Attack surface: Applications or build pipelines that use gray-matter to parse front matter
  • Required access: Ability to supply, modify, or cause processing of a document containing JavaScript-designated front matter
  • Trigger point: Front matter parsing when the language is js or javascript
  • Why exploitation is possible: The parser evaluates supplied content as JavaScript through eval() instead of treating it strictly as data

Why this happens

The underlying bug is the execution of parser input as JavaScript code. Using eval() to interpret front matter creates a direct code injection condition because document content crosses the data-and-code boundary without a safe, constrained representation.

This maps to CWE-95: Improper Neutralization of Directives in Dynamically-Evaluated Code ('Eval Injection'). The insecure pattern is a generic evaluation mechanism applied to content that may originate outside a fully trusted boundary.

Potential impact

  • An attacker may execute arbitrary JavaScript in the application's process
  • Application secrets, files, or environment variables could be exposed
  • The affected service could be modified, disrupted, or taken over
  • Downstream build, publishing, or content-processing systems could be compromised
  • The vulnerability could enable lateral movement where the process has broader network or cloud permissions

General mitigation guidance

Mitigation generally focuses on removing dynamic evaluation from document parsing and reducing trust in front matter inputs.

Common defensive patterns include:

  • Parsing front matter with a data-only format and a strict schema
  • Replacing evaluation with explicit field parsing and allowlisted value types
  • Rejecting JavaScript-designated front matter when executable behavior is not required
  • Treating repository, upload, and generated-document content as untrusted by default
  • Isolating content-processing jobs and applying least-privilege filesystem, network, and cloud permissions
  • Applying read-only or restricted execution environments where practical
  • Separating content parsing from privileged application operations

How teams detect issues like this

Organizations can identify similar issues through:

  • Static analysis rules that flag eval(), dynamic function construction, and equivalent runtime execution APIs
  • Code review checks for parsers that interpret document fields as executable code
  • Dependency and software-composition analysis for gray-matter usage and transitive parser behavior
  • Tests that submit untrusted front matter and verify that it remains data rather than executing
  • CI policies that prohibit dynamic evaluation in content-processing components
  • Runtime monitoring for unexpected child processes, file access, network connections, or environment-variable reads from parser workers

Automated code review and security scanning tools may help surface these patterns during development.

Sources

SourceLink
blog.checo.ccblog.checo.cc/en/posts/Security/1
github.comgithub.com/jonschlinkert/gray-matter/issues/112
github.comgithub.com/jonschlinkert/gray-matter/issues/131
github.comgithub.com/jonschlinkert/gray-matter/issues/182

Frequently asked

questions

It can be exploitable through a remote or indirect input path when an application processes attacker-controlled documents, uploads, repository content, or other externally influenced front matter. Exploitability depends on how the application accepts and processes that content.

An attacker generally needs a way to influence front matter that is parsed using the js or javascript engine. This could involve document submission, content uploads, repository changes, or another upstream source accepted by the application.

The safest pattern is to eliminate dynamic evaluation and parse front matter as data using a strict schema, explicit types, and an allowlist of supported fields.

Treat document content as untrusted, prohibit evaluation APIs in parsers through code review and CI policy, isolate processing workloads, and apply least-privilege permissions to the runtime.

Find out what's already
exploitable in your codebase.