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

[BUG] Turn twitter cards off by default to avoid security issues #2536

Closed
shankari opened this issue May 22, 2023 · 4 comments · Fixed by #2540
Closed

[BUG] Turn twitter cards off by default to avoid security issues #2536

shankari opened this issue May 22, 2023 · 4 comments · Fixed by #2540

Comments

@shankari
Copy link

shankari commented May 22, 2023

  • replace the result of pip list | grep dash below
dash                      2.9.3
dash-auth                 2.0.0
dash-bootstrap-components 1.4.1
dash-core-components      2.0.0
dash-extensions           0.1.13
dash-html-components      2.0.0
dash-table                5.0.0
  • if frontend related, tell us your Browser, Version and OS

    • OS: OSX
    • Browser Firefox
    • Version 102.10

Describe the bug

Deploying a dash app with pages allows attackers to embed code into the webapp. This is a potential security vulnerability since it allows attackers to execute arbitrary code in the context of the dash sandbox.

Concretely, if use_pages is true, dash calls self._pages_meta_tags()

if self.use_pages:

which always adds the twitter and og meta tags

<meta property="twitter:card" content="summary_large_image">

The twitter meta tag includes the URL

            <!-- Twitter Card data -->
            <meta property="twitter:card" content="summary_large_image">
            <meta property="twitter:url" content="{flask.request.url}">
            <meta property="twitter:title" content="{title}">
            <meta property="twitter:description" content="{description}">
            <meta property="twitter:image" content="{image_url}">

So if the dash app is involved with a URL that includes a <script> tag, the script specified in the tag will be executed.

Example URL

[dash_app_base_url]/?'"--></style></scRipt><scRipt>netsparker(0x000F45)</scRipt>

This causes our dash app to fail cyber security/pen testing scans.

A workaround is to a custom index_string which removes all meta tags, but that has the disadvantage of not including any meta tags, even the ones that we might want.

A better option would be to make the twitter and og meta tags opt-in; it is not clear that specifying a twitter card is necessary for all deployers.

I am happy to submit a PR (include_card_configs property) if that would help

Screenshots


Vulnerability report

Screenshot 2023-05-21 at 9 54 22 PM

Page source includes the embedded script

Screenshot 2023-05-21 at 9 52 51 PM

Example of an embedded alert in firefox

Screenshot 2023-05-21 at 9 57 17 PM
@alexcjohnson
Copy link
Collaborator

Thanks @shankari! I think we can address the security concern by calling html.escape on the url - and in fact seems like we should do that on everything that goes into any of the <meta> tag attributes. So that would be here and in format_tag

If we can address this security flaw and you still want the ability to skip these meta tags I'd rather make them opt-out rather than opt-in, as they're fairly low overhead and they're a nice touch in various places you might post links to your app.

@shankari
Copy link
Author

@alexcjohnson I have a workaround for this now, so I will see if one of my summer interns can work on this when they get started in a month or so. If not, I will see if I can spend a Friday working on it.

@alexcjohnson
Copy link
Collaborator

@shankari we believe #2540 will remove any possibility of this vulnerability, however even before that we've been unable to reproduce the problem. In every flavor we've tried flask.request.url is already url-encoded when it gets to us. Can you say more about your environment that might help us figure out what's going on? Flask/Werkzeug versions, are you running anything in front of this like gunicorn, are you doing anything else unusual like setting up your own Flask app and giving it to Dash?

T4rk1n added a commit that referenced this issue May 25, 2023
@shankari
Copy link
Author

@alexcjohnson we are also an open source project, so you should be able to clone https://github.com/e-mission/op-admin-dashboard and use the docker-compose files to reproduce.

I just re-tried and was able to reproduce with the following steps:

$ git checkout da9d8f8ba71f44a3eb081862a2eefae2dab04a66
$ docker-compose -f docker-compose-dev.yml build
$ docker-compose -f docker-compose-dev.yml up -d

Then, copy-paste ?'"--></style></scRipt><scRipt>alert(0x000F45)</scRipt> after the http://localhost:8050
I can't put in the link directly because GitHub URL encodes it

An alert pops up (see screenshot below)

Screenshot 2023-05-25 at 9 00 18 AM

To answer your specific questions:

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 a pull request may close this issue.

2 participants