Skip to content

fix(realtime): guard sessionStorage access in restricted-storage browsers - #2333

Merged
mandarini merged 1 commit into
developfrom
fix/realtime-session-storage-restricted-contexts
May 8, 2026
Merged

mandarini merged 1 commit into
developfrom
fix/realtime-session-storage-restricted-contexts

Conversation

@mandarini

@mandarini mandarini commented May 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #2331.

createClient / createBrowserClient crashed synchronously with SecurityError: Failed to read the 'sessionStorage' property from 'Window' in restricted-storage browsers — sandboxed iframes without allow-same-origin, in-app webviews (Facebook Messenger, Instagram, Google Performance Max), and "block third-party storage" privacy modes. The bundled phoenix Socket constructor reads global.sessionStorage via a bare property access; the getter itself throws in those contexts before the || short-circuit can save us, taking the whole SupabaseClient instantiation down with it.

This change always forwards a truthy Storage to phoenix from _initializeOptions, so the bare read is short-circuited and never reached. The probe tries globalThis.sessionStorage first and falls back to an in-memory shim when the access throws or returns nullish (Worker / Node).

Also adds sessionStorage?: Storage to RealtimeClientOptions, mirroring the existing auth.storage injection pattern, so consumers can inject their own.

@github-actions github-actions Bot added the realtime-js Related to the realtime-js library. label May 7, 2026
@pkg-pr-new

pkg-pr-new Bot commented May 7, 2026

Copy link
Copy Markdown

Open in StackBlitz

@supabase/auth-js

npm i https://pkg.pr.new/@supabase/auth-js@2333

@supabase/functions-js

npm i https://pkg.pr.new/@supabase/functions-js@2333

@supabase/postgrest-js

npm i https://pkg.pr.new/@supabase/postgrest-js@2333

@supabase/realtime-js

npm i https://pkg.pr.new/@supabase/realtime-js@2333

@supabase/storage-js

npm i https://pkg.pr.new/@supabase/storage-js@2333

@supabase/supabase-js

npm i https://pkg.pr.new/@supabase/supabase-js@2333

commit: 7600a94

@mandarini mandarini self-assigned this May 7, 2026
@mandarini
mandarini marked this pull request as ready for review May 8, 2026 10:08
@mandarini
mandarini requested review from a team as code owners May 8, 2026 10:08
@mandarini
mandarini merged commit 1eaaca8 into develop May 8, 2026
25 of 26 checks passed
@mandarini
mandarini deleted the fix/realtime-session-storage-restricted-contexts branch May 8, 2026 11:57
@goxr3plus

Copy link
Copy Markdown

Thanks a lot for the very fast fix of this issue @mandarini

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

realtime-js Related to the realtime-js library.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

createBrowserClient throws SecurityError in restricted-storage browsers (Phoenix Socket bare sessionStorage read)

3 participants