ragebiswas
ragebiswas

Reputation: 3878

response.sendRedirect to a file URL from Chrome

I have a URL shortener app (similar to tinyurl.com, bit.ly etc) which redirects to file:// URLs as well.

Internally, this is a Servlet based web-app, and all I do is, retrieve the targetURL and do a response.sendRedirect(targetURL) from the server side.

This works fine for file:// URLs too. However, recently, this has stopped working on Chrome. When I try to redirect to file://foo.txt (via a response.sendRedirect('file://foo.txt'), things simply fail (the Chrome debugger says "Cancelled").

Things work fine in FF and IE however. Any clues ?

Upvotes: 1

Views: 1830

Answers (1)

NilsH
NilsH

Reputation: 13821

I'd say this is a bad idea, and I'm glad at least chrome denies this (although I would suspect that other browsers would as well). It would be a pretty big security hole if you could instruct someone else's browser to open an arbitrary file.

Second, why would you want to do this? It would require that the user actually have this same file, at the same location on their computer. Seems like a pretty narrow use case. I tested your use case with bit.ly, and it you try to add a file:/// url there, it's regarded as an invalid URL and cannot be shortned.

Edit: There's a very good answer covering the same topic here. It references this useful resource about security restrictions with redirection.

You also specify that this is for an internal app. If you're attempting to do some sort of document sharing, I'd say you should look into dedicated systems for this. Another option is to extend your service with a "dropbox light", where your users can upload the file in question to a storage service, and you can generate a shortned url based on serving the file from your storage via regular http/https.

Upvotes: 1

Related Questions