-
Notifications
You must be signed in to change notification settings - Fork 1.4k
DNS Provider URL Validation #13821
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
DNS Provider URL Validation #13821
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -96,6 +96,7 @@ | |||||
| import com.cloud.user.dao.AccountDao; | ||||||
| import com.cloud.utils.Pair; | ||||||
| import com.cloud.utils.StringUtils; | ||||||
| import com.cloud.utils.UriUtils; | ||||||
| import com.cloud.utils.component.ManagerBase; | ||||||
| import com.cloud.utils.component.PluggableService; | ||||||
| import com.cloud.utils.db.Filter; | ||||||
|
|
@@ -162,14 +163,29 @@ | |||||
| 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)) { | ||||||
|
Check failure on line 173 in server/src/main/java/org/apache/cloudstack/dns/DnsProviderManagerImpl.java
|
||||||
| throw new IllegalArgumentException("URL cannot be blank."); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
A InvalidParameterValueException makes more sense. Also, can we catch the exception of UriUtils.validateUrl and throw a InvalidParameterValueException too? |
||||||
| } | ||||||
| UriUtils.validateUrl(url); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
| @ActionEvent(eventType = EventTypes.EVENT_DNS_SERVER_ADD, eventDescription = "Adding a DNS Server") | ||||||
| public DnsServer addDnsServer(AddDnsServerCmd cmd) { | ||||||
| String url = StringUtils.trim(cmd.getUrl()); | ||||||
|
Check failure on line 182 in server/src/main/java/org/apache/cloudstack/dns/DnsProviderManagerImpl.java
|
||||||
| validateDnsServerUrl(url); | ||||||
| Account caller = CallContext.current().getCallingAccount(); | ||||||
| DnsServer existing = dnsServerDao.findByUrlAndAccount(cmd.getUrl(), caller.getId()); | ||||||
| DnsServer existing = dnsServerDao.findByUrlAndAccount(url, caller.getId()); | ||||||
| if (existing != null) { | ||||||
| throw new InvalidParameterValueException( | ||||||
| "This Account already has a DNS server integration for URL: " + cmd.getUrl()); | ||||||
| "This Account already has a DNS server integration for URL: " + url); | ||||||
| } | ||||||
|
|
||||||
| boolean isDnsPublic = cmd.isPublic(); | ||||||
|
|
@@ -185,7 +201,7 @@ | |||||
| } | ||||||
|
|
||||||
| DnsProviderType type = cmd.getProvider(); | ||||||
| DnsServerVO server = new DnsServerVO(cmd.getName(), cmd.getUrl(), cmd.getPort(), type, | ||||||
| DnsServerVO server = new DnsServerVO(cmd.getName(), url, cmd.getPort(), type, | ||||||
| cmd.getDnsUserName(), cmd.getDnsApiKey(), isDnsPublic, publicDomainSuffix, cmd.getNameServers(), | ||||||
| caller.getAccountId(), caller.getDomainId()); | ||||||
|
|
||||||
|
|
@@ -251,12 +267,14 @@ | |||||
| } | ||||||
|
|
||||||
| if (cmd.getUrl() != null) { | ||||||
| if (!cmd.getUrl().equals(originalUrl)) { | ||||||
| DnsServer duplicate = dnsServerDao.findByUrlAndAccount(cmd.getUrl(), dnsServer.getAccountId()); | ||||||
| String url = StringUtils.trim(cmd.getUrl()); | ||||||
|
Check failure on line 270 in server/src/main/java/org/apache/cloudstack/dns/DnsProviderManagerImpl.java
|
||||||
| if (!url.equals(originalUrl)) { | ||||||
| validateDnsServerUrl(url); | ||||||
| DnsServer duplicate = dnsServerDao.findByUrlAndAccount(url, dnsServer.getAccountId()); | ||||||
| if (duplicate != null && duplicate.getId() != dnsServer.getId()) { | ||||||
| throw new InvalidParameterValueException("Another DNS server with this URL already exists."); | ||||||
| } | ||||||
| dnsServer.setUrl(cmd.getUrl()); | ||||||
| dnsServer.setUrl(url); | ||||||
| validationRequired = true; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we trim the URL inside the method instead of expecting it to be trimmed?