/

CVE-2026-129947

Severity:

HIGH RISK

(8.0)

Code Injection (CWE-94) in Contentlayer Data Export

CVE-2026-129947

Received

Vulnerability type

Category:

Code Injection

CWE:

CWE-94

Impact:

Arbitrary JavaScript execution in the development process

Severity:

HIGH RISK

(8.0)

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

Contentlayer can generate a JavaScript module using content file names in an import specifier without safely handling embedded single quotes. If an attacker can introduce a suitably named content file, the generated code may contain injected JavaScript that runs when the module is imported.

Affected context

The issue is associated with Contentlayer @contentlayer/core through 0.3.4, in the generation of the data export module by makeDataExportFile(). It becomes risky when content file names are attacker-controlled or can be modified by an untrusted contributor, and the generated module is subsequently imported by contentlayer dev or a Next.js development server.

Exploit preconditions

  • Attack surface: Content files processed by Contentlayer's data export generation.
  • Required access: Ability to add or modify a content file name, directly or through an input or contribution workflow.
  • Trigger point: Generation and import of the resulting module during Contentlayer or Next.js development.
  • Why exploitation is possible: A file name containing a single quote can break out of the generated import specifier if it is inserted into JavaScript source without safe encoding.

Why this happens

The underlying bug is unsafe construction of JavaScript source using a content file name as part of an import specifier. If untrusted text is interpolated without context-appropriate escaping or encoding, it can alter the generated program rather than remain data. This maps to CWE-94: Improper Control of Generation of Code (Code Injection).

Potential impact

  • Injected JavaScript may execute in the development process when the generated module is imported.
  • The code may access files, environment variables, or services available to that process.
  • Development credentials or other secrets available to the process could be exposed.
  • A compromised development environment could be used to affect related workflows or systems.

General mitigation guidance

Defensive patterns focus on keeping content-derived values as data rather than allowing them to change generated source.

  • Use safe, context-aware encoding or structured code-generation APIs for values included in JavaScript.
  • Prefer stable generated identifiers that are not derived directly from untrusted file names.
  • Validate and restrict content file names according to a narrowly defined naming policy.
  • Reduce trust in content supplied through external or collaborative workflows, and review changes that introduce or rename files.
  • Run development processes with least privilege and limit access to secrets and sensitive resources.

How teams detect issues like this

  • Use static analysis to identify string interpolation or concatenation that places file names or other untrusted values into generated JavaScript.
  • Review code-generation paths for missing context-aware escaping and check whether validation occurs before source generation.
  • Add policy checks for unexpected characters or naming patterns in content files, particularly in externally supplied changes.
  • Include tests that verify unusual file names cannot alter the structure of generated modules.
  • Automated code review tools may help flag unsafe source-generation patterns.

Sources

SourceLink
github.comgithub.com/contentlayerdev/contentlayer/blob/v0.3.4/packages/@contentlayer/core/src/generation/generate-dotpkg.ts#L377-L379
github.comgithub.com/contentlayerdev/contentlayer/blob/v0.3.4/packages/@contentlayer/core/src/generation/generate-dotpkg.ts#L511
github.comgithub.com/contentlayerdev/contentlayer/issues/688
vulncheck.comvulncheck.com/advisories/contentlayer-contentlayer-core-through-0.3.4-code-injection-via-generated-index-mjs

Frequently asked

questions

The described trigger is local to a development workflow: an affected project must process a content file and import the generated module. Remote exploitation would depend on whether an external workflow allows an attacker to submit or modify such files.

An attacker needs a way to introduce or change a content file name that is processed by Contentlayer. The vulnerability does not, by itself, establish that an unauthenticated remote user can do this.

Ensure untrusted file names cannot alter generated JavaScript. Use structured code generation or context-aware encoding, and avoid embedding raw names in executable source.

Treat content names as untrusted input, enforce a narrow naming policy, test generated output against unusual names, and run development tools with limited privileges.

Find out what's already
exploitable in your codebase.