coheigea commented on code in PR #3794:
URL: https://github.com/apache/cxf/pull/3794#discussion_r4720593808


##########
core/src/main/java/org/apache/cxf/resource/URIResolver.java:
##########
@@ -508,6 +509,51 @@ public static boolean isLocalReference(String href, String 
base) {
         }
     }
 
+    /**
+     * Returns whether a reference may be fetched under the allowed schemes 
(see {@link #getAllowedSchemes()}).
+     * A relative reference is checked against the base URI, or is allowed if 
there is no base URI. For an
+     * archive URL such as jar:http://host/a.jar!/a.xsd, the archive 
location's scheme must also be allowed.
+     * Unlike {@link #checkAllowedScheme(URL)}, this does not need the 
reference to parse as a URL or URI.
+     */
+    public static boolean isAllowedReference(String href, String base) {
+        return href != null && getDisallowedScheme(href, base) == null;
+    }
+
+    /**
+     * Returns the first scheme of a reference that is not allowed, as for
+     * {@link #isAllowedReference(String, String)}, or null if all of its 
schemes are allowed.
+     */
+    public static String getDisallowedScheme(String href, String base) {
+        if (href == null) {
+            return null;
+        }
+        String target = href.trim();
+        if (getScheme(target) == null) {

Review Comment:
   Thanks @reta. That’s intentional: base is only used when href is relative, 
since an absolute reference resolves to itself regardless of the base (RFC 3986 
§5.2). It also matches URIResolver.resolve, which only combines a jar: base 
with the URI when the URI isn’t absolute, so http://host/a.jar!/a.xsd is 
fetched over http. A nested archive goes in href itself 
(jar:http://host/a.jar!/a.xsd), and then both jar and http are checked. I’ve 
added this to the Javadoc with a test, and renamed the parameter to href as you 
suggested.



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to