Repository navigation
Description
Security review: three input-handling issues in build pipeline
This is a coordinated report for three issues found during a local review of contentlayer@0.3.4. No exploit code is included. The repository has no published security policy / advisories, so filing as a public issue.
1. JavaScript frontmatter evaluated via gray-matter (inherited, references existing CVE)
Description:
Content parsing configures gray-matter with a custom yaml engine only. The js / javascript engine remains enabled by default. When a content file declares a JavaScript frontmatter language, that block is passed to the dependency JavaScript engine for evaluation during build.
Vulnerable files:
packages/@contentlayer/source-files/src/fetchData/makeCacheItemFromFilePath.ts:221-228(parseMarkdown->matter()call)- Upstream:
gray-matter@4.0.3lib/engines.jsJavaScript engine - Callers:
packages/@contentlayer/source-files/src/fetchData/mapping/field-mdx.ts,field-markdown.tsviarawDocumentContent
Impact:
Build-time arbitrary code execution in the context running contentlayer build / dev. Affects CI builders that compile untrusted content. Confidentiality / Integrity / Availability impact on build host. This corresponds to existing CVE-2026-78847 / GHSA-j9gx-vjm3-jpmm for gray-matter.
Mitigation:
Explicitly disable executable frontmatter engines in all matter() calls, reject non-yaml/json frontmatter languages before parsing, document that only trusted content should be built, and / or override js and javascript engines to throw. Least-privilege build (no secrets in build env) reduces impact.
2. Unsanitized document ID in generated JavaScript import (novel)
Description:
Document IDs derived from relative file paths are converted to file names by replacing path separators only, with no sanitization of quoting or control characters. The result is interpolated into generated ESM import specifiers in barrel files.
Vulnerable files:
packages/@contentlayer/core/src/generation/generate-dotpkg.ts:511(idToFileNamedefinition)packages/@contentlayer/core/src/generation/generate-dotpkg.ts:199-205(makeDataExportFileimport generation)packages/@contentlayer/core/src/generation/generate-dotpkg.ts:208-212,214-226(per-document JSON + barrel file lists)packages/@contentlayer/core/src/generation/generate-dotpkg.ts:307-331(write path)
Impact:
Integrity impact on generated output. A content filename containing unexpected characters can break out of the intended import string and alter generated module semantics. Generated modules are later imported by application code and internal tooling, so malformed generation can lead to build failure or unintended code execution in build / dev context.
Mitigation:
Sanitize IDs used in code generation: allowlist to alphanumerics plus limited safe punctuation, hash or encode unsafe names, use data-driven manifests instead of string-interpolated imports, and validate content filenames before generation.
3. Image src path not confined to contentDirPath (novel)
Description:
Image fields resolve a frontmatter-supplied path relative to the containing document and join it to the content directory without a containment check. Directory parent segments can resolve outside the intended content root, and the target is read and embedded in build output.
Vulnerable files:
packages/@contentlayer/source-files/src/fetchData/mapping/field-image.ts:54-62(getImageFieldDatapath resolution andreadFileBuffer)- Related existence check:
packages/@contentlayer/source-files/src/fetchData/validateDocumentData.ts:199-213
Impact:
Confidentiality / Availability impact. Out-of-root file read with content embedded in generated JSON, plus exposure of native image decoders (sharp / imagescript) to untrusted bytes.
Mitigation:
Canonicalize resolved image paths and enforce containment within contentDirPath, reject absolute paths and parent-directory segments from frontmatter, follow least-privilege filesystem access, and handle decoder errors without embedding.
Versions reviewed: contentlayer@0.3.4, @contentlayer/source-files@0.3.4, @contentlayer/core with gray-matter@4.0.3, yaml@2.3.1. Happy to provide private reproduction details to maintainers on request and to split into separate advisories if preferred.
Activity