Site administration
Set up the artifacts domain
People publish HTML artifacts, and each page runs its own scripts. Those scripts must never run on the forge's domain, where they can reach the cookies and the pages of the forge. So the forge runs HTML artifacts only on a separate domain, with one subdomain for each owner: https://<owner>.<artifacts domain>. Until you set it up, an HTML artifact shows a note and does not run. This page sets it up.
5 min read
Some steps need the owner of the new domain, and some need the site operator. Each step says who does it.
You need:
- A domain that is not under the forge's domain. For
source.tanstack.com, a subdomain oftanstack.comdoes not work, because it is the same site as the forge. - A Cloudflare login on the account of the forge, with permission to add a zone, edit its DNS and edit its Workers routes.
- Wrangler, signed in to the Cloudflare account of the forge, run from
apps/web. - Write access to the repository of the forge, for the pull request of step 5.
1. Buy the domain
Who: the domain owner.
Buy a domain that has no other use, for example example-artifacts.dev. The forge uses only its subdomains, one for each owner name.
Why a separate domain:
- A browser sends no forge cookie to it, so a page cannot act as the person who reads it.
- Each owner gets an origin of its own, so the pages of one owner cannot read the storage of another.
- If a browser blocks the domain for a bad page, the forge keeps working.
2. Add the zone to Cloudflare
Who: the domain owner.
- In the Cloudflare account of the forge, add the domain as a new zone.
- At the registrar of the domain, set the name servers that Cloudflare gives.
- Wait until Cloudflare shows the zone as active.
Cloudflare's Universal SSL certificate of the zone covers *.<domain>, one level deep. That is the level of <owner>.<domain>.
3. Add the DNS record and the Worker route
Who: the domain owner.
- In the DNS of the zone, add a record of type
AAAA, with the name*, the value100::, and the proxy on (orange cloud). The Worker answers every request, so the address is never used. - Add a Worker route with the pattern
*.<domain>/*for the web Workergitflare. Use the dashboard (Workers & Pages,gitflare, Settings, Domains & Routes), orPOST /zones/<zone id>/workers/routeswith{ "pattern": "*.<domain>/*", "script": "gitflare" }.
Do not put the route in apps/web/wrangler.jsonc. That config lists only the Custom Domain of the forge, so a deploy leaves the routes of the Worker as they are.
4. Make the signing key
Who: the site operator.
The forge page frames each HTML artifact at a URL with a short-lived capability in its path. The keys Worker signs each capability with an RSA key from its secret ARTIFACT_SIGNING_KEYS, and the web Worker checks it with the public key. The web Worker never holds the private key.
pnpm run oidc:keygen makes a key of the right form: an RS256 key with a kid, as one line of JSON. Make a new key for artifacts. Never use the key of OIDC_SIGNING_KEYS. The script prints next steps that name OIDC_SIGNING_KEYS: do not follow them for this key.
Put the key straight into the secret, as a JSON array of one key. The key is never printed or saved in a file:
pnpm --silent run oidc:keygen 2>/dev/null \
| node -e 'let s = ""; process.stdin.on("data", (d) => (s += d)).on("end", () => process.stdout.write(JSON.stringify([JSON.parse(s)])))' \
| pnpm exec wrangler versions secret put ARTIFACT_SIGNING_KEYS -c wrangler.keys.jsonc --tag artifact-keys --message "Artifact signing key"
pnpm exec wrangler versions deploy <the version id it printed>@100% -c wrangler.keys.jsonc
The new version has a tag, so the next ci/deploy goes on as usual (README.md, "Deploying").
5. Set ARTIFACTS_DOMAIN and deploy
Who: the site operator.
In
apps/web/wrangler.jsonc, set the var to the domain, in lowercase, with no scheme:"ARTIFACTS_DOMAIN": "example-artifacts.dev",Open a pull request with this change, and merge it when its checks pass.
Wait for
ci/deployof the merge commit to finish.
6. Check that it works
Ask for a URL with a capability that is not valid:
curl -sI https://test.example-artifacts.dev/v/not-a-capability/The answer is
403, with aContent-Security-Policyheader. If you get another answer, make sure that theci/deployof step 5 finished, and that the route of step 3 namesgitflare.In a test repository, publish an HTML page:
src artifact create report.html.Open the page of the artifact. The page runs in a frame, and Open in a new tab opens it on
https://<owner>.example-artifacts.dev/v/....Run
src artifact view <n> --json contentUrl. The URL is not null.
Done
HTML artifacts run on <owner>.<domain>, in a sandbox, with no forge cookie. The forge frames them on its pages.
While the domain is not set
While ARTIFACTS_DOMAIN is empty, or while the keys Worker has no ARTIFACT_SIGNING_KEYS:
- An HTML artifact shows the note "HTML artifacts are not set up on this forge", and its page does not run.
contentUrlis null in REST, MCP andsrc.- Markdown pages show their text, but not the images and other files next to them.
- Link artifacts work.
- People can still publish, share and comment on every kind of artifact.
In local development (pnpm dev), with the var empty, <owner>.localhost:5173 serves the pages, and you need none of these steps.
How the content host works
- The web Worker takes every request to
<owner>.<domain>before its other routes (apps/web/src/server/artifacts/content-host.ts). It reads onlyGETandHEAD. - A content URL is
/v/<capability>/<path>. The capability names the owner, the artifact and one version, and works for 10 minutes. The forge page gets a fresh one before it ends. - Every answer has a strict Content-Security-Policy, and no
Set-Cookie. Only the forge (EMAIL_ORIGIN) can frame a page. - The bytes of artifacts are in the
artifactsbucket of Neon object storage only, with no R2 copy. See Object storage on Neon.