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

Commit d38659d

Browse files
committed
feat: disable cookie/localstorage access under restricted sandboxes
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.
1 parent 39cfdfc commit d38659d

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/components/Store.react.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,16 @@ class WebStore {
112112
}
113113
}
114114

115-
const _localStore = new WebStore(window.localStorage);
116-
const _sessionStore = new WebStore(window.sessionStorage);
115+
function localStorageTest() {
116+
const test = 'test';
117+
try {
118+
localStorage.setItem(test, test);
119+
localStorage.removeItem(test);
120+
return true;
121+
} catch (e) {
122+
return false;
123+
}
124+
}
117125

118126
/**
119127
* Easily keep data on the client side with this component.
@@ -125,11 +133,11 @@ export default class Store extends React.Component {
125133
constructor(props) {
126134
super(props);
127135

128-
if (props.storage_type === 'local') {
129-
this._backstore = _localStore;
136+
if (props.storage_type === 'local' && localStorageTest()) {
137+
this._backstore = new WebStore(window.localStorage);
130138
} else if (props.storage_type === 'session') {
131-
this._backstore = _sessionStore;
132-
} else if (props.storage_type === 'memory') {
139+
this._backstore = new WebStore(window.sessionStorage);
140+
} else {
133141
this._backstore = new MemStore();
134142
}
135143

0 commit comments

Comments
 (0)