Summary
Contentlayer's source-files package can execute JavaScript embedded in Markdown or MDX frontmatter during parsing. If an attacker can control content files that are processed in a build, they may run code in the build environment and expose accessible CI secrets.
Affected context
The issue occurs in Contentlayer's @contentlayer/source-files Markdown parsing path, where parseMarkdown() uses gray-matter with its JavaScript engine enabled. It becomes risky when attacker-controlled Markdown or MDX files are parsed during a build, particularly in CI environments that hold secrets or have access to other sensitive resources.
Exploit preconditions
- Attack surface: Markdown or MDX content processed by the Contentlayer source-files parser
- Required access: Ability to introduce or modify content files consumed by a build
- Trigger point: Parsing frontmatter during the build
- Why exploitation is possible: The parser permits JavaScript frontmatter to execute while processing the content
Why this happens
The root cause is evaluation of attacker-controlled input during frontmatter parsing. Allowing gray-matter's JavaScript engine to process content treats data as executable code, matching CWE-95: Improper Neutralization of Directives in Dynamically Evaluated Code ('Eval Injection').
Potential impact
- Arbitrary JavaScript may run with the permissions of the build process
- CI secrets available to that process could be exposed
- Build artifacts or source content could be altered
- Connected systems or resources accessible to the build environment could be affected
General mitigation guidance
Mitigation patterns focus on treating content as data rather than executable logic and limiting the consequences of a compromised build.
- Disable JavaScript evaluation in frontmatter parsing and use non-evaluating parsing modes
- Restrict who can contribute or modify content consumed by builds
- Keep secrets out of untrusted build jobs and limit credentials to the minimum required
- Isolate builds and restrict their access to networks, files, and other resources
- Validate content against a narrow expected schema without executing it
How teams detect issues like this
Detection can include static analysis and code review for parser configurations that enable JavaScript evaluation, especially in Markdown or MDX frontmatter handling. Review content-processing pipelines for untrusted contributors and check CI policies for secret exposure, build isolation, and least-privilege permissions. Automated review tools can help flag risky parsing options and content-to-code execution paths.

