2015-06-14 44 views
0

我想爲在谷歌應用引擎上運行的GWT應用程序實現文件上傳。我用GWTUpload,但收到以下錯誤,如果我嘗試上傳文件:GWT Upload on Google Appengine - 跨站點保護

<stdout>: 2015-06-14 17:50:35 ERROR UploadServlet:70 - checkCORS error Origin: http://myApp.appspot.com does not match:^$ 

我看着UploadServlet,實際上沒有對原產againg「^ $」的支票。我不太相信這個正則表達式匹配「^」似乎是字符串的開始和「$」的結尾。但似乎只匹配一個空字符串?

private boolean checkCORS(HttpServletRequest request, HttpServletResponse response) { 
    String origin = request.getHeader("Origin"); 
    if (origin != null && origin.matches(corsDomainsRegex)) { 
     // Maybe the user has used this domain before and has a session-cookie, we delete it 
     // Cookie c = new Cookie("JSESSIONID", ""); 
     // c.setMaxAge(0); 
     // response.addCookie(c); 
     // All doXX methods should set these header 
     response.addHeader("Access-Control-Allow-Origin", origin); 
     response.addHeader("Access-Control-Allow-Credentials", "true"); 
     return true; 
    } else if (origin != null) { 
     logger.error("checkCORS error Origin: " + origin + " does not match:" + corsDomainsRegex); 
    } 
    return false; 
    } 

我不能設置「corsDomainsRegex」或重寫checkCORS()方法,因爲它們都是私有的。這裏的實際問題是什麼?我該如何解決這個問題?

回答

1

這是一個硬連線檢查,以防止人們通過其他域名上傳文件。如果你不需要這個,你可以通過添加以下內容到你的web.xml(或者你想檢查的任何域)來更改corsDomainsRegex。

<context-param> 
    <!-- match all domains --> 
    <param-name>corsDomainsRegex</param-name> 
    <param-value>.*</param-value> 
</context-param>