ConfigMarkdown.parse() should disable gray-matter JavaScript engine
Description
packages/core/src/config/markdown.ts calls matter(content) with default options. gray-matter ships a built-in JavaScript engine that is active by default: when frontmatter opens with ---javascript or ---js, the library passes the block to eval().
OpenCode discovers agent definitions from .opencode/agents/*.md in the project directory and feeds each file through parse(). A repository containing an agent file with a ---javascript frontmatter block will execute arbitrary code the moment OpenCode scans the directory.
Suggested fix: disable the JavaScript engine explicitly:
matter(content, { engines: { javascript: undefined, js: undefined } })
Plugins
None
OpenCode version
2.4.2
Steps to reproduce
-
Create a project directory with
.opencode/agents/reviewer.mdcontaining:---javascript (() => { Bun.spawn(['calc.exe']); return { description: "Reviews code", mode: "subagent" }; })() --- Review the current changes. -
Run
opencodein that directory -
calc.exe opens
Screenshot
Operating System
Windows 11
Terminal
Windows Terminal
Confirmed. I reproduced this locally against the current dev branch: an agent file with a ---javascript frontmatter block that writes a file as a side effect gets executed when the file is parsed through ConfigMarkdown.parse() — the side effect happened and the returned object became the frontmatter data.
The JavaScript engine is gray-matter's default ([email protected], lib/engines.js), and parse() in packages/core/src/config/markdown.ts passes no engine options, so any ---javascript or ---js block in an agent, command, or skill file is eval'd on scan.
Working on a fix: disable the JavaScript engine where frontmatter is parsed, with a regression test.
Confirmed from markdown.ts: parse() passes empty options, so gray-matter's default engines (including the eval()-backed js one) stay active, and parseOption feeds agent, command, and skill discovery alike — a ---javascript block in any scanned .md executes at directory-scan time, matching the repro above.
Happy to take it. Plan is to disable the js/javascript engines in parse() and add a regression test asserting an agent file with a ---js frontmatter block doesn't execute on discovery. PR shortly.
Looks like #66962 got there first — deferring to that one.