Skip to content

ADR 0012 — Previews for people who do not edit ​

  • Status: Accepted
  • Date: 2026-11-26
  • Context repos: cratly.io site (this repo), editor, s3-http

Problem ​

A site's owners want to show a draft to people who neither edit nor have an account with the git host: management, a client's client, an agency signing off on a layout. Today, seeing a draft means signing in to the editor. That requires an account, and someone has to explain the editor to every reviewer.

The editor's preview already works without a server. It downloads the build artifact of a draft, hands its files to a page on a separate preview origin, and a service worker there answers the browser's requests from those files. No file reaches a server; the files stay in the reader's browser. The editor itself is the only thing standing between a reviewer and that preview.

Three ways to take the editor out of that path were considered:

  1. An archive with its own HTTP server that a reviewer downloads and starts.
  2. A page beside the editor that takes an archive and previews it the way the editor does, on the same preview origin.
  3. A staging deployment of the draft branches, protected by a password.

Why not the obvious ways ​

An archive with a server cannot be opened by double-clicking index.html. The pages refer to their assets from the root, and clean URLs need a server that resolves them. So the archive has to bring a program along. That program is unsigned for macOS and Windows, and a company's policy blocks it. The people this is meant for are the ones least able to get past either obstacle.

Taking an archive on today's preview origin is a change of a few lines, because the service worker already serves whatever it was given. The installer refuses every sender but the editor, and only that refusal makes the origin safe to run under a cratly name:

  • Phishing under our name. Anyone could send a prepared archive along with the instruction "open preview.… and pick this file". The address bar would then show a cratly host over a login form of the sender's choosing.
  • Previews tampering with each other. Every preview shares one origin. A script in one archive can write to the Cache API or other storage of that origin and change what the next preview shows, which may be another customer's site. Today only builds of repositories the user can access ever arrive there.

A staging deployment is safe and serves the site exactly as it goes live. However, each site has to arrange it with its own hosting: a host name, credentials and a deploy job. That is a separate setup for every customer, not a feature of cratly.

Signing archives does not cure option 2 by itself. Pipelines run on our customers' runners, so a single key shared by every cratly pipeline is a published key. Even if it stayed secret, cratly is open source: anyone can build a site, and a site may contain any HTML and JavaScript. The statement "built by a cratly pipeline" says nothing about whether the content is harmless. A signature only carries weight with one key per site owner that someone registers and vouches for. That means key management, revocation, and leaving out everyone who runs cratly without us.

Decision ​

Previews of an archive are served from a domain of their own, one origin per archive.

Both risks of option 2 come from the origin, not from where the archive was built. The fix is the one GitHub and Google use for user content (githubusercontent.com, googleusercontent.com):

  • A neutral registrable domain for the content, unrelated to cratly.io. A forged login page shown there carries no cratly name and is worth no more to a phisher than any free host.
  • One origin per archive, named after the archive's hash, e.g. <hash>.<content-domain>. Cache, service worker and storage of one preview are out of reach for every other preview.

The difference from option 2 is only where the files are shown. The mechanism stays the same as in the editor today:

  1. A reviewer opens the start page on the bare domain and picks the archive they were sent.
  2. The start page names the archive's origin after the first 32 hex digits of the archive's SHA-256 and, on the reviewer's click, opens <hash>.<content-domain> in a new tab.
  3. That origin runs the editor's preview installer and service worker unchanged. The installer accepts the files from the bare domain or its www host alone, as it accepts them from the editor alone on the editor's preview origin.
  4. Before showing the site, the installer drops the preview's handle on the page that opened it (window.opener). Otherwise the previewed site, being foreign content, could send the start page or the editor to an address of its choosing.
  5. The files stay in the reviewer's browser. Nothing is uploaded.

The archive is the build artifact the editor already offers for download next to its preview. Turning it into the files of a preview is one module that both the editor and the start page use, so a draft looks the same in both.

The editor's own preview stays as it is. Sharing is an additional option, not a replacement.

Signatures are an optional addition, not the protection. Where an archive carries a signature by a key we have registered, the start page could say whose draft it is. An archive without a signature previews all the same. None is implemented yet.

Keeping and deleting a preview ​

A preview's files sit in the Cache Storage of the archive's origin. That is persistent storage: the preview survives closing and restarting the browser. It goes when the reviewer deletes it, clears the browser's site data, or the browser evicts it for lack of space. Safari does so after seven days without a visit, and a private window drops it on closing. Reviewers want both outcomes: one that opened a draft on a shared computer wants it gone, another one wants it back after a browser update. So the start page explains how long a preview stays and offers to delete it, and does not set an expiry of its own. An expiry could act only once the browser runs the preview's code again, which would make it a promise the start page cannot keep.

The start page cannot reach the storage of another origin, not even to find out what is there. It therefore keeps a list of the archives it has handed over in its own local storage: the file name, the size, when the archive was opened, and the origin's label. Nothing of the archive's contents goes into that list. The page lists these previews, opens them again without the archive, and deletes them.

To check on a preview or delete it, the start page embeds that origin's installer invisibly. The installer answers requests from the same senders that may fill the cache. For this to work, the archives' origins allow the start page, and only the start page, to embed them. Both sit on the same site, so the embedded origin sees the same storage as the preview itself. On loading, the start page drops previews from the list that the browser no longer holds. The list belongs to the address the start page was opened on, so the content domain's www host redirects to the bare domain to keep a single list.

Serving one origin per archive ​

s3-http serves a subdomain from a folder named after it. For names generated per archive, it falls back to a domain's _wildcard folder when a subdomain has none of its own. The content domain therefore holds two folders:

FolderServesContents
www/the bare domain and wwwthe start page
_wildcard/every <hash>.<content-domain>installer, service worker, a landing page

s3-http accepts a host label of at most 32 characters, which is why the hash is cut to that length. 128 bits are still more than enough to keep the archives apart.

What this does not decide ​

  • How an archive gets to the reviewer. A real site measured 39 MB as an archive, almost all of it pictures that do not compress. That is too large for mail; a cloud share or whatever the site owner uses for large files has to carry it.
  • The format of signatures and the key registry, should the optional addition be wanted.
  • How the editor points authors at the start page. Today an author downloads the archive and passes on the start page's address themselves.

Consequences ​

  • The content domain needs a wildcard DNS record and a wildcard certificate. The latter requires a DNS-01 challenge at the reverse proxy in front of s3-http.
  • The editor's pipeline deploys both folders when S3_SHARE_BUCKET names the content domain's bucket; see Editor CI.
  • A reviewer's browser keeps one service worker and cache per archive viewed until the reviewer deletes them on the start page or the browser evicts them, see Keeping and deleting a preview.

See also ​