Contentlayer frontmatter can execute code inside the build
Contentlayer frontmatter can execute code inside the build CVE-2026-129948 affects @contentlayer/source-files through 0.3.4. The vulnerable package passes Markdown content through a processing path where gray-matter's JavaScript engine remains enabled. A person who controls a content file can place a JavaScript expression in frontmatter and have it evaluated while the site or application is…
Contentlayer's frontmatter feature can execute JavaScript code during the build process, which has been identified as a vulnerability in the @contentlayer/source-files package. This occurs because the package passes Markdown content through a processing path where JavaScript remains enabled. If a user with control over a content file inserts a JavaScript expression in the frontmatter, it will be executed while the site or application is being built.
The severity of this vulnerability is rated at 8.8 on the CVSS 3.1 scale. The risk stems from the fact that a Markdown file, which is treated as data, may contain executable JavaScript code. This code can be executed as if it were part of the build, putting it on equal footing with legitimate build code. Once executable syntax is accepted, a file from a content contributor, an imported repository, or a third-party template can behave just like the build code itself.
Potential attacks could involve executing arbitrary JavaScript, accessing or modifying environment variables, package-manager credentials, signing keys, or source-repository tokens. The malicious content might also modify generated assets or inject additional code into the output. Importantly, the malicious frontmatter may not be directly seen by the browser, as it is processed on the build worker before it reaches the public-facing browser.
To mitigate this risk, it is recommended to search dependency manifests and lockfiles for the vulnerable package and version. It's also important to map who can create or update files consumed by the build, as this includes repository contributors, CMS exports, sync jobs, template repositories, and external feeds. When possible, private repositories can reduce exposure if all contributors and automation with write access are trusted.
Regularly reviewing build commands and configurations can also help identify and isolate vulnerable build steps.
Additional security measures include disabling JavaScript evaluation in the frontmatter parser, pinning unsafe versions of the package out of the build, isolating the build worker, and implementing strict logging and monitoring of build events. These controls can help limit the impact of a potentially malicious build, but they do not eliminate the possibility of code execution.
Ultimately, treating content as code and applying the same rigorous review, isolation, and auditing that is applied to build scripts is the most effective way to secure a system where frontmatter can execute code.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to