Git Product home page Git Product logo

Comments (11)

ndrezn avatar ndrezn commented on June 16, 2024 1

So to summarize we have a few options to tackle this issue:

  1. Disable validation at the component level
  • After some thought & more conversation with @alexcjohnson, I think this is the wrong solution. It basically puts us back to square one: Given an app with a mechanism to save a layout statefully, a bad actor could add a dcc.Link(disable_validation=...) component to the layout before saving, meaning we're back to not protecting at all against XSS.
  1. Disable validation at the framework level
  • This avoids the issue above, because a bad actor can't change the setting at the app configuration level via the layout, but it means that apps with this setting might be unsafe (in @emilhe's PDF example, now this app is vulnerable because we might want to prevent any other links besides the one with the embedded PDF from working).
  1. More fine-grained validation to avoid warnings for safe links (which often, data: is safe)
  • We might be able to further scan the URL string to check whether to allow it or now. Blanket preventing data: might be overkill, essentially. We're using https://github.com/braintree/sanitize-url as the mechanism to check for bad URLs rather than something custom, which is quite popular, and which wholesale prevents javascript:, vbscript:, and data: URLs. It might be worth checking with the maintainers of this package to see if they have considered more fine-grained control.
  1. Retain current behaviour. Maybe we don't want users using data: at all!
  • We might just restrict the use of data: in Dash apps. Argument being, because our choice of URL sanitizer says "Don't do it!", the Dash framework should follow suit. But maybe we need a more permissive URL sanitizer if we want to ensure data: is supported.

In general the real risk is a specific class of applications (applications which allow you to save a portion of the layout as state, for example https://github.com/plotly/all-in-ai-demo-app -- observe what happens when you click/how "Save this chart" works).

There's also the reasonable point that for the original example, maybe using data: in the first place isn't a great way to e.g. display a PDF or embedded data. But data: also isn't going to be deprecated so we might need to allow it generally.

I'm going to open a ticket in https://github.com/braintree/sanitize-url to see if they're thinking about this problem.

from dash.

emilhe avatar emilhe commented on June 16, 2024 1

While I am not expect in web technology, I get the impression looking at the literature that using data: to display media (e.g. PDFs) is not considered bad practice. I am curious; @ndrezn do you consider it bad practice? If yes, do you have an example (a conceptual description, a link to a resource, ...) of good practice realising the same functionality?

I see Dash being used for a great variety of projects, many of which that do not have strict security requirements (e.g. a scientific single-user app running locally). For such users, the proposed change is removing (potentially important) functionality to address concerns (e.g. the save-layout-state example) they'll never face. In general, I consider the ability to adopt standard web technology solutions a key strength of Dash. Hence, removing (some of) this flexibility at framework level (without the ability to opt out) feels like a step in the wrong direction to me - unless there is a really strong argument for doing so.

I of course understand the security concerns, and I appreciate the work being put into addressing them. However, with Dash being such a general framework, I believe that we should strive to keep as much flexibilty as possible. Even if that means enabling users to shoot them self in the foot, if they really want to.

from dash.

AnnMarieW avatar AnnMarieW commented on June 16, 2024

Please see more information in this forum discussion:
https://community.plotly.com/t/dangerous-link-detected-error-in-dash-debug-window-after-upgrading-from-2-14-2-to-2-15-0/82311/3

from dash.

ndrezn avatar ndrezn commented on June 16, 2024

Maybe for components which had sanitization added to prevent the XSS issue should have a new disable_validation= property which if flagged True, would revert to the previous behaviour, but would default to False with the current behaviour.

I am hesitant to introduce specific exceptions for example only allowing data:, or in essence manually overriding parts of our URL sanitizer.

from dash.

AnnMarieW avatar AnnMarieW commented on June 16, 2024

A disable_validation prop would be helpful.

@alexcjohnson had mentioned handling the URL sanitation on the Dash framework level rather than the component level -- then it would apply to all components including custom components or libraries such as dbc and dmc. Is that still on the radar?

from dash.

emilhe avatar emilhe commented on June 16, 2024

@ndrezn I like the idea of the disable_validation flag with a default value of False. That protects the (vast) majority of users, while maintining the option to (consciously) opt out to enable specific usecases.

from dash.

alexcjohnson avatar alexcjohnson commented on June 16, 2024

The specific type of data: urls I’ve seen as exploitable are text/html, which unfortunately is exactly what we document in plotly/plotly.py#4559. That’s not to say there aren’t others that could be abused, we need to do a little more research. In fact it’s possible browsers have even closed the entire data: loophole, see eg https://security.stackexchange.com/questions/258306/how-is-object-tag-data-uri-xss-actually-xss - if so we can perhaps whitelist that whole protocol.

from dash.

ndrezn avatar ndrezn commented on June 16, 2024

@AnnMarieW pointed me to the interesting perspective from Mozilla: https://blog.mozilla.org/security/2017/11/27/blocking-top-level-navigations-data-urls-firefox-59/

Whereas the following cases will be allowed:

  • User explicitly entering/pasting “data:…” into the address bar
  • Opening all plain text data files
  • Opening “data:image/*” in top-level window, unless it’s “data:image/svg+xml”
  • Opening “data:application/pdf” and “data:application/json”
  • Downloading a data: URL, e.g. ‘save-link-as’ of “data:…”

from dash.

BSd3v avatar BSd3v commented on June 16, 2024

Hello all,

Curious as to your thoughts on this as a workaround?

https://community.plotly.com/t/dangerous-link-detected-error-in-dash-debug-window-after-upgrading-from-2-14-2-to-2-15-0/82311/8?u=jinnyzor

Basically, you have a flask template, which is setup to pull the data: back and display it. Flask templates are driven from the server and therefore should be safe to use.

Plus the template is outside the ecosystem of dash. So, it should be safe as far as saving layouts and other props as well.

In this example, the weight falls on the dev to make sure the template is rendering safe and secure files.


from dash import *

app = Dash(__name__)

server = app.server

@server.route('/testfile', methods=['GET'])
def testfile():
    return """<html><body style="width:100%; height:100%;"><iframe style="width:100%; height:100%; border:0;" scrolling="no"
    src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAYUAAACBCAMAAAAYG1bYAAABC1BMVEX///8oLTMXHiUgJi0AAA4UGyMFERsjKC5MUFQAABFfYmUMFR74+PmbnZ/ExcbU1dWpqqva29wsMTeuoMn3N3ato8v5NHSpqM/yPnyxnMYbISgACxeJ1vTx8vLVaJ3SbaDOcqWH2Pb8MHDwQX6Oz+6E3vrm5+eChIaQkpUAAABCRkvHyMmxkL5ucXQ7P0Sur7G5urz8AGDYX5fS1+lnam1VWFzm4O17fYD10t/55+70krH0X47vf6XqyNrXj7bYg63gudHKwty3r9HQ6Pei1/L2tMjKcaXYz+Pk9PvZeKaWzOzWpcXS5vWp5vv/AGDu6vP0obv3usztZJTNwdvjscvBrM721+LqSISor9QSCNdVAAAJ+klEQVR4nO2ca0PbOBaGYzuyE2SHJNAB7JqytE0MNIm7Qwj0NlPa0p3OzjLTmXbn//+StWNJ1s2hLiH2hvN+aSPLjnweXY6OTmg0QCAQCAQCgUAgEAgEAoFAIBAIBAKBQCAQCAQCgUAgEAgEAoFAIBAIBAKB6q2LFy9fvjqXS1+/+enNz65UeP328vLtmVz13fuH79/JVUGl9OH54Q/b29uvhE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app.layout = html.Iframe(src='./testfile', style={'height': '100%', 'width': '100%', 'overflow': 'auto'})

app.run(debug=True)

image

from dash.

BSd3v avatar BSd3v commented on June 16, 2024

Another possible concern would be what this person used as the workaround.

https://community.plotly.com/t/dangerous-link-detected-error-in-dash-debug-window-after-upgrading-from-2-14-2-to-2-15-0/82311/14?u=jinnyzor

This adjusted the srcDoc. Does this potentially expose the same vulnerability?

from dash.

ndrezn avatar ndrezn commented on June 16, 2024

@T4rk1n -- I think the strategy will be to use Mozilla's heuristic for detecting safe URLs and using that custom strategy rather than sanitize-url. We can plan @ libraries meeting this week but we should get this resolved. Curious if you have other thoughts in advance or other strategies you'd recommend.

from dash.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.