HOWTO:使用受信任区域助手锁定 Internet Explorer






4.67/5 (15投票s)
2005 年 1 月 14 日
7分钟阅读

126324

801
本文包含一个完整的、可运行的 Javascript,具有插入 Internet Explorer 的用户界面。该插件可让您轻松管理哪些网站属于您的“受信任区域”。受信任区域是一个很少使用(通常也不为人知)的强大安全功能,它属于
引言
最近 Internet Explorer 围绕着它有很多不好的新闻,我认为其中很多是毫无根据的。我经常浏览一些网络论坛,看到人们热衷于宣传切换到 FireFox 的好处,但说实话,我并不相信(至少现在还不相信)。Internet Explorer 的主要问题是它的用户,我并非带有冒犯的意思——这只是一个简单的事实,微软总是被电脑新手所困扰,因为他们创建的软件最容易使用且最易获得。这对微软造成了毁灭性的影响,正如 FireFox 逐渐蚕食市场份额所证明的那样。
我并不是说 IE 是完美的——因为它显然不是,但我说它的最大问题是用户群。
微软在 SP2 中迈出了大步,但最近有所放缓——自去年发布以来,只发布了寥寥几个热修复补丁。并且看到安全公告的底部,通常在小字中写着“XP Service Pack 2 未受影响”,这总是令人欣慰的。
但是,仍然存在几个反复出现的、我称之为“黑客热点”的问题,这些问题在 Service Pack 2 中并未完全修复。这当然是 Active Scripting 及其几乎所有相关内容。就在最近,Internet Explorer 的这个特定部分又发现了几处漏洞,而且几个月来,即使是 CERT 等机构的安全公告也建议禁用 IE 的“Internet 区域”中的 Active Scripting 和其他一些相关权限。
这时我想:“既然我经常访问的网站中可能有一半都需要它才能登录,那我为什么要禁用 Active Scripting 呢?” 就在那时我灵光一闪。为什么不把我所有喜欢的网站都添加到“受信任区域”,并将受信任区域的安全权限设置得相当低,同时将 Internet 区域的安全级别设置为最高(并禁用 Active Scripting)呢?
IE 似乎没有一个易于访问的界面来控制您信任或不信任的网站。所以,我的这个“Code Project”就派上用场了……
Internet Explorer 受信任区域助手插件
经过一番思考,我决定需要一个额外的菜单项添加到任何网页的右键上下文菜单中……一种对话框,可以让您只需几次鼠标点击,轻松地将当前网站的域名添加到受信任区域或从中移除。
我的第一个版本仅仅是一个简单的 JavaScript confirm()
消息框,询问您是否要将“domain.com”添加到受信任区域,如果它已经存在,则询问您是否要将其移除。对于我个人而言,这是一个不错的工具,可以用上几天,但我确实想让它更用户友好、更强大、带有一点风格,让我在这样的伟大网站上分发。
对于界面,我决定几乎完全“模仿” Service Pack 2 的 Internet Explorer 中要求您确认发布者才能运行可执行文件的那个新对话框。
这就是我最终的成果
现在您可能会想“那只是一个普通的 Windows 对话框”,但您错了 :~) 它实际上是一个 HTML 表格、两个表单按钮(但没有表单)以及巧妙使用的 CSS 样式。IE 的 CSS 支持系统颜色,所以背景颜色只需要使用 background-color:ButtonFace;
,字体颜色使用 color:WindowText
,当然,自 Windows 2000 以来标准的对话框字体一直是 Tahoma,但为了保险起见,我使用了“font: 8pt Tahoma, MS Shell Dlg”。
内部
要将额外的菜单项添加到 IE 的右键菜单(也称为上下文菜单),只需将以下条目添加到注册表中即可
“HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\My new menu”
这是我的插件的外观
还有两个额外的键可用:Contexts
和 Flags
。
Contexts
允许您指定额外的菜单项将在哪些 HTML 元素上可用。因此,如果您正在开发一个下载管理器,您只会为锚链接分配一个 Context
。但对于我的插件,我使用的是 Contexts
0x1(也称为默认)。默认意味着该菜单项仅当用户右键单击网页正文时可用——也就是说,他们没有右键单击页面的任何特定元素,例如图像或文本选择。
Flags
稍微复杂一些。将此参数设置为 0x1(就像我的插件中一样)意味着您的 JavaScript 将在新模态对话框窗口中打开。从技术上讲,它与 DOM 中的 createModalDialog
方法非常相似——但是,拥有 Flags
确实为您提供了更多的特权,因为它当然是在本地计算机上运行,而不是在某个网站上。
下一部分是关于 IE 的 ZoneMap
注册表项。位于“HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains”。这就是存储所有关于哪些网站被信任和不被信任的详细信息的地方。我的插件只需要操作这些注册表项,根据用户的意愿添加和删除。不过,这可能会有点复杂,因为 IE 并不识别所有 SLD(二级域名),例如“adslguide.org.uk”和任何使用“.org.uk”的域名都将存储在一个名为“org.uk”的树下,而 IE 确实识别其他 SLD,例如“.co.uk”,任何使用此 SLD 的域名都将始终存储在其自身的唯一键中。我在 JavaScript 中进行了大量的技巧才使其对用户来说能够无缝且完美地工作。
在我的脚本源代码中,我引用了“已知 SLD”和“未知 SLD”。现在可能很明显了,但已知 SLD 是 IE 识别的(例如“.co.uk”),而未知 SLD 是它不识别的(例如“.org.uk”)。
目前您无法使用此插件来信任 IP 地址。我还在犹豫是否需要信任 IP 地址。但是,如果您需要此功能,请随时修改源代码。
我为之自豪的一件很棒的事情,尽管它很简单,是脚本处理带有“favicon.ico”的网站的方式。对于不知道的人来说,这是一个位于网站根目录的普通图标文件,现代浏览器可以用它来显示收藏夹列表中的图标。正如我之前所说,我非常希望保持用户界面与 SP2 IE 中新的安全对话框一致,正如您在上面的截图中看到的,它显示了可执行文件的图标。所以我想使用网站的 favicon 来显示您即将信任的网站的图标。我不知道,只是给它增加了一点特色。如果网站没有 favicon,它将回退到标准图标(请参阅代码了解其工作原理)。我想让它使用 res:// URL 来获取标准的系统图标,但出于某种原因,<img>
和 res:// 配合 .ico 根本不起作用。
请注意:我只在我的 Windows XP Service Pack 2 工作站上测试过此代码。虽然我看不出有什么理由它不能在 IE5 系统上工作。
推荐的安全区域设置
您可以通过输入“Internet Options->Security”选项卡来配置 Internet 和受信任区域的权限。选择区域,然后单击“Custom Level…”按钮。
Internet 区域
Run components not signed with Authenticode = Disable
Run components signed with Authenticode = Disable
Automatic prompting for ActiveX controls = Disable
Binary and script behaviours = Enable
Download signed ActiveX controls = Disable
Download unsigned ActiveX controls = Disable
Initialize and script ActiveX controls not marked as safe = Disable
Run ActiveX controls and plug-ins = Enable
Script ActiveX controls marked safe for scripting = Enable
Automatic prompting for file downloads = Disable
File Download = Enable
Font Download = Disable
Java permissions = High safety
Access data sources across domains = Disable
Allow META REFRESH = Enable
Allow scripting of Internet Explorer Webbrowser control = Disable
Allow script-initiated windows without size
or position constraints = Disable
Allow web pages to use restricted protocols for
active content = Prompt
Display mixed content = Prompt
Don't prompt for client certificate selection when no
certificates or only one certificate exists = Disable
Drag and drop or copy and paste files = Disable
Installation of desktop items = Disable
Launching programs and files in an IFRAME = Disable
Navigate sub-frames across different domains = Enable
Open files based on content, not file extention = Enable
Software channel permissions = High safety
Submit nonencrypted form data = Enable
Use Pop-up Blocker = Enable
Userdata persistence = Enable
Web sites in less privileged web content zone
can navigate into this zone = Enable
Active Scripting = Disable
Allow paste operations via script = Disable
Scripting of Java applets = Enable
Logon = Automatic logon only in Intranet zone
受信任区域
Run components not signed with Authenticode = Disable
Run components signed with Authenticode = Enable
Automatic prompting for ActiveX controls = Disable
Binary and script behaviours = Enable
Download signed ActiveX controls = Prompt
Download unsigned ActiveX controls = Disable
Initialize and script ActiveX controls not marked as safe = Disable
Run ActiveX controls and plug-ins = Enable
Script ActiveX controls marked safe for scripting = Enable
Automatic prompting for file downloads = Disable
File Download = Enable
Font Download = Enable
Java permissions = High safety
Access data sources across domains = Disable
Allow META REFRESH = Enable
Allow scripting of Internet Explorer Webbrowser control = Enable
Allow script-initiated windows without size or
position constraints = Disable
Allow web pages to use restricted protocols for active content = Prompt
Display mixed content = Prompt
Don't prompt for client certificate selection when no certificates
or only one certificate exists = Disable
Drag and drop or copy and paste files = Enable
Installation of desktop items = Disable
Launching programs and files in an IFRAME = Disable
Navigate sub-frames across different domains = Enable
Open files based on content, not file extention = Enable
Software channel permissions = Medium safety
Submit nonencrypted form data = Enable
Use Pop-up Blocker = Enable
Userdata persistence = Enable
Web sites in less privileged web content zone can navigate
into this zone = Enable
Active Scripting = Enable
Allow paste operations via script = Disable
Scripting of Java applets = Enable
Logon = Automatic logon only in Intranet zone
安装
请参阅 ZIP 存档中包含的 Readme.txt。
更改日志
- 19-01-2005:
- 修复了图标大小错误 - 例如,16x16 的图标现在可以正确显示,而不是被缩放到 32x32。
- 修复了点击选项文本时选项按钮选择未触发的问题。
- 向文章添加了右键菜单的截图。
- 2005-01-14:初始发布。