macos - 检测用户正在 chrome/firefox/safari 中查看的 url

标签 macos cocoa security

如何通过 cocoa(桌面应用程序)检测我在 chrome/safari/firefox 中浏览的网址?

作为附带但相关的说明,开发桌面应用程序时是否存在任何安全限制,用户会收到警报并询问是否允许?例如应用程序是否访问他们的联系信息等。

寻找基于 cocoa 的解决方案,而不是 JavaScript。

最佳答案

我会将其作为扩展程序,并且因为您希望以 Chrome、Safari 和 Firefox 为目标,所以我会使用 Crossrider 等跨浏览器扩展框架。

因此,请访问 crossrider.com,设置帐户并创建新的扩展程序。然后打开background.js 文件并粘贴如下代码:

appAPI.ready(function($) {
    appAPI.message.addListener({channel: "notifyPageUrl"}, function(msg) {
        //Do something, like send an xhr post somewhere 
            // notifying you of the pageUrl that the user visited.
        // The url is contained within msg.pageUrl      
    });

    var opts = { listen: true}; 
    // Note: When defining the callback function, the first parameter is an object that
    //       contains the page URL, and the second parameter contains the data passed
    //       to the context of the callback function.
    appAPI.webRequest.onBeforeNavigate.addListener(function(details, opaqueData) {
        // Where:
        //   * details.pageUrl is the URL of the tab requesting the page
        //   * opaqueData is the data passed to the context of the callback function
        if(opaqueData.listen){
            appAPI.message.toBackground({
                msg: details.pageUrl
            }, {channel: "notifyPageUrl"});
        }
    }, opts ); // opts is the opaque parameter that is passed to the callback function
});

然后安装扩展!在上面的示例中,没有对检测到的用户正在访问的 pageUrl 执行任何操作,但是您可以在这里执行任何您喜欢的操作 - 您可以向用户发送消息,您可以利用 cancel 或 redirectTo 返回参数来限制访问,您可以可以使用 crossrider appAPI.db API 在本地记录它,或者您可以直接从后台使用 XHR 请求将通知发送到其他地方(跨域)。

希望有帮助!

要回答有关桌面端安全问题的问题,请注意桌面应用程序将拥有其运行所在用户的权限。因此,如果您正在考虑提供一个供用户在本地运行的桌面应用程序,请说一些内容,通过使用 Windows 上的 winpcap 或 *nix 品种上的 libpcap 等工具进入网络流来检测他们访问的 URL,然后请注意这一点- 而且 libpcap 和 friend 必须有权访问可以由相关用户首先置于混杂模式的网卡。

pcap/安装的桌面应用程序解决方案相当具有侵入性 - 大多数人不希望您监听所有内容,并且实际上可能违反一些安全策略,具体取决于您的用户工作位置 - 他们的网络管理员可能不喜欢您“嗅探” ,无论这是否是实际目的。安全人员可以在此类主题上得到真正令人毛骨悚然的说法。

如果我正确理解了目标,那么通过 Crossrider 进行扩展可能是实现目标的最简单且侵入性最小的方式。

最后一点,您可以使用 Crossrider 的选项卡 API 获取所有选项卡的当前选项卡 URL:

// retrieves the array of tabs
appAPI.tabs.getAllTabs(function(allTabInfo) {
    // Display the array
    for (var i=0; i<allTabInfo.length; i++) {
        console.log(
            'tabId: ' + allTabInfo[i].tabId +
            ' tabUrl: ' + allTabInfo[i].tabUrl
        );
    }
});

标签API请引用: http://docs.crossrider.com/#!/api/appAPI.tabs

对于后台导航API: http://docs.crossrider.com/#!/api/appAPI.webRequest.onBeforeNavigate

对于消息传递: http://docs.crossrider.com/#!/api/appAPI.message

对于 appAPI.db 的内容: http://docs.crossrider.com/#!/api/appAPI.db

关于macos - 检测用户正在 chrome/firefox/safari 中查看的 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17028464/

相关文章:

security - 在应用程序中存储主机和端口数据是否会使服务器容易受到攻击?

cocoa - 在 Mac OS X 上使用 Cocoa 调整 JPEG 大小并将新文件保存为 JPEG

macos - 从boxen卸载nodenv

ios - 新Xcode开发电脑证书问题

python - 无法安装 MySQL-Python Mac Mavericks

c# - 如何在 SQL Server 2012 中加密某些行的某些列

macos - Mac OS X 上 NSAttributedString initWithRTF 没有可见接口(interface)

iphone - 主线程上的 NSOperation 和 NSNotificationCenter

cocoa - NSFetchedResultsController Mac OSX Cocoa 等效项

c# - 如何从收到的 msmq 消息中获取发件人的 WindowsIdentity?