javascript - 使用 Chrome 扩展中的 prompt() 函数来询问密码是否安全?

标签 javascript security google-chrome-extension

我正在开发一个小的扩展,为了简化我的工作,我想使用

prompt("enter password");

以便用户可以输入他/她的密码。我知道提示会将密码显示为纯文本,但还有哪些其他安全问题?其他网站是否可以访问此提示的内容(在这种情况下这将是一件大事)?

最佳答案

如果您不担心输入的文本在没有 *** 的情况下显示,那么它看起来不错。它将与几乎任何其他 JS 密码处理一样安全。

Can other websites have access to the content of this prompt

如果它是一个内容脚本,他们可以拦截 window.prompt 并用他们自己的实现覆盖它,例如:

// page script:
const originalPrompt = window.prompt;
window.prompt = (text) => {
  const result = originalPrompt(text);
  // HERE, the page can do something malicious with the result
  // such as sending it to their server
  console.log('Page detected:', result);
  return result;
};


// Your script:

prompt('Password?');

但这种方法会妥协任何在前端处理密码 - 这不是提示的问题,而是一般的前端.

要在内容脚本中解决这个问题,请确保您调用的提示native 代码版本,这只能以万无一失的方式完成通过在页面上的任何其他代码运行之前运行您的代码。在 document_start 上保存对原始提示的引用。

此外,请确保在后端 而不是前端进行验证。如果你的 JS 是这样的

const userInput = prompt("enter password");
if (userInput !== 'theTruePassword') {
  // wrong
  return;
}
// do stuff

那么对于任何有权访问该网站的人来说,绕过密码检查并通过检查源代码来做事将是微不足道的。相反,确保将密码发送到服务器并让服务器验证密码是否正确,然后让服务器将敏感信息发送回客户端。

关于javascript - 使用 Chrome 扩展中的 prompt() 函数来询问密码是否安全?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66500409/

相关文章:

javascript - Chrome 扩展 - 修改右键单击浏览器操作菜单

javascript - 错误代码 : "auth/internal-error" message: "Photo URL too long." Prototype N

javascript - 创建/下载带有 chrome 扩展名的 excel 文件

javascript - Chrome 扩展程序 : Passing DOM Information to background page/script

javascript - 如何最好地保护对 soap 服务的访问

java - 我们什么时候在 spring security 中使用 denyAll

windows - Windows CardSpace 有何用途?

javascript - 火狐扩展。 DOMContentLoaded 在某些页面上多次触发

javascript - 如何在动态插入的 <input> 标记上初始化 jQuery 日期选择器?

javascript - 浏览器能否将有效负载数据拆分为多个 websocket 帧?