【问题标题】:createObjectURL blob url not secure in FirefoxcreateObjectURL blob url 在 Firefox 中不安全
【发布时间】:2016-09-06 09:32:37
【问题描述】:

我正在尝试使用浏览器从安全 URL (https) 保存下载的文件,但我在使用 Firefox 时遇到问题。

我使用 indexedDB 将文件存储在浏览器内存中,下载完成后,我尝试将文件保存在我的计算机中(我使用的是 Mac,但我认为这并不重要)

我有这段代码:

var fileRequest = fileHandle.getFile(); //from indexedDB
fileRequest.onsuccess = function(event){

{...}
var file = event.target.result;
var url = window.URL.createObjectURL(file, {type : fileMimeType, autoRevoke : true});

//I did this with form and not with a href because:
//https://bugzilla.mozilla.org/show_bug.cgi?id=979227

var form = document.createElement('form');
                        form.action = url;
                        document.body.appendChild(form);
                        form.submit();

浏览器要求将此文件保存在“下载”文件夹中,一切似乎都正常,但它总是提示此消息:

“在此页面上输入的信息将通过不安全的连接发送,并且可能被第三方读取。您确定要发送此信息吗?”

如果单击“确定”,文件保存良好,但此安全警告是用户最想在网页中阅读的,因此用户被吓跑了。

createObjectURL 创建的 url 也是一个安全的 url,因为就像: blob:https//blahblah

此警告不会出现在 Chrome 中(使用他自己的文件系统方法)。

我需要帮助:(

【问题讨论】:

  • 同一版本的 chrome 有什么更新吗?

标签: javascript security firefox indexeddb


【解决方案1】:

我使用此代码来避免 Firefox 中的安全警告

 var blobURL = URL.createObjectURL(some_blob);

 var fr = document.createElement('iframe');
 fr.frameBorder = 0;
 fr.width = 1;
 fr.height = 1;
 document.body.appendChild(fr);

 var doc = fr.contentDocument;
 var form = doc.createElement('form');
 form.action = blobURL;
 doc.body.appendChild(form);
 form.submit();
 setTimeout(function(){
    fr.parentNode.removeChild(fr);
 }, 100);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-12-26
    • 1970-01-01
    • 2017-12-23
    • 1970-01-01
    • 2014-01-07
    • 2014-03-05
    • 2012-03-30
    相关资源
    最近更新 更多