Firefox 扩展中的 Javascript 范围/安全问题

发布于 2024-11-06 06:46:22 字数 757 浏览 0 评论 0原文

我正在开发一个 FireFox 扩展程序,并且必须存储一些我需要安全且无法从任何其他扩展程序/页面等访问的值。

我正在使用我的扩展程序代码的设置,如下所示:

if(!namesp) var namesp={};
if(!namesp.anothernamesp) namesp.anothernamesp={};

namesp.anothernamesp = function() {
  var mySecureValue = ''; //is this variable accessible from anything aside from inside the namesp.anothernamesp scope?

  return {
    useSecureValue: function() {
    //do something here with mySecureValue
    }
  };

  function getSecureValue() { //can this method be called from anywhere besides inside the namesp.anothernamesp scope?
    return mySecureValue;
  }

}();

除了我的之外,还有其他方法吗自己的扩展可以访问“mySecureValue”吗?为了使我可能在扩展等中打开的任何窗口都可以全局访问此对象,我将对象传递给 window.openDialog() 方法中的窗口,并使用 window.arguments 从新创建的窗口访问它。谢谢。

I am developing a FireFox extension and have to store some values that I need to be secure and inaccessible from any other extension/page etc.

I am using a setup for my extension code like seen here:

if(!namesp) var namesp={};
if(!namesp.anothernamesp) namesp.anothernamesp={};

namesp.anothernamesp = function() {
  var mySecureValue = ''; //is this variable accessible from anything aside from inside the namesp.anothernamesp scope?

  return {
    useSecureValue: function() {
    //do something here with mySecureValue
    }
  };

  function getSecureValue() { //can this method be called from anywhere besides inside the namesp.anothernamesp scope?
    return mySecureValue;
  }

}();

Is there any way that anything other than my own extension can access "mySecureValue"? To keep this object global accessible to any windows I might open in my extension etc, I pass the object to the window in the window.openDialog() method and use the window.arguments to access it from the newly created windows. Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

执手闯天涯 2024-11-13 06:46:22

看起来很正确。事实上,这是大多数教程和书籍教授的模拟私有方法和属性的方法。

Seems pretty correct. In fact that's a way the majority of tutorials and books teach to simulate private methods and properties.

假情假意假温柔 2024-11-13 06:46:22

,您无法阻止一个扩展程序影响另一个扩展程序。

原因是:

  • 扩展名是 Zip 存档文件重命名为 *.xpi 文件扩展名。
  • 扩展程序使用 JavaScript 方言以纯文本文件形式编写,
  • 任何其他扩展程序都可以随意打开和访问您的浏览器可以访问的任何文件。

如果其他扩展想要读取您的变量 mySecureValue,它可以通过以下方式实现:

  • 访问您的扩展 *.xpi 文件(使用 nsIFileprofile/extensions 文件夹中读取它)
  • 解压缩nsIZipReader
  • 从源文件中读取变量 mySecureValue

最不幸的原因是 Mozilla firefox 没有在扩展之间实现任何形式的正确分离。每个扩展都可以为每个人做任何事情。它甚至可以执行 shellcode 并造成仲裁其他损害。

您唯一可以尝试的就是混淆您的秘密数据。这虽然不能阻止攻击,但可能只会使攻击复杂化。

No, there is no way you can keep one extension from impacting another extension.

The reasons for that are:

  • extensions are Zip-archive-files renamed to have a *.xpi filename extension.
  • the extensions are writen in plaintextfiles using a JavaScript dialect
  • any other extension can at will open and access any file that your browser can access.

If some other extension wants to read your variable mySecureValue it can do so by:

  • accessing the your extensions *.xpi file (using nsIFile to read it from the profile/extensions folder)
  • unzip it nsIZipReader
  • read the variable mySecureValue from your source file!

The most unfortunate reason for all that is that Mozilla firefox does not implement any form of right separation between the extensions. Every extension can do everything to everybody. It can even excecute a shellcode and do arbitraty other damage.

The only thing you can try is to obfuscate your secret data. This will though not prevent but maybe only complicate the attack.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文