Skip to content

Commit

Permalink
feat: disable cookie access under restricted sandboxes
Browse files Browse the repository at this point in the history
When dash is embedded into an iframe with a sandbox attribute that only has allow-scripts, cookie access is disabled and dash fails to load. As such, we need to restrict our cookie usage by disabling functionality.

This patch removes the disabled functionality in a graceful manner, allowing dash to load in very restricted iframes.
  • Loading branch information
josegonzalez committed Jan 13, 2020
1 parent 735480b commit 260792c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
9 changes: 6 additions & 3 deletions dash-renderer/src/AccessDenied.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ function AccessDenied(props) {
<a
style={styles.base.a}
onClick={() => {
document.cookie =
`${constants.OAUTH_COOKIE_NAME}=; ` +
'expires=Thu, 01 Jan 1970 00:00:01 GMT;';
/* eslint no-empty: ["error", { "allowEmptyCatch": true }] */
try {
document.cookie =
`${constants.OAUTH_COOKIE_NAME}=; ` +
'expires=Thu, 01 Jan 1970 00:00:01 GMT;';
} catch (e) {}
window.location.reload(true);
}}
>
Expand Down
10 changes: 7 additions & 3 deletions dash-renderer/src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,13 @@ export function hydrateInitialOutputs() {
}

export function getCSRFHeader() {
return {
'X-CSRFToken': cookie.parse(document.cookie)._csrf_token,
};
try {
return {
'X-CSRFToken': cookie.parse(document.cookie)._csrf_token,
};
} catch (e) {
return {};
}
}

function triggerDefaultState(dispatch, getState) {
Expand Down

0 comments on commit 260792c

Please sign in to comment.