Skip to content

Restore theme storage and feed access in previews - #55

Merged
ruibaby merged 5 commits into
mainfrom
fix/preview-storage-access
Oct 26, 2026
Merged

ruibaby merged 5 commits into
mainfrom
fix/preview-storage-access

Conversation

@ruibaby

@ruibaby ruibaby commented Oct 23, 2026

Copy link
Copy Markdown
Member

Problem

Preview documents run in an opaque origin (sandbox allow-scripts, no
allow-same-origin). Theme scripts that read localStorage, sessionStorage, or
document.cookie during startup throw SecurityError, which aborts theme hydration
(for example Astro islands in Ethereal) and breaks display settings, language
switching, and search widgets. Theme widgets that fetch /rss.xml also fail because
the preview connect-src allows only public APIs and the CORS filter covers only
theme and plugin assets.

Change

  • Inject a small shim before any theme script in every HTML preview document: the
    Console page/revision preview routes and the sandboxed child used by token previews.
  • The shim replaces only the blocked APIs with in-memory implementations:
    Storage-compatible localStorage/sessionStorage (including property access,
    length, key, and enumeration) and a per-document cookie jar. It does not expose
    real site storage or cookies.
  • Leave the sandbox unchanged: no allow-same-origin, so preview scripts still cannot
    reach site storage, cookies, or the Console parent.
  • Allow /rss.xml, /feed.xml, /sitemap.xml, and /feed/ in the preview
    connect-src and in the CORS filter so theme feed widgets work.
  • Add tests for injection ordering, non-HTML and non-preview pass-through, CSP
    sources, and CORS coverage.

Validation

  • bash gradlew test -x processUiResources passes.
  • Verified the shim in headless Chrome under both an iframe sandbox="allow-scripts"
    and a real Content-Security-Policy: sandbox allow-scripts response:
    localStorage reads/writes, Object.keys, length, and document.cookie work.

Limitations

  • Shimmed values live only for the current preview document. Refreshing resets them,
    and the administrator's real site preferences are not exposed to preview scripts.
  • The POST candidate preview route is intentionally untouched; it renders into a
    script-free visual editing canvas.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-10-26T08:42:19.395411Z a090833 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c68f872364

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ruibaby

ruibaby commented Oct 23, 2026

Copy link
Copy Markdown
Member Author

@codex review

@ruibaby

ruibaby commented Oct 24, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 0be8bb9149

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ruibaby
ruibaby merged commit 57a3f1e into main Oct 26, 2026
1 check passed
@ruibaby
ruibaby deleted the fix/preview-storage-access branch October 26, 2026 08:44
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.

1 participant