Summary
A code injection flaw in the Tina CLI Forestry-to-Tina migration command allows attacker-controlled project metadata to be transformed into executable JavaScript or TypeScript.
When a developer runs the migration and then executes tinacms dev or tinacms build, injected code in generated template files may run with the developer's local privileges.
Affected context
This vulnerability affects development environments where Tina's CLI is used to migrate from Forestry-style projects to Tina.
It becomes relevant when the migration command processes .forestry/**/*.yml configuration files whose label or name fields can be influenced by an attacker, such as in cloned or third-party sample repositories.
The generated tina/templates.{ts,js} file incorporates these fields without sufficient sanitisation, allowing crafted values to become executable code.
Exploit preconditions
- Attack surface: Tina CLI Forestry-to-Tina migration workflow in developer machines.
- Required access: Ability to control or modify a Forestry-style project's
.forestry/**/*.ymlfiles (e.g., a malicious repository, template, or pull request). - Trigger point: A developer runs the migration command and then executes
tinacms devortinacms build, causing the generatedtina/templates.{ts,js}module to be loaded. - Why exploitation is possible: The helper
addVariablesToCodeunquotes values marked with__TINA_INTERNAL__:::(...):::inside stringified JSON, and user-controlledlabelandnamefields are inserted into this JSON without sanitisation, allowing arbitrary JavaScript to be emitted at module top level.
Why this happens
The underlying bug is a classic code injection issue where data originating from configuration files is treated as trusted source code during code generation.
Instead of keeping user-supplied label and name fields as inert strings, the migration logic uses a marker-based unquoting mechanism that converts them into raw JavaScript fragments inside generated templates.
This directly maps to CWE-94: Improper Control of Generation of Code, where input is incorporated into dynamically produced code without strict validation, escaping, or a safe templating boundary.
Potential impact
- Arbitrary JavaScript/TypeScript execution on the developer's machine when running Tina CLI commands.
- Exfiltration of sensitive local files, environment variables, or access tokens available to the developer account.
- Installation of additional malware or backdoors in the local development environment or checked-in project files.
- Propagation of malicious code into the project's codebase, potentially affecting downstream builds or deployments.
General mitigation guidance
Effective mitigation centers on treating all configuration-driven content as untrusted data rather than executable code.
Recommended defensive patterns include:
- Avoid directly embedding user-controlled values into generated source code; when necessary, ensure they remain properly quoted strings.
- Use strict encoding and escaping routines for any content interpolated into code templates, preventing it from altering surrounding syntax or introducing new statements.
- Replace marker-based "unquoting" mechanisms with structured code generation that only permits well-typed, pre-validated values.
- Enforce schema validation and character restrictions on configuration fields that influence code generation, limiting them to safe, expected formats.
- Isolate code generation and subsequent build steps in least-privileged, sandboxed environments to reduce the impact of unexpected execution.
How teams detect issues like this
Detection typically combines source-level review and automated analysis of code generation flows:
- Use static analysis or linters to identify patterns where configuration values or stringified JSON segments are injected into templates without escaping or are deliberately unquoted into code.
- During code review, scrutinize utilities that transform configuration into source code, especially helpers that manipulate strings with regex-based markers or custom templating logic.
- Implement CI policies that flag newly generated files containing suspicious patterns (e.g., unexpected function calls, imports, or markers derived from configuration fields).
- Employ supply-chain security tools that scan project templates and starter repositories for embedded dynamic code paths that depend on user-controlled metadata.

