Skip to content

SessionStorage exception when blocking cookies #34512

Closed
@herecydev

Description

@herecydev

Preliminary Checks

Description

Through chrome (probably other browsers as well), users can disable cookies which will cause sessionStorage/localStorage to also throw an exception when accessed. Currently in Gatsby there are places where this is left unchecked, the offending code is here: https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby/cache-dir/production-app.js#L187-L200

This is actually catered for in the react-router-scroll package, which checks for an exception: https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-react-router-scroll/src/session-storage.ts#L9

Potentially this could be extracted and reused as an all purpose function.

Reproduction Link

https://github.com/gatsbyjs/gatsby

Steps to Reproduce

  1. gatsby build
  2. gatsby serve
  3. In chrome, security & privacy => disable cookies

Expected Result

No exceptions are raised, using sessionStorage should be an enhancement not a given.

Actual Result

Security Exception is raised

Environment

System:
    OS: Windows 10 10.0.19042
    CPU: (16) x64 AMD Ryzen 9 5950X 16-Core Processor            
  Binaries:
    Node: 16.13.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 3.1.0 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 8.1.2 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.19041.1266.0), Chromium (97.0.1072.62)
  npmPackages:
    gatsby: ^4.5.2 => 4.5.2 
    gatsby-cypress: ^2.5.0 => 2.5.0 
    gatsby-plugin-google-tagmanager: ^4.5.0 => 4.5.0 
    gatsby-plugin-image: ^2.5.1 => 2.5.1 
    gatsby-plugin-newrelic: ^2.1.1 => 2.1.1 
    gatsby-plugin-react-helmet: ^5.5.0 => 5.5.0 
    gatsby-plugin-remove-generator: ^1.2.0 => 1.2.0 
    gatsby-plugin-sharp: ^4.5.1 => 4.5.1 
    gatsby-plugin-sitemap: ^5.5.0 => 5.5.0 
    gatsby-plugin-styled-components: ^5.5.0 => 5.5.0 
    gatsby-plugin-webpack-bundle-analyser-v2: ^1.1.26 => 1.1.26 
    gatsby-source-filesystem: ^4.5.1 => 4.5.1 
    gatsby-transformer-remark: ^5.5.1 => 5.5.1 
    gatsby-transformer-sharp: ^4.5.0 => 4.5.0 
  npmGlobalPackages:
    gatsby-cli: 4.5.2

Config Flags

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueIssue that doesn't require previous experience with Gatsbyhelp wantedIssue with a clear description that the community can help with.topic: coreRelates to Gatsby's core (e.g. page loading, reporter, state machine)type: bugAn issue or pull request relating to a bug in Gatsby

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions