Skip to content

Gift links: reader access path (/g/, gating, counting) - #28629

Closed
jonatansberg wants to merge 2 commits into
mainfrom
ber-3728-gift-links-reader-access
Closed

jonatansberg wants to merge 2 commits into
mainfrom
ber-3728-gift-links-reader-access

Conversation

@jonatansberg

Copy link
Copy Markdown
Member

ref https://linear.app/ghost/issue/BER-3728

Slice 3 of 4 carving up the gift-links spike (#28625). Stacked on #28627 (BER-3727 service & admin API) — review/merge that first.

What this adds

The reader access path for gift links:

  • /g/<slug>/?key=TOKEN router + controller — a dedicated top-level prefix (like /p/ previews), outside the theme's collection space, with a path-based cache boundary.
  • Token-resolving middleware — resolves ?key= into a content-only access grant on res.locals.giftLink before routing dispatches; sets X-Robots-Tag: noindex + Referrer-Policy: no-referrer on gift requests.
  • Cache bypass — /g/ responses are never cached (they contain unlocked gated content); the controller's invalid-token 301s carry their own Cache-Control: no-store.
  • Posts-public cache key — keyed so gift renders don't poison the canonical cache.
  • Content gating honours the gift grant — a valid token unlocks the post's content (and member-only gated blocks) for an otherwise-anonymous reader, only for the post the token was minted for.
  • Read counting — bot-filtered, cookie-deduped, fire-and-forget increment of redeemed_count.
  • @gift template context — documented, set only on the verified render path (never on redirects/404s/canonical routes). No default reader UI; theme authors opt in via {{#if @gift}}.

Review fixes folded in

  • A. No self-redirect loop — the invalid-token fallback 301 now guards that the redirect target isn't itself under /g/ (or equal to the current path), falling through to 404 instead of looping when a site permalinks a collection under /g/.
  • B. Real errors surface — readPostOrPage only swallows genuine NotFoundError; any other error (DB timeout, serializer crash) is logged and re-thrown so the controller returns a real 5xx instead of a wrong 301-to-paywall.
  • C. Bot UA matching tightened — generic tokens (bot, monitor, preview, scanner, spider) are word-boundary anchored so real devices (e.g. Cubot's CUBOT_X30) are no longer misclassified as bots; all real crawler UAs still match. New test case asserts the Cubot UA is not a bot.
  • D. Counting works behind TLS-terminating proxies — secure is now passed at the new Cookies(req, res, {secure}) constructor level (mirroring members-ssr) instead of as a per-.set() option, which the cookies lib throws on when the connection isn't seen as https — that throw previously skipped recordRead.
  • E. Dedup cookie persists across sessions — the gift_seen cookie now carries a 1-year maxAge so the once-per-client-per-post dedup survives browser restarts (it was session-only, inflating redeemed_count).
  • Best-effort: single /g/ prefix constant (GIFT_LINK_PREFIX) shared by the router and frontend-caching.

Documented follow-ups (out of this slice's scope)

  • Read amplification — the posts-then-pages fallback can double-read, and the invalid-token fallback could resolve via urlService instead of a second API read.
  • Analytics token leak — ghost-stats sends location.href including ?key=; tracked in the BER-3728 ticket.

Tests

  • New: controller self-redirect/error-surfacing unit tests; middleware counting persistence/no-throw tests; Cubot bot-UA case.
  • Reader e2e (@gift marker + no-leak-on-404) green.

@coderabbitai

coderabbitai Bot commented Jun 16, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 1acb75f5-875c-447a-9e73-eaf5ff2e4af4

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ber-3728-gift-links-reader-access

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@nx-cloud

nx-cloud Bot commented Jun 16, 2026 •

Copy link
Copy Markdown

🤖 Nx Cloud AI Fix

Ensure the fix-ci command is configured to always run in your CI pipeline to get automatic fixes in future runs. For more information, please see https://nx.dev/ci/features/self-healing-ci


View your CI Pipeline Execution ↗ for commit 59e6a67

Command Status Duration Result
nx run @tryghost/admin-x-settings:test:acceptance ✅ Succeeded 9m 48s View ↗
nx build @tryghost/comments-ui ✅ Succeeded <1s View ↗
nx build @tryghost/activitypub ✅ Succeeded 2s View ↗
nx build @tryghost/admin-toolbar ✅ Succeeded <1s View ↗
nx build @tryghost/portal ✅ Succeeded <1s View ↗
nx build @tryghost/announcement-bar ✅ Succeeded <1s View ↗
nx build @tryghost/signup-form ✅ Succeeded <1s View ↗
nx build @tryghost/sodo-search ✅ Succeeded <1s View ↗
Additional runs (15) ✅ Succeeded ... View ↗

💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-06-22 07:04:44 UTC

@jonatansberg
jonatansberg force-pushed the ber-3727-gift-links-service-admin-api branch from bca071c to 27420ed Compare June 16, 2026 14:30
@jonatansberg
jonatansberg force-pushed the ber-3728-gift-links-reader-access branch from 175b158 to b8929b0 Compare June 16, 2026 14:30
@jonatansberg
jonatansberg force-pushed the ber-3727-gift-links-service-admin-api branch from 27420ed to d85e91e Compare June 16, 2026 14:39
@jonatansberg
jonatansberg force-pushed the ber-3728-gift-links-reader-access branch from b8929b0 to 8cd81c6 Compare June 16, 2026 14:39
@jonatansberg
jonatansberg force-pushed the ber-3727-gift-links-service-admin-api branch from d85e91e to 05de009 Compare June 17, 2026 06:31
@jonatansberg
jonatansberg force-pushed the ber-3728-gift-links-reader-access branch from 8cd81c6 to 8689fcd Compare June 17, 2026 06:31
@jonatansberg
jonatansberg force-pushed the ber-3727-gift-links-service-admin-api branch from 05de009 to 61115dc Compare June 17, 2026 06:52
@jonatansberg
jonatansberg force-pushed the ber-3728-gift-links-reader-access branch 2 times, most recently from 53fd483 to 124210d Compare June 17, 2026 07:54
@jonatansberg
jonatansberg force-pushed the ber-3727-gift-links-service-admin-api branch from 61115dc to 1b0362f Compare June 17, 2026 09:28
@jonatansberg
jonatansberg force-pushed the ber-3728-gift-links-reader-access branch 3 times, most recently from b6a6081 to 82f5eb2 Compare June 17, 2026 11:22
@codecov

codecov Bot commented Jun 17, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.56701% with 43 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.04%. Comparing base (4620a3b) to head (59e6a67).
⚠️ Report is 81 commits behind head on main.

Files with missing lines Patch % Lines
...rontend/services/routing/controllers/gift-links.ts 91.21% 21 Missing ⚠️
...core/core/server/services/gift-links/middleware.ts 92.30% 12 Missing ⚠️
...host/core/core/server/services/gift-links/index.ts 91.66% 3 Missing ⚠️
...st/core/core/server/services/gift-links/service.ts 96.90% 3 Missing ⚠️
...ore/core/server/services/members/content-gating.js 62.50% 3 Missing ⚠️
...host/core/core/server/services/gift-links/model.ts 97.95% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #28629      +/-   ##
==========================================
+ Coverage   73.81%   74.04%   +0.22%     
==========================================
  Files        1550     1559       +9     
  Lines      133527   134477     +950     
  Branches    16065    16206     +141     
==========================================
+ Hits        98561    99569    +1008     
+ Misses      33989    33914      -75     
- Partials      977      994      +17     
Flag Coverage Δ
admin-tests 55.10% <ø> (+0.04%) ⬆️
e2e-tests 76.17% <95.56%> (+0.23%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jonatansberg
jonatansberg force-pushed the ber-3727-gift-links-service-admin-api branch from 1b0362f to 3332e19 Compare June 17, 2026 13:25
@jonatansberg
jonatansberg force-pushed the ber-3728-gift-links-reader-access branch from 82f5eb2 to e6b653b Compare June 17, 2026 13:25
@jonatansberg
jonatansberg force-pushed the ber-3728-gift-links-reader-access branch from e6b653b to a9646c3 Compare June 17, 2026 14:17
@jonatansberg
jonatansberg force-pushed the ber-3727-gift-links-service-admin-api branch from 3332e19 to 90ac687 Compare June 17, 2026 14:17
@jonatansberg
jonatansberg force-pushed the ber-3728-gift-links-reader-access branch from a9646c3 to f36455f Compare June 18, 2026 16:06
@jonatansberg
jonatansberg changed the base branch from ber-3727-gift-links-service-admin-api to feat/gift-links-redesign June 18, 2026 16:07
@rob-ghost
rob-ghost force-pushed the feat/gift-links-redesign branch from d8397b5 to 5c2cc52 Compare June 18, 2026 16:31
@rob-ghost
rob-ghost force-pushed the feat/gift-links-redesign branch from 5c2cc52 to 4d8c687 Compare June 18, 2026 18:22
ref https://linear.app/ghost/issue/BER-3728

- /g/<slug>/?key=TOKEN router + controller, token-resolving middleware,
  cache bypass, posts-public cache key, and the documented @gift template
  context (no default reader UI; theme authors opt in via {{#if @gift}})
- content gating honours a gift access grant; bot-filtered, cookie-deduped
  read counting
- consumes the #28693 gift-links service (getPostByToken / recordRedemption);
  service reached via the frontend proxy seam, not a direct require
- fixes: no self-redirect loop under /g/ collections; real errors surface
  instead of 301-to-paywall; bot UA matching no longer false-positives real
  devices; read counting works behind TLS-terminating proxies and dedupes
  across sessions
- slice 3 of 4 carving up spike #28625; stacked on the gift-links redesign (#28693)
@jonatansberg
jonatansberg force-pushed the ber-3728-gift-links-reader-access branch from f36455f to 59e6a67 Compare June 22, 2026 06:52
Base automatically changed from feat/gift-links-redesign to main June 22, 2026 12:58
kevinansfield added a commit that referenced this pull request Jun 22, 2026
ref https://linear.app/ghost/issue/BER-3728

- the public reader path for gift links: /g/<slug>/?key=TOKEN renders a
  paid post's full content to an anonymous visitor holding a valid token,
  reworked from the spike (#28629) to keep one owner and reuse the render
  pipeline
- the whole flow lives in a single controller: no site-wide middleware and
  no res.locals hand-off. getPostByToken now returns just {id, type}, so the
  happy path is one by-id read through the real public serializer
- access is granted the same way /p/ previews grant it — a synthesized
  all-active-paid-tiers member — rather than threading a gift branch through
  content-gating, post-gating and the posts-public cache key. The synthesis
  is extracted to members/synthesize-member.js and previews.js refactored
  onto it, so the security-sensitive grant has one source of truth
- the token is authoritative and the slug cosmetic: a stale slug on a valid
  token canonicalises to /g/<current-slug>/?key=…; an invalid/missing token
  301s the slug to its canonical URL with the key dropped, or 404s (the
  single redirect-loop guard: never redirect to a target under /g/)
- the router mounts in preview's privileged position so /g/ always wins over
  a routes.yaml collection; frontend-caching marks /g/ no-store so the edge
  never caches unlocked content; everything gated on labs.giftLinks
kevinansfield added a commit that referenced this pull request Jun 22, 2026
ref https://linear.app/ghost/issue/BER-3728

- the public reader path for gift links: /g/<slug>/?key=TOKEN renders a
  paid post's full content to an anonymous visitor holding a valid token,
  reworked from the spike (#28629) to keep one owner and reuse the render
  pipeline
- the whole flow lives in a single controller: no site-wide middleware and
  no res.locals hand-off. getPostByToken now returns just {id, type}, so the
  happy path is one by-id read through the real public serializer
- access is granted the same way /p/ previews grant it — a synthesized
  all-active-paid-tiers member — rather than threading a gift branch through
  content-gating, post-gating and the posts-public cache key. The synthesis
  is extracted to members/synthesize-member.js and previews.js refactored
  onto it, so the security-sensitive grant has one source of truth
- the token is authoritative and the slug cosmetic: a stale slug on a valid
  token canonicalises to /g/<current-slug>/?key=…; an invalid/missing token
  301s the slug to its canonical URL with the key dropped, or 404s (the
  single redirect-loop guard: never redirect to a target under /g/)
- the router mounts in preview's privileged position so /g/ always wins over
  a routes.yaml collection; frontend-caching marks /g/ no-store so the edge
  never caches unlocked content; everything gated on labs.giftLinks
kevinansfield added a commit that referenced this pull request Jun 22, 2026
ref https://linear.app/ghost/issue/BER-3728

- the public reader path for gift links: /g/<slug>/?key=TOKEN renders a
  paid post's full content to an anonymous visitor holding a valid token,
  reworked from the spike (#28629) to keep one owner and reuse the render
  pipeline
- the whole flow lives in a single controller: no site-wide middleware and
  no res.locals hand-off. getPostByToken now returns just {id, type}, so the
  happy path is one by-id read through the real public serializer
- access is granted the same way /p/ previews grant it — a synthesized
  all-active-paid-tiers member — rather than threading a gift branch through
  content-gating, post-gating and the posts-public cache key. The synthesis
  is extracted to members/synthesize-member.js and previews.js refactored
  onto it, so the security-sensitive grant has one source of truth
- the token is authoritative and the slug cosmetic: a stale slug on a valid
  token canonicalises to /g/<current-slug>/?key=…; an invalid/missing token
  301s the slug to its canonical URL with the key dropped, or 404s (the
  single redirect-loop guard: never redirect to a target under /g/)
- the router mounts in preview's privileged position so /g/ always wins over
  a routes.yaml collection; frontend-caching marks /g/ no-store so the edge
  never caches unlocked content; everything gated on labs.giftLinks
kevinansfield added a commit that referenced this pull request Jun 22, 2026
ref https://linear.app/ghost/issue/BER-3728

- the public reader path for gift links: /g/<slug>/?key=TOKEN renders a
  paid post's full content to an anonymous visitor holding a valid token,
  reworked from the spike (#28629) to keep one owner and reuse the render
  pipeline
- the whole flow lives in a single controller: no site-wide middleware and
  no res.locals hand-off. getPostByToken now returns just {id, type}, so the
  happy path is one by-id read through the real public serializer
- access is granted the same way /p/ previews grant it — a synthesized
  all-active-paid-tiers member — rather than threading a gift branch through
  content-gating, post-gating and the posts-public cache key. The synthesis
  is extracted to members/synthesize-member.js and previews.js refactored
  onto it, so the security-sensitive grant has one source of truth
- the token is authoritative and the slug cosmetic: a stale slug on a valid
  token canonicalises to /g/<current-slug>/?key=…; an invalid/missing token
  301s the slug to its canonical URL with the key dropped, or 404s (the
  single redirect-loop guard: never redirect to a target under /g/)
- the router mounts in preview's privileged position so /g/ always wins over
  a routes.yaml collection; frontend-caching marks /g/ no-store so the edge
  never caches unlocked content; everything gated on labs.giftLinks
kevinansfield added a commit that referenced this pull request Jun 23, 2026
ref https://linear.app/ghost/issue/BER-3728

- the public reader path for gift links: a paid post/page's own URL plus
  ?gift=TOKEN renders its full content to an anonymous visitor holding a
  valid token, reworked from the spike (#28629) to build on the existing
  routers rather than a dedicated /g/ route
- because collection/static-pages routing already resolves the URL, the
  resource type is known up-front: no dedicated router, no slug
  canonicalisation and no redirect-loop guard — the entry controller owns
  the whole flow
- the token is verified against the entry that lives at the request URL via
  the in-memory URL service, so a token for one post can never unlock
  another; getPostByToken returns just the post id
- access is granted the same way /p/ previews grant it — a synthesized
  all-active-paid-tiers member — passed to entryLookup as a read-context
  override only, so gating reveals member-only content while
  res.locals.member / @member stays the visitor's real member. The synthesis
  is extracted to members/synthesize-member.js and previews.js refactored
  onto it, so the security-sensitive grant has one source of truth
- an invalid/revoked/wrong-post token 301s to the canonical URL with the
  param dropped (via res.redirect so the no-store header survives);
  frontend-caching marks any ?gift request no-store so the edge never caches
  unlocked content, while the bare URL stays cacheable; everything gated on
  labs.giftLinks
kevinansfield added a commit that referenced this pull request Jun 23, 2026
ref https://linear.app/ghost/issue/BER-3728

- the public reader path for gift links: a paid post/page's own URL plus
  ?gift=TOKEN renders its full content to an anonymous visitor holding a
  valid token, reworked from the spike (#28629) to build on the existing
  routers rather than a dedicated /g/ route
- because collection/static-pages routing already resolves the URL, the
  resource type is known up-front: no dedicated router, no slug
  canonicalisation and no redirect-loop guard — the entry controller owns
  the whole flow
- the token is verified against the entry that lives at the request URL via
  the in-memory URL service, so a token for one post can never unlock
  another; getPostByToken returns just the post id
- access is granted the same way /p/ previews grant it — a synthesized
  all-active-paid-tiers member — passed to entryLookup as a read-context
  override only, so gating reveals member-only content while
  res.locals.member / @member stays the visitor's real member. The synthesis
  is extracted to members/synthesize-member.js and previews.js refactored
  onto it, so the security-sensitive grant has one source of truth
- an invalid/revoked/wrong-post token 301s to the canonical URL with the
  param dropped (via res.redirect so the no-store header survives);
  frontend-caching marks any ?gift request no-store so the edge never caches
  unlocked content, while the bare URL stays cacheable; everything gated on
  labs.giftLinks
kevinansfield added a commit that referenced this pull request Jun 23, 2026
ref https://linear.app/ghost/issue/BER-3728

- the public reader path for gift links: a paid post/page's own URL plus
  ?gift=TOKEN renders its full content to an anonymous visitor holding a
  valid token, reworked from the spike (#28629) to build on the existing
  routers rather than a dedicated /g/ route
- because collection/static-pages routing already resolves the URL, the
  resource type is known up-front: no dedicated router, no slug
  canonicalisation and no redirect-loop guard — the entry controller owns
  the whole flow
- the token is verified against the entry that lives at the request URL via
  the in-memory URL service, so a token for one post can never unlock
  another; getPostByToken returns just the post id
- access is granted the same way /p/ previews grant it — a synthesized
  all-active-paid-tiers member — passed to entryLookup as a read-context
  override only, so gating reveals member-only content while
  res.locals.member / @member stays the visitor's real member. The synthesis
  is extracted to members/synthesize-member.js and previews.js refactored
  onto it, so the security-sensitive grant has one source of truth
- an invalid/revoked/wrong-post token 301s to the canonical URL with the
  param dropped (via res.redirect so the no-store header survives);
  frontend-caching marks any ?gift request no-store so the edge never caches
  unlocked content, while the bare URL stays cacheable; everything gated on
  labs.giftLinks
kevinansfield added a commit that referenced this pull request Jun 23, 2026
ref https://linear.app/ghost/issue/BER-3728

- the public reader path for gift links: a paid post/page's own URL plus
  ?gift=TOKEN renders its full content to an anonymous visitor holding a
  valid token, reworked from the spike (#28629) to build on the existing
  routers rather than a dedicated /g/ route
- because collection/static-pages routing already resolves the URL, the
  resource type is known up-front: no dedicated router, no slug
  canonicalisation and no redirect-loop guard — the entry controller owns
  the whole flow
- the token is verified against the entry that lives at the request URL via
  the in-memory URL service, so a token for one post can never unlock
  another; getPostByToken returns just the post id
- access is granted the same way /p/ previews grant it — a synthesized
  all-active-paid-tiers member — passed to entryLookup as a read-context
  override only, so gating reveals member-only content while
  res.locals.member / @member stays the visitor's real member. The synthesis
  is extracted to members/synthesize-member.js and previews.js refactored
  onto it, so the security-sensitive grant has one source of truth
- an invalid/revoked/wrong-post token 301s to the canonical URL with the
  param dropped (via res.redirect so the no-store header survives);
  frontend-caching marks any ?gift request no-store so the edge never caches
  unlocked content, while the bare URL stays cacheable; everything gated on
  labs.giftLinks
kevinansfield added a commit that referenced this pull request Jun 23, 2026
ref https://linear.app/ghost/issue/BER-3728

- the public reader path for gift links: a paid post/page's own URL plus
  ?gift=TOKEN renders its full content to an anonymous visitor holding a
  valid token, reworked from the spike (#28629) to build on the existing
  routers rather than a dedicated /g/ route
- because collection/static-pages routing already resolves the URL, the
  resource type is known up-front: no dedicated router, no slug
  canonicalisation and no redirect-loop guard — the entry controller owns
  the whole flow
- gift handling is encapsulated in a services/routing/gift-access module:
  giftAccess.forRequest(req) resolves the token once into a per-request
  object the controller talks to in domain terms — member, isInvalidFor,
  redirectWithoutToken, cacheSafeRedirect, decorateResponse — keeping the
  grant, ?gift-stripping and cache-header choices out of the controller
- the token is verified against the entry that lives at the request URL via
  the in-memory URL service, so a token for one post can never unlock
  another; getPostByToken returns just the post id
- access is granted the same way /p/ previews grant it — a synthesized
  all-active-paid-tiers member — passed to entryLookup as a read-context
  override only, so gating reveals member-only content while
  res.locals.member / @member stays the visitor's real member. The synthesis
  is extracted to members/synthesize-member.js and previews.js refactored
  onto it, so the security-sensitive grant has one source of truth
- an invalid/revoked/wrong-post token 301s to the canonical URL with the
  param dropped via a cache-safe redirect (res.redirect, never redirect301)
  so the no-store header survives and the token-bearing redirect is never
  edge-cached; frontend-caching marks any ?gift request no-store so the edge
  never caches unlocked content, while the bare URL stays cacheable;
  everything gated on labs.giftLinks
kevinansfield added a commit that referenced this pull request Jun 23, 2026
ref https://linear.app/ghost/issue/BER-3728

- the public reader path for gift links: a paid post/page's own URL plus
  ?gift=TOKEN renders its full content to an anonymous visitor holding a
  valid token, reworked from the spike (#28629) to build on the existing
  routers rather than a dedicated /g/ route
- because collection/static-pages routing already resolves the URL, the
  resource type is known up-front: no dedicated router, no slug
  canonicalisation and no redirect-loop guard — the entry controller owns
  the whole flow
- gift handling is encapsulated in a services/routing/gift-access module:
  giftAccess.forRequest(req) resolves the token once into a per-request
  object the controller talks to in domain terms — member, isInvalidFor,
  redirectWithoutToken, cacheSafeRedirect, decorateResponse — keeping the
  grant, ?gift-stripping and cache-header choices out of the controller
- the token is verified against the entry that lives at the request URL via
  the in-memory URL service, so a token for one post can never unlock
  another; getPostByToken returns just the post id
- access is granted the same way /p/ previews grant it — a synthesized
  all-active-paid-tiers member — passed to entryLookup as a read-context
  override only, so gating reveals member-only content while
  res.locals.member / @member stays the visitor's real member. The synthesis
  is extracted to members/synthesize-member.js and previews.js refactored
  onto it, so the security-sensitive grant has one source of truth
- an invalid/revoked/wrong-post token 301s to the canonical URL with the
  param dropped via a cache-safe redirect (res.redirect, never redirect301)
  so the no-store header survives and the token-bearing redirect is never
  edge-cached; frontend-caching marks any ?gift request no-store so the edge
  never caches unlocked content, while the bare URL stays cacheable;
  everything gated on labs.giftLinks
kevinansfield added a commit that referenced this pull request Jun 24, 2026
ref https://linear.app/ghost/issue/BER-3728

- the public reader path for gift links: a paid post/page's own URL plus
  ?gift=TOKEN renders its full content to an anonymous visitor holding a
  valid token, reworked from the spike (#28629) to build on the existing
  routers rather than a dedicated /g/ route
- because collection/static-pages routing already resolves the URL, the
  resource type is known up-front: no dedicated router, no slug
  canonicalisation and no redirect-loop guard — the entry controller owns
  the whole flow
- the controller resolves the entry as normal, then a single ?gift branch at
  the end validates the token against that resolved entry: the gift-links
  service's isValidTokenForPost(token, entry.id) confirms a live token bound
  to this post, so a token for one post can never unlock another
- access is granted the same way /p/ previews grant it — a synthesized
  all-active-paid-tiers member — layered over res.locals as the entry
  lookup's read context only, so gating reveals member-only content while
  res.locals.member / @member stays the visitor's real member. The synthesis
  is extracted to members/synthesize-member.js and previews.js refactored
  onto it, so the security-sensitive grant has one source of truth
- an invalid/revoked/wrong-post token 301s to the canonical URL with the
  param dropped via res.redirect (never redirect301) so the no-store header
  survives and the token-bearing redirect is never edge-cached;
  frontend-caching marks any ?gift request no-store so the edge never caches
  unlocked content, while the bare URL stays cacheable; everything gated on
  labs.giftLinks
kevinansfield added a commit that referenced this pull request Jun 24, 2026
ref https://linear.app/ghost/issue/BER-3728

- the public reader path for gift links: a paid post/page's own URL plus
  ?gift=TOKEN renders its full content to an anonymous visitor holding a
  valid token, reworked from the spike (#28629) to build on the existing
  routers rather than a dedicated /g/ route
- because collection/static-pages routing already resolves the URL, the
  resource type is known up-front: no dedicated router, no slug
  canonicalisation and no redirect-loop guard — the entry controller owns
  the whole flow
- the controller resolves the entry as normal, then a single ?gift branch at
  the end validates the token against that resolved entry: the gift-links
  service's isValidTokenForPost(token, entry.id) confirms a live token bound
  to this post, so a token for one post can never unlock another
- access is granted the same way /p/ previews grant it — a synthesized
  all-active-paid-tiers member — layered over res.locals as the entry
  lookup's read context only, so gating reveals member-only content while
  res.locals.member / @member stays the visitor's real member. The synthesis
  is extracted to members/synthesize-member.js and previews.js refactored
  onto it, so the security-sensitive grant has one source of truth
- an invalid/revoked/wrong-post token 301s to the canonical URL with the
  param dropped via res.redirect (never redirect301) so the no-store header
  survives and the token-bearing redirect is never edge-cached;
  frontend-caching marks any ?gift request no-store so the edge never caches
  unlocked content, while the bare URL stays cacheable; everything gated on
  labs.giftLinks
kevinansfield added a commit that referenced this pull request Jun 24, 2026
ref https://linear.app/ghost/issue/BER-3728

- the public reader path for gift links: a paid post/page's own URL plus
  ?gift=TOKEN renders its full content to an anonymous visitor holding a
  valid token, reworked from the spike (#28629) to build on the existing
  routers rather than a dedicated /g/ route
- because collection/static-pages routing already resolves the URL, the
  resource type is known up-front: no dedicated router, no slug
  canonicalisation and no redirect-loop guard — the entry controller owns
  the whole flow
- the controller resolves the entry as normal, then a single ?gift branch at
  the end validates the token against that resolved entry: the gift-links
  service's isValidTokenForPost(token, entry.id) confirms a live token bound
  to this post, so a token for one post can never unlock another
- access is granted the same way /p/ previews grant it — a synthesized
  all-active-paid-tiers member — layered over res.locals as the entry
  lookup's read context only, so gating reveals member-only content while
  res.locals.member / @member stays the visitor's real member. The synthesis
  is extracted to members/synthesize-member.js and previews.js refactored
  onto it, so the security-sensitive grant has one source of truth
- an invalid/revoked/wrong-post token 301s to the canonical URL with the
  param dropped via res.redirect (never redirect301) so the no-store header
  survives and the token-bearing redirect is never edge-cached;
  frontend-caching marks any ?gift request no-store so the edge never caches
  unlocked content, while the bare URL stays cacheable; everything gated on
  labs.giftLinks
kevinansfield added a commit that referenced this pull request Jun 24, 2026
ref https://linear.app/ghost/issue/BER-3728

- the public reader path for gift links: a paid post/page's own URL plus
  ?gift=TOKEN renders its full content to an anonymous visitor holding a
  valid token, reworked from the spike (#28629) to build on the existing
  routers rather than a dedicated /g/ route
- because collection/static-pages routing already resolves the URL, the
  resource type is known up-front: no dedicated router, no slug
  canonicalisation and no redirect-loop guard — the entry controller owns
  the whole flow
- the controller resolves the entry as normal, then a single ?gift branch at
  the end validates the token against that resolved entry: the gift-links
  service's isValidTokenForPost(token, entry.id) confirms a live token bound
  to this post, so a token for one post can never unlock another
- access is granted the same way /p/ previews grant it — a synthesized
  all-active-paid-tiers member — layered over res.locals as the entry
  lookup's read context only, so gating reveals member-only content while
  res.locals.member / @member stays the visitor's real member. The synthesis
  is extracted to members/synthesize-member.js and previews.js refactored
  onto it, so the security-sensitive grant has one source of truth
- an invalid/revoked/wrong-post token 301s to the canonical URL with the
  param dropped via res.redirect (never redirect301) so the no-store header
  survives and the token-bearing redirect is never edge-cached;
  frontend-caching marks any ?gift request no-store so the edge never caches
  unlocked content, while the bare URL stays cacheable; everything gated on
  labs.giftLinks
kevinansfield added a commit that referenced this pull request Jun 24, 2026
ref https://linear.app/ghost/issue/BER-3728

- the public reader path for gift links: a paid post/page's own URL plus
  ?gift=TOKEN renders its full content to an anonymous visitor holding a
  valid token, reworked from the spike (#28629) to build on the existing
  routers rather than a dedicated /g/ route
- because collection/static-pages routing already resolves the URL, the
  resource type is known up-front: no dedicated router, no slug
  canonicalisation and no redirect-loop guard — the entry controller owns
  the whole flow
- the controller resolves the entry as normal, then a single ?gift branch at
  the end validates the token against that resolved entry: the gift-links
  service's isValidTokenForPost(token, entry.id) confirms a live token bound
  to this post, so a token for one post can never unlock another
- access is granted the same way /p/ previews grant it — a synthesized
  all-active-paid-tiers member — layered over res.locals as the entry
  lookup's read context only, so gating reveals member-only content while
  res.locals.member / @member stays the visitor's real member. The synthesis
  is extracted to members/synthesize-member.js and previews.js refactored
  onto it, so the security-sensitive grant has one source of truth
- an invalid/revoked/wrong-post token 301s to the canonical URL with the
  param dropped via res.redirect (never redirect301) so the no-store header
  survives and the token-bearing redirect is never edge-cached;
  frontend-caching marks any ?gift request no-store so the edge never caches
  unlocked content, while the bare URL stays cacheable; everything gated on
  labs.giftLinks
kevinansfield added a commit that referenced this pull request Jun 24, 2026
ref https://linear.app/ghost/issue/BER-3728

- the public reader path for gift links: a paid post/page's own URL plus
  ?gift=TOKEN renders its full content to an anonymous visitor holding a
  valid token, reworked from the spike (#28629) to build on the existing
  routers rather than a dedicated /g/ route
- because collection/static-pages routing already resolves the URL, the
  resource type is known up-front: no dedicated router, no slug
  canonicalisation and no redirect-loop guard — the entry controller owns
  the whole flow
- the controller resolves the entry as normal, then a single ?gift branch at
  the end validates the token against that resolved entry: the gift-links
  service's isValidTokenForPost(token, entry.id) confirms a live token bound
  to this post, so a token for one post can never unlock another
- access is granted the same way /p/ previews grant it — a synthesized
  all-active-paid-tiers member — layered over res.locals as the entry
  lookup's read context only, so gating reveals member-only content while
  res.locals.member / @member stays the visitor's real member. The synthesis
  is extracted to members/synthesize-member.js and previews.js refactored
  onto it, so the security-sensitive grant has one source of truth
- an invalid/revoked/wrong-post token 301s to the canonical URL with the
  param dropped via res.redirect (never redirect301) so the no-store header
  survives and the token-bearing redirect is never edge-cached;
  frontend-caching marks any ?gift request no-store so the edge never caches
  unlocked content, while the bare URL stays cacheable; everything gated on
  labs.giftLinks
kevinansfield added a commit that referenced this pull request Jun 24, 2026
ref https://linear.app/ghost/issue/BER-3728

- the public reader path for gift links: a paid post/page's own URL plus
  ?gift=TOKEN renders its full content to an anonymous visitor holding a
  valid token, reworked from the spike (#28629) to build on the existing
  routers rather than a dedicated /g/ route
- because collection/static-pages routing already resolves the URL, the
  resource type is known up-front: no dedicated router, no slug
  canonicalisation and no redirect-loop guard — the entry controller owns
  the whole flow
- the controller resolves the entry as normal, then a single ?gift branch at
  the end validates the token against that resolved entry: the gift-links
  service's isValidTokenForPost(token, entry.id) confirms a live token bound
  to this post, so a token for one post can never unlock another
- access is granted the same way /p/ previews grant it — a synthesized
  all-active-paid-tiers member — layered over res.locals as the entry
  lookup's read context only, so gating reveals member-only content while
  res.locals.member / @member stays the visitor's real member. The synthesis
  is extracted to members/synthesize-member.js and previews.js refactored
  onto it, so the security-sensitive grant has one source of truth
- an invalid/revoked/wrong-post token 301s to the canonical URL with the
  param dropped via res.redirect (never redirect301) so the no-store header
  survives and the token-bearing redirect is never edge-cached;
  frontend-caching marks any ?gift request no-store so the edge never caches
  unlocked content, while the bare URL stays cacheable; everything gated on
  labs.giftLinks
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.

2 participants