Send no-cache headers on the record preview response#187
Merged
Conversation
The ?atproto preview is served on a public front-end URL but carries per-object, edit_post-gated data (a post's custom Bluesky text and any third-party preview-transformer output). Preview::send() sent no cache-control headers, so a URL-keyed edge/page cache that stores a logged-in response could replay an authorized projection to a later unauthorized visitor. Call nocache_headers() on every branch, mirroring the well-known handlers.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens the public ?atproto record preview endpoint against misconfigured URL-keyed caches by ensuring preview responses are always emitted with no-cache headers, aligning it with the plugin’s existing well-known handlers.
Changes:
- Add
\nocache_headers()to the unsupported post type404exit path inPreview::render(). - Add
\nocache_headers()at the start ofPreview::send()so both200payloads and400error payloads are consistently non-cacheable. - Add a patch-level changelog entry documenting the behavior change.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| includes/transformer/class-preview.php | Sends no-cache headers for all preview response branches (200/400 and unsupported-type 404). |
| .github/changelog/fix-preview-cache-headers | Documents the preview no-cache header change as a patch fix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed changes:
The
?atprotorecord preview is served on a public front-end URL but carries per-object,edit_post-gated data — a post's saved custom Bluesky text and any third-party preview-transformer output.Preview::send()sent no cache-control headers, so a URL-keyed edge/page cache that stores a logged-in response could replay an authorized projection to a later unauthorized visitor.This calls
\nocache_headers()on every branch that emits a preview response — the 200 record payload, the 400 error, and the unsupported-post-type 404 — mirroring the well-known handlers (serve_wellknown_atproto_did/serve_wellknown_publication), which already no-cache every branch. It does not hoist the call to the top ofrender(), becauserender()'s many fall-throughreturnbranches must leave the normal (cacheable) page render untouched.Context: surfaced by a full-codebase security audit as the one open item; classified as defense-in-depth hardening (not an exploitable vulnerability) — the leak only bites under a misconfigured cache that stores logged-in responses and keys purely on URL, a config under which far more sensitive authenticated content would already leak site-wide. Fixing it brings the preview in line with the plugin's two other public GET surfaces.
Other information:
exit-ing path can't be exercised under PHPUnit (the CLI harness has already sent headers), the same reason the sibling well-known handlers carry no header assertions. Verified instead against a live wp-env response (see below).Testing instructions:
composer lintandnpm run env-testpass (854 tests).atmosphere_identity), then as a logged-in editor request a post preview and inspect headers:page) returns404with the sameCache-Controlheader.Changelog entry
A patch/fixed entry is included at
.github/changelog/fix-preview-cache-headers.