Safely hosting arbitrary user HTML: the cookieless-origin sandbox pattern ShareMyPage lets users publish HTML generated by LLMs like Claude or ChatGPT and share it behind per-page access control. To safely host arbitrary user HTML, the service serves untrusted content from a cookieless subdomain (view.) separate from the app (app.), uses short-lived signed URLs for access control, and relies on the iframe sandbox attribute without allow-same-origin to isolate scripts. This pattern prevents uploaded JavaScript from accessing the app's session or APIs. ShareMyPage https://www.sharemypage.app lets people publish HTML, often generated by an LLM like Claude or ChatGPT, and share it behind per-page access control. So the core of the product is the one thing every security guide warns against: taking arbitrary HTML from users and serving it back, executing, in a browser. Here is how I make that safe. The same approach works for anything that hosts user-supplied HTML: comment previews, email renderers, no-code builders, AI artifact viewers. Rendering the HTML in an iframe on your own domain is broken. An iframe on app.yoursite.com shares an origin with your app. If you grant allow-same-origin , uploaded JavaScript can read document.cookie , call your same-origin APIs with the user's session, and walk your DOM. And combining sandbox with allow-same-origin is the trap: together they hand the untrusted code back the origin you were trying to take away. I serve untrusted HTML from a different origin than the app, view. instead of app. , and keep that origin cookieless. Three things work together. First, the separate origin. Because content lives on its own domain, the same-origin policy now protects you instead of working against you. Scripts in the page can't reach the app origin at all. Second, no cookies on the content origin. This isn't a hope, it's structural. The content route is left out of the auth middleware's matcher, so the origin never sets or receives an app session cookie. Even if isolation failed, there is no session to take. Third, the sandbox attribute leaves out allow-same-origin . The iframe gets a null origin. Scripts run, so interactive prototypes work, but they are cut off from anything that matters.