简体   繁体   English

response.send从Chrome重定向到文件URL

[英]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. 我有一个URL缩短应用程序(类似于tinyurl.com,bit.ly等),它也重定向到file:// URL。

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. 在内部,这是一个基于Servlet的Web应用程序,我所做的就是从服务器端检索targetURL并执行response.sendRedirect(targetURL)

This works fine for file:// URLs too. 这也适用于file:// URL。 However, recently, this has stopped working on Chrome. 但是,最近,这已停止在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"). 当我尝试重定向到file://foo.txt (通过response.sendRedirect('file://foo.txt') ,事情就失败了(Chrome调试器说“已取消”)。

Things work fine in FF and IE however. 但是,在FF和IE中一切正常。 Any clues ? 有什么线索吗?

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). 我会说这是个坏主意,至少我很高兴chrome否认了这一点(尽管我怀疑其他浏览器也会这么做)。 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. 我用bit.ly测试了您的用例,并尝试在其中添加file:/// url,它被视为无效的URL,不能被缩短。

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. 另一种选择是通过“投递灯”扩展服务,您的用户可以在其中将有问题的文件上传到存储服务,并且可以基于通过常规http / https从存储中提供的文件来生成简短的url。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM