Open Graph link previews (SPAs, private posts, private-storage media)
open-graphlink-previewsspaflutter-webs3presigned-urlscachingprivacy
Link previews (Discord, iMessage, Slack, Facebook) are built from og:title, og:description, og:image, og:url and og:type tags. When the media lives in a private bucket, the image URL needs special handling.
Preview fetchers (and iMessage, which builds the card on the sender's phone) do not run JavaScript. They read the raw HTML of the URL once. Everything below follows from that.
Single-page apps: inject tags per route on the server
A Flutter web or other SPA serves the same index.html for every path, so every link previews
as the bare app name. The fix needs no server-side rendering of the app itself:
- A rewrite sends only the shareable path patterns to a small script, e.g. on Apache at vhost
level: RewriteRule ^/(s/[0-9a-f]{32}|posts/[0-9]+)/?$ /path/to/link_preview.php [L].
- The script reads the built index.html, strips its static og:/twitter: tags, swaps
<title> and the description, and injects per-link og:*, twitter:* and a canonical link
just before </head>. The <body> stays byte-identical, so the app boots exactly as before
for a human visitor.
- Send Cache-Control: no-cache (the answer depends on the post's current state) and
X-Robots-Tag: noindex.
- Keep the script outside the API's public docroot if it reads files the API must not serve.
- Also put site-wide default og tags (name, icon) in index.html itself, so the bare domain
and every other route get a branded card instead of nothing.
- og:description: strip markdown and cut to ~200 characters; fall back to "By summary_large_image, minus any URL fragment.
What a preview may reveal
A preview is served to an anonymous fetcher, so it can only show what an anonymous visitor
may see. Decisions from TLDR (canon there, 2026-10-30):
- Sequential ids are an enumeration oracle. If /posts/<id> previews showed titles for
non-private posts, anyone could walk the ids and harvest every title without an account. Those
links get a generic card ("A post on tldr. Sign in to read it.").
- Capability links (/s/<token>) get the real title, excerpt and image, because holding the
token already grants read access. See "Anyone with the link" share links (capability URLs). Check validity on every
fetch: a revoked, deleted or unpublished target answers with a generic "no longer available".
- A sent preview cannot be recalled. iMessage embeds the card in the message; other SMS/RCS
apps store it with the conversation (and its backups); Slack, Discord and Facebook cache
server-side for hours to days. Making a post private later only affects new fetches.
- Images leak their URL. If uploads are served from unauthenticated URLs, a preview image
hands the recipient a permanent direct link that survives the post going private. Prefer
title-only cards where images would widen an existing gap.
og:image cannot be a pre-signed URL
A preview image is fetched by the chat service's servers at a time of their choosing and then cached, often for days. A six-hour signature works for an afternoon and becomes a broken image in every chat the link was ever pasted into. Use a stable, unsigned route that streams the image from the bucket, e.g. /poster/<slug>.jpg. Stream it rather than redirect: a redirect hands over the very URL that expires.
The privacy rule for the unsigned route
An unsigned route asks for no session, so anything it serves is public to anyone with the address.
- Serve public, unencrypted items only.
- Anything else answers 404, not 403, so the route cannot be used to learn what exists.
- Enforce it in two places on purpose: where the tag is written (no og:image at all for a hidden item, which degrades to a text-only card) and in the route itself, which is the actual door.
- Page descriptions should count only what an anonymous visitor is listed, not the whole catalog (that leaks how much is hidden) and not only the freely playable items (which undercounts).
Caching the route
Let the script own its caching: a day for a poster, five minutes for a 404 (the answer changes when an item is made public), no-store when the bucket is unreachable. On Apache, a blanket Header always set Cache-Control on *.php silently overrides this; see Apache vhost gotchas (icons alias, manifests, SPA fallback, redirects).
Routing note
With FallbackResource routing series pages by slug, an AliasMatch for /poster/*.jpg must come before the FallbackResource line or the fallback swallows it.
Testing
Fetch with a crawler user agent (curl -A facebookexternalhit/1.1) and diff against the plain
index.html: only the head should differ. Apps that already fetched a link may keep their old
card for a while, so test with a fresh URL.
See also
- Flutter web (renderers, SEO, performance, when not to use it)
- videos.jhampton.io (private video site architecture)
- Linode (Akamai) Object Storage
Linked from
- "Anyone with the link" share links (capability URLs)
- Generating iCalendar (.ics) files and subscribe feeds
- Linode (Akamai) Object Storage
- TLDR platform architecture (tldrnerd.com)
- Upload links for people without an account (getting a full-quality video from a friend)
- videos.jhampton.io (private video site architecture)