Summary
The @tinacms/mdx serializer can write rich-text values into MDX expressions without escaping them, allowing crafted content to break out of those expressions. An authenticated content editor may be able to cause JavaScript to run when the content is rendered in a visitor's browser or processed by a build or server-side rendering host.
Affected context
The issue concerns MDX serialization in @tinacms/mdx. It becomes risky when authenticated editors can save rich-text values that the serializer places into list field or highlightColor expressions without context-appropriate escaping, and those stored files are later rendered or processed.
Exploit preconditions
- Attack surface: MDX content serialization and subsequent rendering or processing
- Required access: Authenticated content-editing access sufficient to save rich-text values
- Trigger point: The crafted stored content is rendered in a browser or handled by a build or server-side rendering process
- Why exploitation is possible: Unescaped values can break out of MDX expressions and be interpreted as executable code
Why this happens
The serializer places content values into MDX expression contexts without safely encoding them for those contexts. This is a code injection flaw mapped to CWE-94: Improper Control of Generation of Code, because data is incorporated into generated code in a way that can alter its intended structure and behavior.
Potential impact
- JavaScript could execute in visitors' browsers when affected content is rendered.
- Build or server-side rendering hosts may execute attacker-controlled code while processing stored MDX.
- Browser sessions or data accessible to the affected page could be exposed or manipulated.
- Build or rendering environments could be compromised, depending on their permissions and available resources.
General mitigation guidance
Defensive approaches focus on keeping content as data rather than allowing it to change generated code structure.
- Use context-aware escaping or structured serialization for values inserted into MDX expressions.
- Prefer safe-by-default APIs that separate data from executable expressions.
- Validate content against strict schemas and reduce the amount of editor-controlled input accepted in expression contexts.
- Apply least privilege and isolate build and rendering processes from sensitive resources.
- Treat stored content as untrusted when it is rendered or processed.
How teams detect issues like this
- Use static analysis to identify serializers that interpolate untrusted values into MDX, JavaScript, or other executable expressions.
- Review code paths that generate list field or highlightColor expressions, checking whether values are encoded for their output context.
- Test serialization and rendering boundaries with content containing syntax-significant characters, without relying on unsafe execution.
- Enforce code review or CI policies that flag dynamic code generation and require safe serialization patterns.
- Consider automated code review tools as an additional way to surface risky interpolation patterns.

