Skip to content

Guard localStorage access against SecurityError in restricted browsers#8615

Merged
iHiD merged 2 commits into
mainfrom
fix/8595
Feb 12, 2026
Merged

Guard localStorage access against SecurityError in restricted browsers#8615
iHiD merged 2 commits into
mainfrom
fix/8595

Conversation

@iHiD
Copy link
Copy Markdown
Member

@iHiD iHiD commented Feb 12, 2026

Closes #8595

Summary

  • Added a safeLocalStorage() helper that wraps window.localStorage in a try/catch and returns null when access is denied (Safari private browsing, restricted iframes, strict cookie settings)
  • Protected the React Query persister setup in application.tsx — the library already accepts null and returns a no-op persister, so the app gracefully skips cache persistence
  • Protected the sign-out localStorage cleanup in application.tsx — if storage is inaccessible, there's nothing to clear
  • Wrapped direct localStorage.getItem() calls in NewListItemForm.tsx and StartDiscussionPanel.tsx with try/catch, falling back to empty string
  • Added a Sentry beforeSend filter to suppress the non-actionable SecurityError for localStorage/sessionStorage access, following the existing pattern for other browser-specific errors

Test plan

  • yarn test passes (1550 tests passed)
  • Pre-commit hooks pass (prettier auto-formatted)
  • Verified createSyncStoragePersister gracefully handles null storage (returns no-op persister)
  • Sentry filter pattern matches the exact error message from the issue

🤖 Generated with Claude Code

Browsers with strict privacy settings (Safari private browsing, restricted
iframes, cookie-blocked contexts) throw a SecurityError when accessing
window.localStorage. This adds a safeLocalStorage() helper that returns
null when access is denied, wraps the four unprotected call sites, and
adds a Sentry beforeSend filter to suppress the non-actionable error.

Closes #8595

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@iHiD iHiD requested a review from dem4ron as a code owner February 12, 2026 17:18
@iHiD iHiD merged commit 2b4608e into main Feb 12, 2026
40 checks passed
@iHiD iHiD deleted the fix/8595 branch February 12, 2026 18:13
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.

SecurityError: Failed to read the 'localStorage' property from 'Window': Access is denied for this document.

1 participant