This document covers artifacts.posthog.com: one Cloudflare Worker that does three jobs. It is the MCP server, it is the OAuth authorization server for MCP clients, and it is the artifact viewer. It was last reviewed on 2026-10-30. That review combined an internal pass with an independent adversarial review. Every fix below has a regression check in scripts/smoke.mjs.
- Private artifact content. Internal analyses that can include customer data.
- The share-link capability. Holding a 131-bit ID for a public artifact grants access to it.
- User sessions and MCP grants. Either one lets the holder publish, read, share or delete artifacts as that user.
- The posthog.com origin's reputation. Content hosted on it is trusted by staff and customers.
| Actor | Can | Wants |
|---|---|---|
| Anonymous internet | Reach every route, register OAuth clients, hold public links | Read private artifacts, phish users, abuse resources |
| Artifact content (LLM output, possibly prompt-injected, or a malicious author) | Run arbitrary HTML/JS in the viewer | Escape the sandbox, steal tokens, phish the viewer |
| Malicious MCP client | Register, then send a staffer to /authorize |
Obtain a staffer's MCP token |
| Non-owner staff | Sign in | Read other people's private artifacts or old versions |
| Departed staff, or someone holding a stolen cookie/token | Replay credentials | Keep access |
- Who can sign in. "Sign in with PostHog" uses OIDC with PKCE as a public client. Access requires
email_verified === trueand an email exactly@posthog.com. The verified check is required because anyone can sign up to PostHog with an unverified address. - ID-token checks. Each ID token is bound to the issuer (exactly
https://us.posthog.com; EU Cloud and the region-agnosticoauth.posthog.comare not accepted), the audience (ourclient_id), the nonce and the expiry. The signature isn't checked: the token comes straight from the token endpoint over TLS, which OIDC Core §3.1.3.7 allows in place of a signature check. - Login-flow state. State, the PKCE verifier and the nonce live in a signed, 10-minute
__Host-cookie that is used once. After login,nextis resolved againstPUBLIC_URLand must stay on our origin. - Sessions. A session is a signed 7-day
__Host-cookie (HttpOnly, Secure, SameSite=Lax). Sign-out is a POST request. - Token purposes. Every signed token includes its purpose (
session/frame/login) in the MAC. That stops a public iframe grant being replayed as a session. The OAuth library's consent cookie gets a separately derived key.
- Owner-only actions. Every MCP tool and the share endpoint go through
getOwnedArtifact. Non-owners get "not found". - Private artifacts. To everyone except the owner, a private artifact looks the same as a missing one: signed-in users get a 404 and signed-out visitors are sent to sign in, in both cases.
- Team artifacts. Viewable by any signed-in user, which means a verified
@posthog.comaccount that hasn't been revoked. To signed-out visitors they look exactly like private ones (a sign-in redirect), and they carry no Open Graph tags, so unfurlers learn nothing. Like public links, team access covers the latest version only, and team iframe grants are re-checked on every load, so going back to private, or publishing a new version, cuts off open viewers. A revoked user's already-issued team grant lasts until it expires: 10 minutes for an iframe grant, an hour for an agent handover link. - Invited artifacts (customers). The visitor signs in with their own PostHog account through the same OIDC + PKCE flow as staff, but in a guest mode: any account with a verified email is accepted, and the artifact's allowlist decides access. The result is a
guestcookie (__Host-, HttpOnly, 7 days), a different token purpose from a session, so it cannot be replayed as one andgetUserignores it. It opens only artifacts whose allowlist still matches the address, checked on every view.- Gate. Anyone who isn't the owner, signed in or not, sees the same page with the sign-in buttons. It shows no title, author or other artifact detail and is never unfurled. Having a PostHog account, or being PostHog staff, earns nothing without being on the list.
- Issuers. Staff logins are still accepted from US Cloud only. Guest logins may go to US Cloud or EU Cloud (
POSTHOG_EU_OAUTH_HOST). The host is fixed in the signed login cookie at the start, and the ID token's issuer, audience, nonce and expiry are checked against it. - Trust. Identity is whatever PostHog asserts: we require
email_verified === trueand rely on PostHog's own verification of the address. - Allowlist. Exact addresses or
@domain(exact domain, not subdomains or lookalikes), at most 50 entries, consumer mail domains refused. A domain entry admits everyone with a verified address at that domain, so use it only for companies you'd share with entirely. - Revocation. Removing an entry, unsharing or publishing a new version cuts off open iframe grants on their next load (grants carry the address and are re-checked, like public and team grants). A guest's cookie lasts 7 days but opens nothing once they're off the list.
revoked:<email>also blocks a guest address.
- Quizzes. A quiz is JSON that we validate at publish (strict schema, every problem named by field) and render ourselves, so no author HTML or script runs next to the answers. The answer key and explanations never go to a taker: the page is built from
publicQuiz, which has neither, and scoring happens on the server. Everywhere else the source could leak is closed for quizzes: the iframe content route returns 404 for a quiz, and the agent handover route and download grant refuse everyone but the owner (the source is the key). A submission may contain onlyq_<question id>fields holding that question's option ids; unknown questions or options, repeats, and two picks on a single-choice question are refused. It is a same-origin POST with a 32 KB body cap checked before anything is parsed, then rate limited per taker (and per IP for signed-out takers) before the form is read, and read in one pass that refuses the first unknown question or more fields than any quiz can need. It is refused past the attempts limit and past a per-version ceiling (1,000 counted attempts from signed-out takers, 5,000 from signed-in ones, so a public link can't use up the room signed-in people need), and for the latest version only. Both limits are enforced inside the single INSERT ... SELECT that numbers the attempt, so submissions sent at the same moment can't all pass a check made before the insert; if no row is written the person is told they've hit a limit. (The table's unique key only stops two attempts getting the same number; it is not what enforces the limits.) A signed-out taker is identified to the quiz by a keyed hash of their browser ID, not the browser ID itself, which is also their analytics ID and so not a secret. A result can be read only by the person who made it or the owner, and only while its version is the shared one: once the owner publishes a new version, takers can no longer open results (or the questions and explanations behind them) from the old one. Signed-out takers of a quiz withoutshow_answerssee pass or fail but not points, because all-or-nothing scoring turns a points figure into an oracle for single answers. Takers' emails are stored with their attempts and shown only on the owner's Results page andquiz_results; the typed name of a signed-out taker is escaped everywhere andquiz_resultstells the model it is other people's words. Thequiz submittedevent carries the score and pass or fail but never answers or emails (guests use the hashed ID, as for views). Deleting the artifact deletes its attempts.- Residual risk. A public quiz can't tell takers apart beyond a cookie and an IP rate limit, so its results are indicative, not proof. With
show_answerson and unlimited attempts anyone can read off the key by retaking, which is the author's choice. Even with it off, a public quiz can't keep its key from someone patient: every request without a cookie is a new taker, so pass or fail can still be probed (slowly, at the rate limit, and only if the pass mark lets a partial attempt pass). Don't rely on a public quiz to keep its answers secret; use team or invited visibility for that. The owner's Results totals and per-question figures count every attempt, and the list shows signed-in people first, so a flood of signed-out ones can't hide them.
- Residual risk. A public quiz can't tell takers apart beyond a cookie and an IP rate limit, so its results are indicative, not proof. With
- Comments. Off per artifact until the owner turns them on. Who may write mirrors who may view, minus anonymous visitors: the owner; signed-in staff on team and public artifacts; invited guests on invited ones, with the allowlist re-checked on every post and delete, not taken from the cookie. Anonymous link viewers get no panel and every comment route answers 404 for them. All comment routes are same-origin POSTs. Bodies are plain text, capped at 2000 characters and 500 per artifact, and only ever rendered escaped. Posting is rate limited per person (
COMMENT_LIMITER). Authors may delete their own comments (matched on kind and address, so a staff address can't delete a guest's) and the owner may delete any.list_commentstells the model that comment text is other people's words, not instructions.- Comments on a passage. The artifact runs in a sandbox the viewer can't read, so a short script (
src/web/annotate.ts) is added to the artifact's own response and runs in that same opaque-origin iframe. It is only added when the signed frame grant says the viewer can see comments, and the content route re-checks that comments are still on and the version is still the latest, so turning comments off or publishing again removes it. It talks to the viewer only bypostMessage, targeted at the viewer's origin; the viewer accepts messages only from that iframe's window, treats everything as untrusted text, and uses it only to fill a form the person still has to submit or to toggle a class. The artifact's own code shares the iframe with the script and can send the same messages, so a hostile artifact can at worst prefill a comment box with text it chose or mark comments as not found. The viewer sends the iframe only the quoted passages and comment ids, never comment bodies or authors. Quotes are cleaned of control characters, capped at 500 characters (context 64), and only ever rendered escaped, including inside attributes. The script adds no DOM to the artifact apart from a closed shadow-root button on the document element. - Residual risk. A thread is visible to every viewer who can comment, so an internal remark on an artifact that is also shared with customers is visible to them. The panel says who can see comments, but the owner is the control.
- Comments on a passage. The artifact runs in a sandbox the viewer can't read, so a short script (
- Public links. A public link exposes the latest version only. Public iframe grants are re-checked on every load, so unsharing an artifact, or publishing a new version, cuts off people who already have it open.
- Kill switch.
revoked:<email>inOAUTH_KVis checked on every web request and every MCP call:It's also checked on every load of an owner's content links: their iframe grants and the agent handover links they made (valid for an hour, and possibly pasted into an agent or elsewhere). Revoking an owner cuts those off straight away. Links issued to other viewers of a team or public artifact are still checked against the artifact, not the viewer, so a revoked staff member's team link lasts until it expires: 10 minutes for an iframe grant, an hour for a handover link.wrangler kv key put --binding OAUTH_KV --remote revoked:someone@posthog.com 1
- Sandbox. Content renders in
<iframe sandbox>and also carriesContent-Security-Policy: sandbox. Either way the content gets an opaque origin, so it can't read our cookies or call our API as the viewer. - Sandbox flags we never grant:
allow-same-origin,allow-top-navigation*orallow-modals. - Viewer-only rendering.
/c/*only serves requests withSec-Fetch-Dest: iframe. Content can't be opened as a bare page on our domain (phishing) or fetched as a document, for example as an OAuth client metadata document. It is always shown under PostHog chrome that names the author. - Frame grants. These are signed and expire after 10 minutes.
- No tab-nabbing. The viewer sends
Cross-Origin-Opener-Policy: same-origin, so popups the content opens can't navigate the viewer tab. - Optional content host.
CONTENT_URLmust be a different registrable domain, such asposthogusercontent.com. On aposthog.comsubdomain, content could set cookies for every posthog.com app. WhenCONTENT_URLis set, content is never served from the app origin.
- Where tokens can go. MCP clients may only send tokens to loopback addresses (Claude Code and other local clients) or to hosts in
MCP_REDIRECT_HOSTS(defaultclaude.ai,claude.com). This is enforced at both registration and/authorize. - No self-hosted client IDs. Client metadata documents hosted on our own domains are refused, so the consent page can never say "Published by artifacts.posthog.com" for a client that an artifact author controls.
- Consent page protections. The consent page is bound to the browser, single-use and impossible to frame (library helpers). The consent POST must be same-origin. Remembered consent is per user, client, redirect URI and resource.
- Registration rate limit. Dynamic client registration is limited to 10 per minute per IP.
- Our own pages send:
- a strict CSP (
script-src 'self', no inline script or styles,frame-ancestors 'none') X-Frame-Options: DENY, HSTS,nosniffandnoindexReferrer-Policy: same-origin, withno-referreron content
- a strict CSP (
- Cross-site POSTs. State-changing POSTs check
Sec-Fetch-Site(falling back toOrigin) on top of the SameSite cookies. - Login errors. These travel as fixed codes, so nobody can put their own text on the sign-in page.
- Escaping. Templates use hono/html auto-escaping, and
raw()is used only for static SVGs.
- Publish limits. 5 MB per version and 30 publishes per minute per user. The MCP body limit (about 10 MB, to allow for JSON escaping) is enforced before the SDK sees the request, which works around an
agentsbug that applied a 4 MB default. - Bounded queries. The viewer's version list is capped.
- No orphaned files. If the database write fails, the uploaded R2 object is deleted.
- Migrations. They are idempotent (
IF NOT EXISTS) and applied transactionally by the Worker.
- Phishing by insiders. A staff member, or an agent that has been prompt-injected, can still publish a convincing phishing page inside the viewer, and share it. The viewer shows the author's name, and revocation is immediate. Moving content to a separate registrable domain (
CONTENT_URL) would further separate it from posthog.com trust. - Leaked public links. A public link is a bearer capability. Whoever holds it can view until the owner sets the artifact back to private.
- Offboarding. Revocation is manual (the KV key). Tie it to the HR or IdP offboarding process. Unrevoked sessions last at most 7 days. MCP refresh grants last up to 30 days unless revoked.
- Rate-limit scope. Limits are counted per Cloudflare location, not globally.
- Rendering cost. Markdown is rendered on every public view. That's cheap, but an attacker could amplify it with a very popular link. Add caching if traffic grows.
- Scope. There is a single
artifactsscope, so any MCP grant can also delete. Split read and write scopes if third-party clients ever get access.