Skip to content

Fix CSP initialization in sandboxed iframes - #4893

Merged
calebporzio merged 1 commit into
mainfrom
codex/fix-csp-sandboxed-iframe
Sep 4, 2026
Merged

Fix CSP initialization in sandboxed iframes#4893
calebporzio merged 1 commit into
mainfrom
codex/fix-csp-sandboxed-iframe

Conversation

@calebporzio

Copy link
Copy Markdown
Collaborator

What this fixes

Closes #4892.

The CSP build snapshots values from globalThis when the module loads so the evaluator can reject global objects later. Some browser globals are accessors that can throw when unavailable; in a sandboxed iframe without allow-same-origin, reading localStorage throws a SecurityError and aborts Alpine before initialization.

Changes

  • Skip global properties whose getters throw while building the CSP global-value set.
  • Add a browser regression fixture that runs the CSP build in an opaque-origin iframe and verifies x-data/x-text initialize.

Verification

  • Confirmed the new Cypress regression fails on unpatched main.
  • npm run build
  • npx cypress run --browser chrome --spec tests/cypress/integration/plugins/csp-compatibility.spec.js
  • npx vitest run tests/vitest/csp-parser.spec.js

@calebporzio
calebporzio merged commit e610f47 into main Sep 4, 2026
2 checks passed
@calebporzio
calebporzio deleted the codex/fix-csp-sandboxed-iframe branch September 4, 2026 12:37
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.

@alpinejs/csp throws SecurityError when running in a sandboxed iframe without allow-same-origin

1 participant