T09 · Insecure Skill Coding Practices
- Location
scripts/src/core/markdown.ts:21- Finding
Arbitrary Server-Side JavaScript Execution Through Untrusted MDX Evaluation
- Content
View full analysis
{ const mdxComponentNames = [...markdown.matchAll(/<([A-Z][A-Za-z0-9_]*)\b/g)].map((match) => match[1]); const fallbackComponents: Record>> = {}; for (const componentName of mdxComponentNames) { if (fallbackComponents[componentName]) { continue; } fallbackComponents[componentName] = function UnknownMdxComponent(props: Record = {}) { const { children } = props; return React.createElement( 'div', { 'data-mdx-component': componentName }, children as React.ReactNode ); }; } const module = (await evaluate(markdown, { Fragment, jsx, jsxs, development: false, remarkPlugins: [remarkGfm] })) as { default: React.ComponentType> }; const Component = module.default; const html = renderToStaticMarkup( React.createElement(Component, { components: fallbackComponents }) ).trim(); return html.length > 0 ? html : '
'; } ``` The feature is exposed as a normal CLI option: ```ts .option('--mdx-mode', 'Enable mdx mode', false) ``` ### Technical Analysis `@mdx-js/mdx` evaluation is not equivalent to parsing Markdown as inert text. MDX supports executable JavaScript expressions and compiles the supplied document into a JavaScript module. Calling `evaluate()` on content from the input file therefore crosses a code-versus-data boundary. The CLI reads a user-selected file and passes its contents directly into this evaluation path when `--mdx-mode` is enabled. There is no trust check, isolation boundary, sandbox, capability restriction, or validation that limits ...[truncated 1361 chars]- Remediation
View remediation
