mozilla / makedrive

[RETIRED] Webmaker Filesystem
Mozilla Public License 2.0
351 stars 33 forks source link

Safely allow server-side creation of new files in order to overcome origin issues #417

Closed humphd closed 7 years ago

humphd commented 9 years ago

Imagine I want to put http://some-other-origin.com/image.png into my filesystem. I have two options:

The problem with the first method is that we can't get the raw bytes for a file we XHR unless it's same-origin. In order to make it possible, we'd have to proxy the file from our MakeDrive origin (e.g., XHR https://makedrive.webmaker.org/download?url=http://some-other-origin.com/image.png). This is possible, but also kind of sucks.

Another option is to do what I've outlined above in option 2, specifically, we somehow tell the MakeDrive server to download this file and get its raw bytes (no origin restrictions on server-side). The tricky part is simulating having the server be another client for this user, and safely writing this new file to the user's filesystem without causing a conflict.

This will help with #402, and the case that we want to "download" an arbitrary URL into our filesystem.

humphd commented 9 years ago

One way to do this would be to have the client specify a filename to use:

humphd commented 9 years ago

Here's how I think this should be done:

humphd commented 9 years ago

NOTE: I don't think this is a requirement for Everest, since Mobile Webmaker doesn't need it (yet). However, the CreativeCommons people will want this.

humphd commented 9 years ago

I think I've talked myself out of doing this. It's going to be a really weird user experience if you request a URL be downloaded into your drive in the browser, send that request to the server, wait for the server to get a lock, download that file, then for a downstream sync. It's also going to be complicated to deal with exclusive path access for the downloaded file, which becomes easy if we just grab it directly via the client.

I think the answer is to have MakeDrive provide a proxy so you can download arbitrary data into your drive locally. Maybe we can build something on top of https://github.com/nodejitsu/node-http-proxy.

humphd commented 9 years ago

I really want to find time to discuss this approach with @Pomax, since Thimble does something similar for http->https mixed-content proxying for images and the like, see https://github.com/mozilla/thimble.webmaker.org/blob/20f91c43ba80071e461e20ab05a6e1c4ed742fd4/lib/proxy.js. I wonder if we can use something similar here.

gideonthomas commented 9 years ago

@humphd would we want to implement this only to avoid cross origin issues?

humphd commented 9 years ago

Correct. I think it's worth exploring, but it's not a P1 I don't think. Users are going to want to stuff things into their filesystem that they find on the web. We need to support that somehow, given origin policy.