【问题标题】:PhoneGap and cross domain callsPhoneGap 和跨域调用
【发布时间】:2013-03-03 15:31:22
【问题描述】:

我一直在为客户进行安全审查,并在 config.xml 中遇到了这一行 它是一款适用于 Android 设备的 phonegap 应用程序

<access origin=".*"/>

如果它只是 origin=* 我会知道这意味着它可以访问任何其他站点。 但是 .* 是什么意思?和*一样吗​​?

谢谢

【问题讨论】:

  • 我假设这是一个正则表达式,其中.* 的意思是“匹配零到 N 次出现的任何字符”。

标签: android security cordova mobile


【解决方案1】:

来自 Cordova Android source code:

private void _addWhiteListEntry(String origin, boolean subdomains) {
    try {
        // Unlimited access to network resources
        if (origin.compareTo("*") == 0) {
            LOG.d(TAG, "Unlimited access to network resources");
            this.whiteList.add(Pattern.compile(".*"));
        } else { // specific access
            // check if subdomains should be included
            // TODO: we should not add more domains if * has already been added
            if (subdomains) {
                // XXX making it stupid friendly for people who forget to include protocol/SSL
                if (origin.startsWith("http")) {
                    this.whiteList.add(Pattern.compile(origin.replaceFirst("https?://", "^https?://(.*\\.)?")));
                } else {
                    this.whiteList.add(Pattern.compile("^https?://(.*\\.)?" + origin));
                }
                LOG.d(TAG, "Origin to allow with subdomains: %s", origin);
            } else {
                // XXX making it stupid friendly for people who forget to include protocol/SSL
                if (origin.startsWith("http")) {
                    this.whiteList.add(Pattern.compile(origin.replaceFirst("https?://", "^https?://")));
                } else {
                    this.whiteList.add(Pattern.compile("^https?://" + origin));
                }
                LOG.d(TAG, "Origin to allow: %s", origin);
            }
        }
    } catch (Exception e) {
        LOG.d(TAG, "Failed to add origin %s", origin);
    }
}

显然,如果不完全是*,他们会将所有内容都视为正则表达式。相信这种行为可能不是一个好主意,因为它不是 documented 并且不在目标 W3C Widget Access 规范中。 (我认为这可能不是故意的。)

但是.* 仍然在PhoneGap 2.5.0 项目模板中使用,所以现在没问题,只要您使用一个版本的PhoneGap。

【讨论】:

    【解决方案2】:

    我认为没有必要:

    http://www.w3.org/TR/widgets-access/

    PhoneGap 文档中未提及:

    http://docs.phonegap.com/en/2.5.0/guide_whitelist_index.md.html#Domain%20Whitelist%20Guide

    这是正则表达式:

    http://www.regular-expressions.info/reference.html

    ".*" matches 
    "def" "ghi" in 
    abc "def" "ghi" jkl
    

    【讨论】:

      【解决方案3】:

      * 表示通配符。当有 * 存在时,这意味着该应用程序可以访问任何外部站点。如果您将 * 替换为域,那么它将只允许应用访问该特定站点。

      <access origin="*" /> // all external domains
      <access origin="http://google.com" /> // app can only reach google all other doamins are restricted
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-09-30
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多