Skip to content

fix: guard sessionStorage read in Socket constructor#35

Merged
mandarini merged 1 commit into
mainfrom
fix/socket-session-storage-getter-throw
May 8, 2026
Merged

fix: guard sessionStorage read in Socket constructor#35
mandarini merged 1 commit into
mainfrom
fix/socket-session-storage-getter-throw

Conversation

@mandarini
Copy link
Copy Markdown
Collaborator

@mandarini mandarini commented May 7, 2026

Summary

Defense-in-depth fix for the bug reported in supabase/supabase-js#2331.

socket.js:62 reads global.sessionStorage via a bare property access. In sandboxed iframes without allow-same-origin, certain in-app webviews (Facebook Messenger, Instagram, Google Performance Max), and "block third-party storage" privacy modes, the property getter itself throws SecurityError before || short-circuit evaluation completes — taking down the entire Socket constructor synchronously.

This wraps the read in try/catch so the constructor cannot throw. Behavior is unchanged in every path that previously worked: null is the fallback, and downstream call sites already guard this.sessionStore && this.sessionStore.getItem(...) (socket.js:394, 396).

Test plan

  • Existing phoenix tests continue to pass.
  • Manual: in DevTools, override window.sessionStorage getter to throw, then construct new Socket(...) — expect no throw.

Note: source-only change. Bundled assets under priv/static/ need a separate rebuild commit (per recurring fix: rebuild assets pattern, e.g. 8b8c7b2).

@mandarini mandarini force-pushed the fix/socket-session-storage-getter-throw branch from ffe7a26 to 8b63fa6 Compare May 8, 2026 11:38
@mandarini mandarini marked this pull request as ready for review May 8, 2026 11:39
@mandarini mandarini self-assigned this May 8, 2026
@mandarini mandarini merged commit 298070d into main May 8, 2026
13 checks passed
@mandarini mandarini deleted the fix/socket-session-storage-getter-throw branch May 8, 2026 11:57
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