Repository navigation
Gift links: reader access path (/g/, gating, counting) - #28629
jonatansberg wants to merge 2 commits into
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
| 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
bca071c to
27420ed
Compare
175b158 to
b8929b0
Compare
27420ed to
d85e91e
Compare
b8929b0 to
8cd81c6
Compare
d85e91e to
05de009
Compare
8cd81c6 to
8689fcd
Compare
05de009 to
61115dc
Compare
53fd483 to
124210d
Compare
61115dc to
1b0362f
Compare
b6a6081 to
82f5eb2
Compare
Codecov Report❌ Patch coverage is 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
1b0362f to
3332e19
Compare
82f5eb2 to
e6b653b
Compare
e6b653b to
a9646c3
Compare
3332e19 to
90ac687
Compare
a9646c3 to
f36455f
Compare
d8397b5 to
5c2cc52
Compare
5c2cc52 to
4d8c687
Compare
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)
f36455f to
59e6a67
Compare
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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

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=TOKENrouter + controller — a dedicated top-level prefix (like/p/previews), outside the theme's collection space, with a path-based cache boundary.?key=into a content-only access grant onres.locals.giftLinkbefore routing dispatches; setsX-Robots-Tag: noindex+Referrer-Policy: no-referreron gift requests./g/responses are never cached (they contain unlocked gated content); the controller's invalid-token 301s carry their ownCache-Control: no-store.redeemed_count.@gifttemplate 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
/g/(or equal to the current path), falling through to 404 instead of looping when a site permalinks a collection under/g/.readPostOrPageonly swallows genuineNotFoundError; 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.bot,monitor,preview,scanner,spider) are word-boundary anchored so real devices (e.g. Cubot'sCUBOT_X30) are no longer misclassified as bots; all real crawler UAs still match. New test case asserts the Cubot UA is not a bot.secureis now passed at thenew 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 skippedrecordRead.gift_seencookie now carries a 1-yearmaxAgeso the once-per-client-per-post dedup survives browser restarts (it was session-only, inflatingredeemed_count)./g/prefix constant (GIFT_LINK_PREFIX) shared by the router and frontend-caching.Documented follow-ups (out of this slice's scope)
urlServiceinstead of a second API read.ghost-statssendslocation.hrefincluding?key=; tracked in the BER-3728 ticket.Tests
@giftmarker + no-leak-on-404) green.