CORS issue with Tomcat and Android Webview

后端 未结 5 798
南笙
南笙 2021-02-15 12:38

I am facing a strange problem with Tomcat 8 and CORS. I am developing a Hybrid web app using ionicframework, AngularJS, Cordova as front end and Tomcat 8 and Spring 3 as back-en

5条回答
  •  我寻月下人不归
    2021-02-15 13:26

    I did more research on this and figure out the issue.If you see the headers from Android and look into Origin Header.

    Origin: file://
    

    Tomcat CORS filter tries to validate the URI in Origin header and considers "file://" as an invalid URI and returns back 403.

         */
        protected static boolean isValidOrigin(String origin) {
           /* // Checks for encoded characters. Helps prevent CRLF injection.
            if (origin.contains("%")) {
                return false;
            }
    
            URI originURI;
    
            try {
                originURI = new URI(origin);
            } catch (URISyntaxException e) {
                return false;
            }
            // If scheme for URI is null, return false. Return true otherwise.
            return originURI.getScheme() != null;
    */
            return true;
        }
    

    I need to dig more on why Android is sending the incorrect URI.

提交回复
热议问题