You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by GitBox <gi...@apache.org> on 2020/12/02 04:56:47 UTC

[GitHub] [cordova-android] dpogue commented on a change in pull request #1138: feat(allow-list): integrate and refactor core plugin

dpogue commented on a change in pull request #1138:
URL: https://github.com/apache/cordova-android/pull/1138#discussion_r533896184



##########
File path: framework/src/org/apache/cordova/AllowListPlugin.java
##########
@@ -0,0 +1,162 @@
+/*
+       Licensed to the Apache Software Foundation (ASF) under one
+       or more contributor license agreements.  See the NOTICE file
+       distributed with this work for additional information
+       regarding copyright ownership.  The ASF licenses this file
+       to you under the Apache License, Version 2.0 (the
+       "License"); you may not use this file except in compliance
+       with the License.  You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+       Unless required by applicable law or agreed to in writing,
+       software distributed under the License is distributed on an
+       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+       KIND, either express or implied.  See the License for the
+       specific language governing permissions and limitations
+       under the License.
+*/
+
+package org.apache.cordova;
+
+import org.apache.cordova.CordovaPlugin;
+import org.apache.cordova.ConfigXmlParser;
+import org.apache.cordova.LOG;
+import org.apache.cordova.AllowList;
+import org.xmlpull.v1.XmlPullParser;
+
+import android.content.Context;
+
+public class AllowListPlugin extends CordovaPlugin {
+    public static final String PLUGIN_NAME = "CordovaAllowListPlugin";
+    protected static final String LOG_TAG = "CordovaAllowListPlugin";
+
+    private AllowList allowedNavigations;
+    private AllowList allowedIntents;
+    private AllowList allowedRequests;
+
+    // Used when instantiated via reflection by PluginManager
+    public AllowListPlugin() { }
+
+    // These can be used by embedders to allow Java-configuration of an allow list.
+    public AllowListPlugin(Context context) {
+        this(new AllowList(), new AllowList(), null);
+        new CustomConfigXmlParser().parse(context);
+    }
+
+    public AllowListPlugin(XmlPullParser xmlParser) {
+        this(new AllowList(), new AllowList(), null);
+        new CustomConfigXmlParser().parse(xmlParser);
+    }
+
+    public AllowListPlugin(AllowList allowedNavigations, AllowList allowedIntents, AllowList allowedRequests) {
+        if (allowedRequests == null) {
+            allowedRequests = new AllowList();
+            allowedRequests.addAllowListEntry("file:///*", false);
+            allowedRequests.addAllowListEntry("data:*", false);
+        }
+
+        this.allowedNavigations = allowedNavigations;
+        this.allowedIntents = allowedIntents;
+        this.allowedRequests = allowedRequests;
+    }
+
+    @Override
+    public void pluginInitialize() {
+        if (this.allowedNavigations == null) {
+            this.allowedNavigations = new AllowList();
+            this.allowedIntents = new AllowList();
+            this.allowedRequests = new AllowList();
+
+            new CustomConfigXmlParser().parse(webView.getContext());
+        }
+    }
+
+    private class CustomConfigXmlParser extends ConfigXmlParser {
+        @Override
+        public void handleStartTag(XmlPullParser xml) {
+            String strNode = xml.getName();
+            if (strNode.equals("content")) {
+                String startPage = xml.getAttributeValue(null, "src");
+                allowedNavigations.addAllowListEntry(startPage, false);
+            } else if (strNode.equals("allow-navigation")) {
+                String origin = xml.getAttributeValue(null, "href");
+                if ("*".equals(origin)) {
+                    allowedNavigations.addAllowListEntry("http://*/*", false);
+                    allowedNavigations.addAllowListEntry("https://*/*", false);
+                    allowedNavigations.addAllowListEntry("data:*", false);
+                } else {
+                    allowedNavigations.addAllowListEntry(origin, false);
+                }
+            } else if (strNode.equals("allow-intent")) {
+                String origin = xml.getAttributeValue(null, "href");
+                allowedIntents.addAllowListEntry(origin, false);
+            } else if (strNode.equals("access")) {
+                String origin = xml.getAttributeValue(null, "origin");
+                String subdomains = xml.getAttributeValue(null, "subdomains");
+                boolean external = (xml.getAttributeValue(null, "launch-external") != null);
+                if (origin != null) {
+                    if (external) {
+                        LOG.w(LOG_TAG, "Found <access launch-external> within config.xml. Please use <allow-intent> instead.");

Review comment:
       Now seems like a good time to drop this deprecated `<access launch-external>` support?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org