From 053835e61dc06cb80f362a87cfb2aad56505d3a2 Mon Sep 17 00:00:00 2001 From: scuffi Date: Wed, 25 Nov 2026 18:03:31 +0000 Subject: [PATCH 1/2] computer: Tell code to send Artifacts tokens in a header The `codemode:artifacts` description called `share()`'s URL clone-ready. Code that took it at its word cloned from a URL with a token in it, and git saves a clone's URL in `.git/config`, so the token stayed in the Workspace after the run. The docs already say to clone and push with the git module and the token in an `Authorization` header, and to pass `share()`'s URL to a shell command through `env`. Say the same in the description the model reads. --- .changeset/artifacts-token-header.md | 5 +++++ packages/computer/src/modules/artifacts.test.ts | 7 +++++++ packages/computer/src/modules/artifacts.ts | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 .changeset/artifacts-token-header.md diff --git a/.changeset/artifacts-token-header.md b/.changeset/artifacts-token-header.md new file mode 100644 index 00000000..5cad749c --- /dev/null +++ b/.changeset/artifacts-token-header.md @@ -0,0 +1,5 @@ +--- +"@cloudflare/computer": patch +--- + +`codemode:artifacts` tells code to clone and push with a token in a header, as the docs do, rather than calling `share()`'s URL clone-ready: git saves a clone's URL, token and all, in `.git/config`. diff --git a/packages/computer/src/modules/artifacts.test.ts b/packages/computer/src/modules/artifacts.test.ts index 22c1967c..611d729c 100644 --- a/packages/computer/src/modules/artifacts.test.ts +++ b/packages/computer/src/modules/artifacts.test.ts @@ -150,4 +150,11 @@ describe("createArtifactsModule share", () => { expect(description).toContain("createToken(name"); expect(description).toContain("share(name"); }); + + it("tells code to send a token in a header, not in the URL", () => { + const description = createArtifactsModule().description ?? ""; + expect(description).toContain('headers: { Authorization: "Bearer " }'); + expect(description).toContain(".git/config"); + expect(description).not.toContain("clone-ready"); + }); }); diff --git a/packages/computer/src/modules/artifacts.ts b/packages/computer/src/modules/artifacts.ts index 9e575e6e..aeb76ab2 100644 --- a/packages/computer/src/modules/artifacts.ts +++ b/packages/computer/src/modules/artifacts.ts @@ -95,7 +95,7 @@ export function createArtifactsModule( }, }); return Object.assign(create, { - description: `Git repositories stored in Cloudflare Artifacts: \`create(name)\`, \`get(name)\`, \`list()\`, \`importArtifact(name, source)\`, and \`deleteArtifact(name)\`.${allowNetwork ? "" : " Importing from a remote URL is not allowed."} \`createToken(name, scope?, ttl?)\` mints a git token ("read" by default). \`share(name, { scope?, ttl? })\` returns a clone-ready URL with a token embedded; it is a credential, so never print or return it. \`ttl\` is seconds or a duration like "15m".`, + description: `Git repositories stored in Cloudflare Artifacts: \`create(name)\`, \`get(name)\`, \`list()\`, \`importArtifact(name, source)\`, and \`deleteArtifact(name)\`.${allowNetwork ? "" : " Importing from a remote URL is not allowed."} \`createToken(name, scope?, ttl?)\` mints a git token ("read" by default): to clone or push with the git module, pass \`get(name)\`'s \`remote\` as the URL and the token's \`plaintext\` in \`headers: { Authorization: "Bearer <plaintext>" }\`, not in the URL, which git saves in \`.git/config\`. \`share(name, { scope?, ttl? })\` returns the remote URL with a token embedded, for git in a shell command: pass it in \`env\`, not in the command text. Tokens and shared URLs are credentials, so never print or return them. \`ttl\` is seconds or a duration like "15m".`, }); } From 03f11485fafb65cf542d6aff1f4ce631352bf51e Mon Sep 17 00:00:00 2001 From: scuffi <aferguson@cloudflare.com> Date: Fri, 27 Nov 2026 11:00:45 +0000 Subject: [PATCH 2/2] computer: Strip the expiry hint from Artifacts tokens sent in a header A token's plaintext ends in an `?expires=` hint that isn't part of the credential, as credentialURL() already knows. The description and the docs example sent the whole plaintext as a bearer token, so a clone or push following them would fail to authenticate. Tell code to cut the hint off first, and link the docs from the changeset. --- .changeset/artifacts-token-header.md | 2 +- docs/17_isolate_javascript.md | 3 ++- packages/computer/src/modules/artifacts.test.ts | 3 ++- packages/computer/src/modules/artifacts.ts | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.changeset/artifacts-token-header.md b/.changeset/artifacts-token-header.md index 5cad749c..9267bf03 100644 --- a/.changeset/artifacts-token-header.md +++ b/.changeset/artifacts-token-header.md @@ -2,4 +2,4 @@ "@cloudflare/computer": patch --- -`codemode:artifacts` tells code to clone and push with a token in a header, as the docs do, rather than calling `share()`'s URL clone-ready: git saves a clone's URL, token and all, in `.git/config`. +`codemode:artifacts` tells code to clone and push with a token in a header, as [the docs](https://github.com/cloudflare/computer/blob/main/docs/17_isolate_javascript.md#codemodeartifacts) do, rather than calling `share()`'s URL clone-ready: git saves a clone's URL, token and all, in `.git/config`. diff --git a/docs/17_isolate_javascript.md b/docs/17_isolate_javascript.md index ac30674d..e10bb8a6 100644 --- a/docs/17_isolate_javascript.md +++ b/docs/17_isolate_javascript.md @@ -603,7 +603,8 @@ import { clone, push } from "codemode:git"; export default async function () { const { remote } = await get("site"); const { plaintext } = await createToken("site", "write", "15m"); - const headers = { Authorization: `Bearer ${plaintext}` }; + // The plaintext ends in an `?expires=` hint that isn't part of the token. + const headers = { Authorization: `Bearer ${plaintext.split("?expires=")[0]}` }; await clone({ url: remote, dir: "site", headers }); // ...change and commit files... return push({ dir: "site", ref: "main", headers }); diff --git a/packages/computer/src/modules/artifacts.test.ts b/packages/computer/src/modules/artifacts.test.ts index 611d729c..6fe635c5 100644 --- a/packages/computer/src/modules/artifacts.test.ts +++ b/packages/computer/src/modules/artifacts.test.ts @@ -153,7 +153,8 @@ describe("createArtifactsModule share", () => { it("tells code to send a token in a header, not in the URL", () => { const description = createArtifactsModule().description ?? ""; - expect(description).toContain('headers: { Authorization: "Bearer <plaintext>" }'); + expect(description).toContain('headers: { Authorization: "Bearer <token>" }'); + expect(description).toContain('plaintext.split("?expires=")[0]'); expect(description).toContain(".git/config"); expect(description).not.toContain("clone-ready"); }); diff --git a/packages/computer/src/modules/artifacts.ts b/packages/computer/src/modules/artifacts.ts index aeb76ab2..14d76644 100644 --- a/packages/computer/src/modules/artifacts.ts +++ b/packages/computer/src/modules/artifacts.ts @@ -95,7 +95,7 @@ export function createArtifactsModule( }, }); return Object.assign(create, { - description: `Git repositories stored in Cloudflare Artifacts: \`create(name)\`, \`get(name)\`, \`list()\`, \`importArtifact(name, source)\`, and \`deleteArtifact(name)\`.${allowNetwork ? "" : " Importing from a remote URL is not allowed."} \`createToken(name, scope?, ttl?)\` mints a git token ("read" by default): to clone or push with the git module, pass \`get(name)\`'s \`remote\` as the URL and the token's \`plaintext\` in \`headers: { Authorization: "Bearer <plaintext>" }\`, not in the URL, which git saves in \`.git/config\`. \`share(name, { scope?, ttl? })\` returns the remote URL with a token embedded, for git in a shell command: pass it in \`env\`, not in the command text. Tokens and shared URLs are credentials, so never print or return them. \`ttl\` is seconds or a duration like "15m".`, + description: `Git repositories stored in Cloudflare Artifacts: \`create(name)\`, \`get(name)\`, \`list()\`, \`importArtifact(name, source)\`, and \`deleteArtifact(name)\`.${allowNetwork ? "" : " Importing from a remote URL is not allowed."} \`createToken(name, scope?, ttl?)\` mints a git token ("read" by default): to clone or push with the git module, pass \`get(name)\`'s \`remote\` as the URL and the token in \`headers: { Authorization: "Bearer <token>" }\`, not in the URL, which git saves in \`.git/config\`. The token is \`plaintext\` up to its \`?expires=\` hint, which isn't part of it: \`plaintext.split("?expires=")[0]\`. \`share(name, { scope?, ttl? })\` returns the remote URL with a token embedded, for git in a shell command: pass it in \`env\`, not in the command text. Tokens and shared URLs are credentials, so never print or return them. \`ttl\` is seconds or a duration like "15m".`, }); }