Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

feat: disable cookie/localstorage access under restricted sandboxes #729

Merged
merged 1 commit into from
Jan 15, 2020

Conversation

josegonzalez
Copy link
Contributor

When dash is embedded into an iframe with a sandbox attribute that only has allow-scripts, cookie/localstorage access is disabled and dash-core-components fails to load. As such, we need to restrict our cookie/localstorage usage by disabling functionality.

This patch removes the disabled functionality in a graceful manner, allowing dash-core-components to load in very restricted iframes.

@josegonzalez josegonzalez force-pushed the iframe-sandbox-support branch 3 times, most recently from 7f267de to d38659d Compare January 13, 2020 17:46
@@ -126,9 +123,9 @@ export default class Store extends React.Component {
super(props);

if (props.storage_type === 'local') {
this._backstore = _localStore;
this._backstore = new WebStore(window.localStorage);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message we get when trying to access localStorage is fairly informative / helpful:

Uncaught DOMException: Failed to read the 'localStorage' property from 'Window': The document is sandboxed and lacks the 'allow-same-origin' flag.

I don't think it needs to be improved to make sense to an app developer and as such can be exposed as-is.

@Marc-Andre-Rivet
Copy link
Contributor

Created plotly/dash#1088 for follow up.

Copy link
Contributor

@Marc-Andre-Rivet Marc-Andre-Rivet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@josegonzalez Looks good. Just need two more things:

  • a changelog entry under ## Unreleased --> ### Changed
  • a branch update

@josegonzalez josegonzalez force-pushed the iframe-sandbox-support branch 2 times, most recently from 23372eb to 39087e2 Compare January 15, 2020 20:11
When dash is embedded into an iframe with a sandbox attribute that only has allow-scripts, cookie/localstorage access is disabled and dash-core-components fails to load. As such, we need to restrict our cookie/localstorage usage by disabling functionality.

This patch moves the disabled functionality to a place where it doesn't get autoloaded regardless of usage, allowing dash-core-components to load in very restricted iframes.
Copy link
Contributor

@Marc-Andre-Rivet Marc-Andre-Rivet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💃

@Marc-Andre-Rivet Marc-Andre-Rivet merged commit 9bea97b into dev Jan 15, 2020
@Marc-Andre-Rivet Marc-Andre-Rivet deleted the iframe-sandbox-support branch January 15, 2020 21:04
@Marc-Andre-Rivet Marc-Andre-Rivet added this to the Dash v1.9 milestone Jan 15, 2020
JHSaunders pushed a commit to JHSaunders/dash-core-components that referenced this pull request Mar 30, 2020
…lotly#729)

When dash is embedded into an iframe with a sandbox attribute that only has allow-scripts, cookie/localstorage access is disabled and dash-core-components fails to load. As such, we need to restrict our cookie/localstorage usage by disabling functionality.

This patch moves the disabled functionality to a place where it doesn't get autoloaded regardless of usage, allowing dash-core-components to load in very restricted iframes.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants