reta commented on code in PR #3794:
URL: https://github.com/apache/cxf/pull/3794#discussion_r4719607627
##########
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) {
+ if (base == null) {
+ return null;
+ }
+ target = base.trim();
+ }
+ Set<String> allowed = getAllowedSchemes();
+ String scheme = getScheme(target);
+ while (scheme != null) {
+ if (!allowed.contains(scheme)) {
+ return scheme;
+ }
+ if (!ARCHIVE_URL_SCHEMES.contains(scheme)) {
+ break;
+ }
+ target = target.substring(scheme.length() + 1);
+ scheme = getScheme(target);
+ }
+ return null;
+ }
+
+ private static String getScheme(String reference) {
Review Comment:
For consistency, we use `href` in some places, but `reference` in other:
```suggestion
private static String getScheme(String href) {
```
--
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]