Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: disable cookie access under restricted sandboxes #1080

Merged
merged 9 commits into from
Jan 29, 2020

Conversation

josegonzalez
Copy link
Contributor

@josegonzalez josegonzalez commented Jan 11, 2020

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.

Contributor Checklist

  • I have broken down my PR scope into the following TODO tasks not needed
  • I have run the tests locally and they passed. (refer to testing section in contributing)
  • I have added tests, or extended existing tests, to cover any new features or bugs fixed in this PR

optionals

  • I have added entry in the CHANGELOG.md

@josegonzalez
Copy link
Contributor Author

Not sure how to fix the Empty block statement error...

@alexcjohnson
Copy link
Collaborator

Not sure how to fix the Empty block statement error...

May be worth console.log-ing the error anyway, could be useful to sandbox users for debugging. That would fill the block :)

@josegonzalez
Copy link
Contributor Author

heh:

Unexpected console statement  no-console

@josegonzalez
Copy link
Contributor Author

@alexcjohnson I've ignored the prettier issue in code for now since there isn't a great way to handle it otherwise.

Do you have any thoughts on how I should write a test for the code? The change itself was manually tested and confirmed working within a large-ish dash app, so I'm fairly confident it works, but I'm not sure how to write tests for the change...

@alexcjohnson
Copy link
Collaborator

how I should write a test for the code?

The most robust thing I can think of is to make a container html file (in an assets/ folder next to the test file so dash will serve it) with the actual dash app in a sandboxed iframe - then go interact with the app in the iframe - I've never done that but it looks manageable http://allselenium.info/handling-iframes-using-selenium-webdriver/

@josegonzalez josegonzalez force-pushed the iframe-sandbox-support branch 4 times, most recently from 5dbb6af to 6d9660c Compare January 16, 2020 19:45
@josegonzalez
Copy link
Contributor Author

@alexcjohnson once tests pass (I rebased everything together, they previously passed) this should be good for a re-review/merge :)

document.cookie =
`${constants.OAUTH_COOKIE_NAME}=; ` +
'expires=Thu, 01 Jan 1970 00:00:01 GMT;';
} catch (e) {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Between an eslint exception allowing error swallowing and an eslint exception for a console.warn entry, I'd rather have the warning. Dash will be operating with limited capabilities and the information should be exposed. Maybe later we can approve it with #1088


dash_duo.driver.get("data:text/html;charset=utf-8," + html_content)

assert not dash_duo.get_logs()
Copy link
Contributor

Choose a reason for hiding this comment

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

@josegonzalez I suppose that test failure was predictable.. we now log a warning.. and the test picks it up! You'll want to update assert not dash_duo.get_logs() accordingly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, the other failures i was talking about previously were eslint errors, but i got them covered.

release Outdated Show resolved Hide resolved
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.

dash_duo.driver.get("data:text/html;charset=utf-8," + html_content)

assert len(dash_duo.get_logs()) == 2
Copy link
Contributor

@Marc-Andre-Rivet Marc-Andre-Rivet Jan 24, 2020

Choose a reason for hiding this comment

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

@josegonzalez The ==2 part is brittle but ok for now I think -- if you could open an issue to improve this part of the test later, I'm fine as-is. What I would like so see here is some validation that the Dash app actually loaded and works as expected. Maybe select the #btn, click it, and make sure at least one of the divs got updated by the callback.

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 ca58cc4 into dev Jan 29, 2020
@Marc-Andre-Rivet Marc-Andre-Rivet deleted the iframe-sandbox-support branch January 29, 2020 21:03
nightsailer added a commit to o3cloud/dash that referenced this pull request Feb 23, 2020
* Add standard dash interface for location change (plotly#1094)

* feat: disable cookie access under restricted sandboxes (plotly#1080)

* IE11 compatibility (plotly#1106)

* Add `inheritAsyncDecorator` for wrapper components (plotly#1109)

* bump version, loosen version requirements

* dcc>=1.7.0, 1.7.1 was JS only

* stricten versions

* stricten table version

Co-authored-by: Marc-André Rivet <Marc-Andre-Rivet@users.noreply.github.com>
Co-authored-by: Jose Diaz-Gonzalez <email@josediazgonzalez.com>
nightsailer added a commit to o3cloud/dash that referenced this pull request Feb 23, 2020
* Add standard dash interface for location change (plotly#1094)

* feat: disable cookie access under restricted sandboxes (plotly#1080)

* IE11 compatibility (plotly#1106)

* Add `inheritAsyncDecorator` for wrapper components (plotly#1109)

* bump version, loosen version requirements

* dcc>=1.7.0, 1.7.1 was JS only

* stricten versions

* stricten table version

Co-authored-by: Marc-André Rivet <Marc-Andre-Rivet@users.noreply.github.com>
Co-authored-by: Jose Diaz-Gonzalez <email@josediazgonzalez.com>
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.

None yet

3 participants