2013-03-03 46 views
1

我一直致力於安全審查的客戶和在config.xml跨越這條線來 其Android設備的PhoneGap和跨域調用

<access origin=".*"/> 

如果這只是原點的PhoneGap的應用程序= *我知道這意味着它可以訪問任何其他網站。 但。*是什麼意思?和*一樣嗎​​?

感謝

+0

我會假設這是一個正則表達式,其中'。*'表示「匹配零到N次出現的任何字符」。 – CommonsWare 2013-03-03 15:37:27

回答

1

從科爾多瓦的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中即可。

0

*表示通配符。當有*時,這意味着應用程序可以訪問任何外部網站。它用一個域替換*,然後它將只允許應用訪問該特定網站。

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