Skip to content

feat: run apps and HTML docs on a separate content origin - #15

Merged
onmax merged 1 commit into
mainfrom
feat/app-content-origin
Oct 12, 2026
Merged

onmax merged 1 commit into
mainfrom
feat/app-content-origin

Conversation

@onmax

@onmax onmax commented Oct 12, 2026

Copy link
Copy Markdown
Member

Why

App and HTML drops ran in an opaque-origin sandbox. In that sandbox localStorage, sessionStorage, document.cookie, and history.pushState throw a SecurityError ("The operation is insecure" in Safari/Firefox). The Lakebed landing app crashed on history.replaceState.

What changes

  • DROP_CONTENT_ORIGIN (optional): a second hostname served by the same deployment, e.g. https://drop-usercontent.vitehub.dev. It answers every path with a small frame-host page and nothing else (no API, pages, or files; non-document fetches 404). The viewer frames it at the page's own URL (/, /product/) and sends the document over postMessage, so private drops and unsaved edits never pass through that origin's server.
  • The viewer follows in-frame navigation (links, pushState, reloads) and switches the page selector. Apps that frame their own pages get their documents relayed up through each level. Messages to and from the frame are pinned to the content origin.
  • Without a content origin, an in-memory shim replaces storage and cookies and ignores URL changes in the opaque sandbox, so apps stop crashing. Apps that route by URL still need the content origin.
  • Subdomain hardening:
    • On HTTPS, Better Auth cookies are now __Host-drop.*, so a sibling subdomain can't overwrite them (cookie tossing). This signs everyone out once on deploy.
    • Cookie-carrying writes to /api/* must come from Drop's own origin (Sec-Fetch-Site / Origin). Same-site subdomains would otherwise get Lax cookies on no-preflight requests. Agents use bearer tokens and aren't affected.
  • Docs: self-host guide (new "Give apps their own domain" section, Cloudflare/VPS notes, keep it outside oauth2-proxy), README, .env.example, the review docs, and the skill reference.

Verification

  • node --test test/*/*.test.mjs: 95 pass, 3 skipped (need a live server). New test/content-origin/runtime.test.mjs covers host routing, the write guard, detail payloads, page/URL mapping, head injection, and the opaque shim.
  • pnpm typecheck passes.
  • Cloudflare build under wrangler dev, with Chromium, WebKit, and Firefox via Playwright:
    • the real Lakebed app (39 files) renders, including its nested self-embed;
    • a test app's localStorage + replaceState work;
    • link navigation is followed and the page selector reloads the frame;
    • text comments and markers work;
    • an HTML doc gets localStorage.
  • Opaque fallback: the same app no longer throws.

🤖 Generated with Claude Code

Apps and HTML docs ran in an opaque-origin sandbox, where localStorage,
cookies, and history.pushState throw a SecurityError ("The operation is
insecure"). Apps that route by URL or persist state crashed.

DROP_CONTENT_ORIGIN names a second hostname served by the same deployment.
It only serves a frame host page; the viewer sends each document over
postMessage, so private drops never pass through it. Apps get a real URL per
page, Drop follows in-frame navigation, and apps that frame their own pages
are relayed. Without it, an in-memory shim keeps apps from crashing.

Subdomain hardening: Better Auth cookies use the __Host- prefix on HTTPS so a
sibling subdomain can't toss them, and cookie-carrying API writes must come
from Drop's own origin.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-12T16:20:35.033915Z 1132c84 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@onmax
onmax merged commit 5d9a8a6 into main Oct 12, 2026
@onmax
onmax deleted the feat/app-content-origin branch October 12, 2026 16:18

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1132c842bf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +39 to +44
addEventListener("message", (event) => {
const message = event.data;
if (event.source !== parent || !message || message.__drop !== true || message.type !== "document" || typeof message.html !== "string") return;
document.open();
document.write(message.html);
document.close();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Reject untrusted parents before writing preview HTML

Any third-party page can iframe the content-origin host and send a __drop/document message, because the handler only checks that the sender is the immediate parent and does not validate its origin or restrict framing. The supplied HTML is then written into an unsandboxed document on the content origin, allowing attacker-controlled scripts to run there and read or exfiltrate shared localStorage/cookies and data belonging to apps the user has visited. Bind the host handshake to the Drop origin (preferably with a nonce) or prevent the host from being framed by untrusted sites before accepting documents.

Useful? React with 👍 / 👎.

onmax added a commit that referenced this pull request Oct 20, 2026
…re anchor through the zoom's own mapping

comark-annotate 0.2.0, with comark-zoom and comark-annotate patched to comark-plugins main plus
onmax/comark-ui#25 and #15 until a release has them: the zoom puts a screenshot's notes in a column beside it,
a mark and its note light up together, and the zoom's events map copies to the page and back (copyOf/originalOf).

The frame runtime uses that mapping instead of its own child-index walk. A comment on a note in the zoom draws in a
layer inside the notes column, which covered it on the zoom's layer, and anchors to the note on the page.

0.2.0 renamed a screenshot's `url` to `href` and `label` to `title`, and reports the old names. Published docs keep
them, so the renderer reads them as the new names; the pr-evidence skill teaches the new ones. Issues are in
meta.issues now. The render cache's integrity moves to 3, since the screenshot markup changed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant