winterhazel commented on code in PR #13821:
URL: https://github.com/apache/cloudstack/pull/13821#discussion_r3785686431


##########
server/src/main/java/org/apache/cloudstack/dns/DnsProviderManagerImpl.java:
##########
@@ -162,14 +163,29 @@ private DnsProvider getProviderByType(DnsProviderType 
type) {
         throw new CloudRuntimeException("No plugin found for DNS provider 
type: " + type);
     }
 
+    /**
+     * Rejects a DNS provider URL that resolves to an illegal address before 
any provider client is given
+     * the chance to connect to it. See {@link UriUtils#validateUrl(String)} 
for the exact rules enforced
+     * (including the requirement that the URL declares an {@code http}/{@code 
https} scheme).
+     * Expects {@code url} to already be trimmed.

Review Comment:
   Can we trim the URL inside the method instead of expecting it to be trimmed?



##########
server/src/main/java/org/apache/cloudstack/dns/DnsProviderManagerImpl.java:
##########
@@ -162,14 +163,29 @@ private DnsProvider getProviderByType(DnsProviderType 
type) {
         throw new CloudRuntimeException("No plugin found for DNS provider 
type: " + type);
     }
 
+    /**
+     * Rejects a DNS provider URL that resolves to an illegal address before 
any provider client is given
+     * the chance to connect to it. See {@link UriUtils#validateUrl(String)} 
for the exact rules enforced
+     * (including the requirement that the URL declares an {@code http}/{@code 
https} scheme).
+     * Expects {@code url} to already be trimmed.
+     */
+    private void validateDnsServerUrl(String url) {
+        if (StringUtils.isBlank(url)) {
+            throw new IllegalArgumentException("URL cannot be blank.");

Review Comment:
   ```suggestion
               throw new InvalidParameterValueException("URL cannot be blank.");
   ```
   
   A InvalidParameterValueException makes more sense. Also, can we catch the 
exception of UriUtils.validateUrl and throw a InvalidParameterValueException 
too?



##########
server/src/main/java/org/apache/cloudstack/dns/DnsProviderManagerImpl.java:
##########
@@ -162,14 +163,29 @@ private DnsProvider getProviderByType(DnsProviderType 
type) {
         throw new CloudRuntimeException("No plugin found for DNS provider 
type: " + type);
     }
 
+    /**
+     * Rejects a DNS provider URL that resolves to an illegal address before 
any provider client is given
+     * the chance to connect to it. See {@link UriUtils#validateUrl(String)} 
for the exact rules enforced
+     * (including the requirement that the URL declares an {@code http}/{@code 
https} scheme).
+     * Expects {@code url} to already be trimmed.
+     */
+    private void validateDnsServerUrl(String url) {
+        if (StringUtils.isBlank(url)) {
+            throw new IllegalArgumentException("URL cannot be blank.");
+        }
+        UriUtils.validateUrl(url);

Review Comment:
   `UriUtils.validateUrl` does not reject addresses belonging private networks 
(e.g `192.168.1.1`) are still accepted. If this URL specifies a DNS server 
which the MS will send commands to, then it should be rejected in my opinion.
   
   cc @sudo87 @weizhouapache 



##########
server/src/main/java/org/apache/cloudstack/dns/DnsProviderManagerImpl.java:
##########
@@ -162,14 +163,29 @@ private DnsProvider getProviderByType(DnsProviderType 
type) {
         throw new CloudRuntimeException("No plugin found for DNS provider 
type: " + type);
     }
 
+    /**
+     * Rejects a DNS provider URL that resolves to an illegal address before 
any provider client is given
+     * the chance to connect to it. See {@link UriUtils#validateUrl(String)} 
for the exact rules enforced
+     * (including the requirement that the URL declares an {@code http}/{@code 
https} scheme).
+     * Expects {@code url} to already be trimmed.
+     */
+    private void validateDnsServerUrl(String url) {
+        if (StringUtils.isBlank(url)) {
+            return;
+        }
+        UriUtils.validateUrl(url);
+    }

Review Comment:
   @DaanHoogland @sudo87 @weizhouapache I think the scheme should be ignored 
here for the validation. The provider should either use the appropriate scheme 
automatically, or check whether the provided URL has the expected scheme.



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