简体   繁体   English

window.prompt() 可以比经典形式更安全吗?

[英]Can window.prompt() be more secure then the classic form?

I'm developing a pure javascript app that will run entirely on the client side and MUST BE VERY SECURE .我正在开发一个纯 javascript 应用程序,它将完全在客户端运行并且必须非常安全

At the start I need to get a password to decrypt a file, after that I don't need to save it for any future uses.一开始我需要获取密码来解密文件,之后我不需要保存它以备将来使用。

So my question is: can the window.prompt() be more secure to get this password than write it in a <input> field and retrieve it through document.getElementById().value ?所以我的问题是: window.prompt()能否比将其写入<input>字段并通过document.getElementById().value检索它更安全地获取此密码?

Thanks谢谢

No, there is no guarantee of practical difference in security.不,不能保证安全性的实际差异。 An injected script could hook window.prompt to intercept anything entered.注入的脚本可以挂钩 window.prompt 以拦截输入的任何内容。 For example:例如:

// In the attacker's script
const _prompt = window.prompt;
window.prompt = function(p) {
  const v = _prompt(p);
  alert(`I intercepted ${v}`);
  return v;
}

// In your script
window.prompt("Enter your secret password");

You could perhaps take a private handle to window.prompt, but you'd have to be certain that it happened prior to point that a script could be injected.您也许可以将一个私有句柄用于 window.prompt,但您必须确定它发生在可以注入脚本之前。

As far as I know there is no difference as you don't seem to send the form over the network and there is no extra level of security between window.prompt and the browser (where you have to handle the entered password at some time).据我所知没有区别,因为您似乎没有通过网络发送表单,并且 window.prompt 和浏览器之间没有额外的安全级别(您必须在某个时间处理输入的密码) .

As for any other vulnerabilities such as keyloggers, infected packages, weak or wrongly stored passwords, there are very much open to the same risks.至于任何其他漏洞,例如键盘记录器、受感染的软件包、弱密码或错误存储的密码,都存在同样的风险。

Don't know if I'd use the term VERY SECURE in regards to any javascript application, but well, there you have it.不知道我是否会在任何 javascript 应用程序中使用术语“非常安全”,但是,您已经知道了。

Edit: Actually, there is one major difference.编辑:实际上,有一个主要区别。 I don't think there is a way to mask the entry in the window.prompt like you can do with a form input set to type password.我认为没有办法像使用设置为输入密码的表单输入那样屏蔽 window.prompt 中的条目。 If there is no workaround for that, and I don't think there is, given everything else is about the same level of security, the input field is definetly more secure.如果没有解决方法,我认为没有,鉴于其他所有内容的安全级别大致相同,输入字段肯定更安全。

https://developer.mozilla.org/de/docs/Web/API/Window/prompt https://developer.mozilla.org/de/docs/Web/API/Window/prompt

 <button onClick="window.prompt()">trigger prompt</button> <input type='password'>

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

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